Annotation of loncom/publisher/lonpublisher.pm, revision 1.87
1.1 www 1: # The LearningOnline Network with CAPA
2: # Publication Handler
1.54 albertel 3: #
1.86 albertel 4: # $Id: lonpublisher.pm,v 1.85 2002/07/26 19:35:20 albertel Exp $
1.54 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: #
29: # (TeX Content Handler
30: #
31: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
32: #
1.15 www 33: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
1.20 www 34: # 03/23 Guy Albertelli
1.23 www 35: # 03/24,03/29,04/03 Gerd Kortemeyer
1.24 harris41 36: # 04/16/2001 Scott Harrison
1.27 www 37: # 05/03,05/05,05/07 Gerd Kortemeyer
1.30 harris41 38: # 05/28/2001 Scott Harrison
1.51 www 39: # 06/23,08/07,08/11,8/13,8/17,8/18,8/24,9/26,10/16 Gerd Kortemeyer
1.58 www 40: # 12/04,12/05 Guy Albertelli
41: # 12/05 Gerd Kortemeyer
1.62 www 42: # 12/05 Guy Albertelli
1.64 www 43: # 12/06,12/07 Gerd Kortemeyer
1.66 harris41 44: # 12/15,12/16 Scott Harrison
1.67 www 45: # 12/25 Gerd Kortemeyer
1.71 www 46: # YEAR=2002
47: # 1/16,1/17 Scott Harrison
48: # 1/17 Gerd Kortemeyer
1.65 harris41 49: #
50: ###
51:
52: ###############################################################################
53: ## ##
54: ## ORGANIZATION OF THIS PERL MODULE ##
55: ## ##
56: ## 1. Modules used by this module ##
57: ## 2. Various subroutines ##
58: ## 3. Publication Step One ##
59: ## 4. Phase Two ##
60: ## 5. Main Handler ##
61: ## ##
62: ###############################################################################
1.1 www 63:
64: package Apache::lonpublisher;
65:
1.65 harris41 66: # ------------------------------------------------- modules used by this module
1.1 www 67: use strict;
68: use Apache::File;
1.13 www 69: use File::Copy;
1.2 www 70: use Apache::Constants qw(:common :http :methods);
1.76 albertel 71: use HTML::LCParser;
1.4 www 72: use Apache::lonxml;
1.17 albertel 73: use Apache::lonhomework;
1.27 www 74: use Apache::loncacc;
1.24 harris41 75: use DBI;
1.65 harris41 76: use Apache::lonnet();
77: use Apache::loncommon();
1.2 www 78:
1.3 www 79: my %addid;
1.5 www 80: my %nokey;
1.10 www 81:
1.7 www 82: my %metadatafields;
83: my %metadatakeys;
84:
1.12 www 85: my $docroot;
86:
1.27 www 87: my $cuname;
88: my $cudom;
89:
1.12 www 90: # ----------------------------------------------- Evaluate string with metadata
1.7 www 91: sub metaeval {
92: my $metastring=shift;
93:
1.76 albertel 94: my $parser=HTML::LCParser->new(\$metastring);
1.7 www 95: my $token;
96: while ($token=$parser->get_token) {
97: if ($token->[0] eq 'S') {
98: my $entry=$token->[1];
99: my $unikey=$entry;
1.32 www 100: if (defined($token->[2]->{'package'})) {
101: $unikey.='_package_'.$token->[2]->{'package'};
102: }
1.7 www 103: if (defined($token->[2]->{'part'})) {
104: $unikey.='_'.$token->[2]->{'part'};
105: }
1.32 www 106: if (defined($token->[2]->{'id'})) {
1.49 www 107: $unikey.='_'.$token->[2]->{'id'};
1.32 www 108: }
1.7 www 109: if (defined($token->[2]->{'name'})) {
110: $unikey.='_'.$token->[2]->{'name'};
111: }
1.65 harris41 112: foreach (@{$token->[3]}) {
1.7 www 113: $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
114: if ($metadatakeys{$unikey}) {
115: $metadatakeys{$unikey}.=','.$_;
116: } else {
117: $metadatakeys{$unikey}=$_;
118: }
1.65 harris41 119: }
1.7 www 120: if ($metadatafields{$unikey}) {
1.8 www 121: my $newentry=$parser->get_text('/'.$entry);
1.41 www 122: unless (($metadatafields{$unikey}=~/$newentry/) ||
123: ($newentry eq '')) {
1.8 www 124: $metadatafields{$unikey}.=', '.$newentry;
125: }
1.7 www 126: } else {
127: $metadatafields{$unikey}=$parser->get_text('/'.$entry);
128: }
129: }
130: }
131: }
132:
1.12 www 133: # -------------------------------------------------------- Read a metadata file
1.7 www 134: sub metaread {
135: my ($logfile,$fn)=@_;
136: unless (-e $fn) {
137: print $logfile 'No file '.$fn."\n";
138: return '<br><b>No file:</b> <tt>'.$fn.'</tt>';
139: }
140: print $logfile 'Processing '.$fn."\n";
141: my $metastring;
142: {
143: my $metafh=Apache::File->new($fn);
144: $metastring=join('',<$metafh>);
145: }
146: &metaeval($metastring);
147: return '<br><b>Processed file:</b> <tt>'.$fn.'</tt>';
148: }
149:
1.25 harris41 150: # ---------------------------- convert 'time' format into a datetime sql format
151: sub sqltime {
1.70 harris41 152: my $timef=shift @_;
1.25 harris41 153: my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
1.70 harris41 154: localtime($timef);
1.25 harris41 155: $mon++; $year+=1900;
156: return "$year-$mon-$mday $hour:$min:$sec";
157: }
158:
1.12 www 159: # --------------------------------------------------------- Various form fields
160:
1.8 www 161: sub textfield {
1.10 www 162: my ($title,$name,$value)=@_;
1.8 www 163: return "\n<p><b>$title:</b><br>".
1.11 www 164: '<input type=text name="'.$name.'" size=80 value="'.$value.'">';
165: }
166:
167: sub hiddenfield {
168: my ($name,$value)=@_;
169: return "\n".'<input type=hidden name="'.$name.'" value="'.$value.'">';
1.8 www 170: }
171:
1.9 www 172: sub selectbox {
1.65 harris41 173: my ($title,$name,$value,$functionref,@idlist)=@_;
174: my $uctitle=uc($title);
175: my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
176: "</b></font><br />".'<select name="'.$name.'">';
177: foreach (@idlist) {
178: $selout.='<option value=\''.$_.'\'';
179: if ($_ eq $value) {
180: $selout.=' selected>'.&{$functionref}($_).'</option>';
181: }
182: else {$selout.='>'.&{$functionref}($_).'</option>';}
183: }
1.10 www 184: return $selout.'</select>';
1.9 www 185: }
186:
1.12 www 187: # -------------------------------------------------------- Publication Step One
188:
1.34 www 189: sub urlfixup {
1.35 www 190: my ($url,$target)=@_;
1.39 www 191: unless ($url) { return ''; }
1.68 albertel 192: #javascript code needs no fixing
193: if ($url =~ /^javascript:/i) { return $url; }
1.69 albertel 194: if ($url =~ /^mailto:/i) { return $url; }
1.68 albertel 195: #internal document links need no fixing
196: if ($url =~ /^\#/) { return $url; }
1.35 www 197: my ($host)=($url=~/(?:http\:\/\/)*([^\/]+)/);
1.65 harris41 198: foreach (values %Apache::lonnet::hostname) {
1.35 www 199: if ($_ eq $host) {
200: $url=~s/^http\:\/\///;
201: $url=~s/^$host//;
202: }
1.65 harris41 203: }
1.40 www 204: if ($url=~/^http\:\/\//) { return $url; }
1.35 www 205: $url=~s/\~$cuname/res\/$cudom\/$cuname/;
1.71 www 206: return $url;
207: }
208:
209:
210: sub absoluteurl {
211: my ($url,$target)=@_;
212: unless ($url) { return ''; }
1.35 www 213: if ($target) {
214: $target=~s/\/[^\/]+$//;
215: $url=&Apache::lonnet::hreflocation($target,$url);
216: }
217: return $url;
1.34 www 218: }
219:
1.81 albertel 220: sub set_allow {
221: my ($allow,$logfile,$target,$tag,$oldurl)=@_;
222: my $newurl=&urlfixup($oldurl,$target);
223: my $return_url=$oldurl;
224: print $logfile 'GUYURL: '.$tag.':'.$oldurl.' - '.$newurl."\n";
225: if ($newurl ne $oldurl) {
226: $return_url=$newurl;
227: print $logfile 'URL: '.$tag.':'.$oldurl.' - '.$newurl."\n";
228: }
229: if (($newurl !~ /^javascript:/i) &&
230: ($newurl !~ /^mailto:/i) &&
231: ($newurl !~ /^http:/i) &&
232: ($newurl !~ /^\#/)) {
233: $$allow{&absoluteurl($newurl,$target)}=1;
234: }
235: return $return_url
236: }
237:
1.85 albertel 238: sub get_subscribed_hosts {
239: my ($target)=@_;
240: my @subscribed;
241: my $filename;
242: $target=~/(.*)\/([^\/]+)$/;
243: my $srcf=$2;
244: opendir(DIR,$1);
245: while ($filename=readdir(DIR)) {
246: if ($filename=~/$srcf\.(\w+)$/) {
247: my $subhost=$1;
248: if ($subhost ne 'meta' && $subhost ne 'subscription') {
249: push(@subscribed,$subhost);
250: }
251: }
252: }
253: closedir(DIR);
254: my $sh;
255: if ( $sh=Apache::File->new("$target.subscription") ) {
256: &Apache::lonnet::logthis("opened $target.subscription");
257: while (my $subline=<$sh>) {
258: &Apache::lonnet::logthis("Trying $subline");
259: if ($subline =~ /(^\w+):/) { push(@subscribed,$1); } else {
260: &Apache::lonnet::logthis("No Match for $subline");
261: }
262: }
263: } else {
264: &Apache::lonnet::logthis("Un able to open $target.subscription");
265: }
266: &Apache::lonnet::logthis("Got list of ".join(':',@subscribed));
267: return @subscribed;
268: }
269:
1.86 albertel 270:
271: sub get_max_ids_indices {
272: my ($content)=@_;
273: my $maxindex=10;
274: my $maxid=10;
275: my $needsfixup=0;
276:
277: my $parser=HTML::LCParser->new($content);
278: my $token;
279: while ($token=$parser->get_token) {
280: if ($token->[0] eq 'S') {
281: my $counter;
282: if ($counter=$addid{$token->[1]}) {
283: if ($counter eq 'id') {
284: if (defined($token->[2]->{'id'})) {
285: $maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid;
286: } else {
287: $needsfixup=1;
288: }
289: } else {
290: if (defined($token->[2]->{'index'})) {
291: $maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex;
292: } else {
293: $needsfixup=1;
294: }
295: }
296: }
297: }
298: }
299: return ($needsfixup,$maxid,$maxindex);
300: }
301:
1.87 ! albertel 302: sub get_all_text_unbalanced {
! 303: #there is a copy of this in lonxml.pm
! 304: my($tag,$pars)= @_;
! 305: my $token;
! 306: my $result='';
! 307: $tag='<'.$tag.'>';
! 308: while ($token = $$pars[-1]->get_token) {
! 309: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
! 310: $result.=$token->[1];
! 311: } elsif ($token->[0] eq 'PI') {
! 312: $result.=$token->[2];
! 313: } elsif ($token->[0] eq 'S') {
! 314: $result.=$token->[4];
! 315: } elsif ($token->[0] eq 'E') {
! 316: $result.=$token->[2];
! 317: }
! 318: if ($result =~ /(.*)$tag(.*)/) {
! 319: &Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);
! 320: &Apache::lonnet::logthis('Result is :'.$1);
! 321: $result=$1;
! 322: my $redo=$tag.$2;
! 323: push (@$pars,HTML::LCParser->new(\$redo));
! 324: $$pars[-1]->xml_mode('1');
! 325: last;
! 326: }
! 327: }
! 328: return $result
! 329: }
! 330:
! 331: #Arguably this should all be done as a lonnet::ssi instead
1.86 albertel 332: sub fix_ids_and_indices {
333: my ($logfile,$source,$target)=@_;
334:
335: my %allow;
336: my $content;
337: {
338: my $org=Apache::File->new($source);
339: $content=join('',<$org>);
340: }
341:
342: my ($needsfixup,$maxid,$maxindex)=&get_max_ids_indices(\$content);
343:
344: if ($needsfixup) {
345: print $logfile "Needs ID and/or index fixup\n".
346: "Max ID : $maxid (min 10)\n".
347: "Max Index: $maxindex (min 10)\n";
348: }
349: my $outstring='';
350: my @parser;
351: $parser[0]=HTML::LCParser->new(\$content);
352: $parser[-1]->xml_mode(1);
353: my $token;
354: while (@parser) {
355: while ($token=$parser[-1]->get_token) {
356: if ($token->[0] eq 'S') {
357: my $counter;
358: my $tag=$token->[1];
359: my $lctag=lc($tag);
360: if ($lctag eq 'allow') {
361: $allow{$token->[2]->{'src'}}=1;
362: next;
363: }
364: my %parms=%{$token->[2]};
365: $counter=$addid{$tag};
366: if (!$counter) { $counter=$addid{$lctag}; }
367: if ($counter) {
368: if ($counter eq 'id') {
369: unless (defined($parms{'id'})) {
370: $maxid++;
371: $parms{'id'}=$maxid;
372: print $logfile 'ID: '.$tag.':'.$maxid."\n";
373: }
374: } elsif ($counter eq 'index') {
375: unless (defined($parms{'index'})) {
376: $maxindex++;
377: $parms{'index'}=$maxindex;
378: print $logfile 'Index: '.$tag.':'.$maxindex."\n";
379: }
380: }
381: }
382: foreach my $type ('src','href','background','bgimg') {
383: foreach my $key (keys(%parms)) {
384: print $logfile "for $type, and $key\n";
385: if ($key =~ /^$type$/i) {
386: print $logfile "calling set_allow\n";
387: $parms{$key}=&set_allow(\%allow,$logfile,
388: $target,$tag,
389: $parms{$key});
390: }
391: }
392: }
393: # probably a <randomlabel> image type <label>
394: if ($lctag eq 'label' && defined($parms{'description'})) {
395: my $next_token=$parser[-1]->get_token();
396: if ($next_token->[0] eq 'T') {
397: $next_token->[1]=&set_allow(\%allow,$logfile,
398: $target,$tag,
399: $next_token->[1]);
400: }
401: $parser[-1]->unget_token($next_token);
402: }
403: if ($lctag eq 'applet') {
404: my $codebase='';
405: if (defined($parms{'codebase'})) {
406: my $oldcodebase=$parms{'codebase'};
407: unless ($oldcodebase=~/\/$/) {
408: $oldcodebase.='/';
409: }
410: $codebase=&urlfixup($oldcodebase,$target);
411: $codebase=~s/\/$//;
412: if ($codebase ne $oldcodebase) {
413: $parms{'codebase'}=$codebase;
414: print $logfile 'URL codebase: '.$tag.':'.
415: $oldcodebase.' - '.
416: $codebase."\n";
417: }
418: $allow{&absoluteurl($codebase,$target).'/*'}=1;
419: } else {
420: foreach ('archive','code','object') {
421: if (defined($parms{$_})) {
422: my $oldurl=$parms{$_};
423: my $newurl=&urlfixup($oldurl,$target);
424: $newurl=~s/\/[^\/]+$/\/\*/;
425: print $logfile 'Allow: applet '.$_.':'.
426: $oldurl.' allows '.
427: $newurl."\n";
428: $allow{&absoluteurl($newurl,$target)}=1;
429: }
430: }
431: }
432: }
433: my $newparmstring='';
434: my $endtag='';
435: foreach (keys %parms) {
436: if ($_ eq '/') {
437: $endtag=' /';
438: } else {
439: my $quote=($parms{$_}=~/\"/?"'":'"');
440: $newparmstring.=' '.$_.'='.$quote.$parms{$_}.$quote;
441: }
442: }
443: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
444: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1.87 ! albertel 445: if ($lctag eq 'm') {
! 446: $outstring.=&get_all_text_unbalanced('/m',\@parser);
! 447: }
1.86 albertel 448: } elsif ($token->[0] eq 'E') {
449: if ($token->[2]) {
450: unless ($token->[1] eq 'allow') {
451: $outstring.='</'.$token->[1].'>';
452: }
453: }
454: } else {
455: $outstring.=$token->[1];
456: }
457: }
458: pop(@parser);
459: }
460:
461: if ($needsfixup) {
462: print $logfile "End of ID and/or index fixup\n".
463: "Max ID : $maxid (min 10)\n".
464: "Max Index: $maxindex (min 10)\n";
465: } else {
466: print $logfile "Does not need ID and/or index fixup\n";
467: }
468:
469: return ($outstring,%allow);
470: }
471:
1.2 www 472: sub publish {
1.50 www 473:
1.2 www 474: my ($source,$target,$style)=@_;
475: my $logfile;
1.4 www 476: my $scrout='';
1.23 www 477: my $allmeta='';
478: my $content='';
1.36 www 479: my %allow=();
1.4 www 480:
1.2 www 481: unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
1.7 www 482: return
483: '<font color=red>No write permission to user directory, FAIL</font>';
1.2 www 484: }
485: print $logfile
1.11 www 486: "\n\n================= Publish ".localtime()." Phase One ================\n";
1.2 www 487:
1.3 www 488: if (($style eq 'ssi') || ($style eq 'rat')) {
489: # ------------------------------------------------------- This needs processing
1.4 www 490:
491: # ----------------------------------------------------------------- Backup Copy
1.3 www 492: my $copyfile=$source.'.save';
1.13 www 493: if (copy($source,$copyfile)) {
1.3 www 494: print $logfile "Copied original file to ".$copyfile."\n";
495: } else {
1.13 www 496: print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";
497: return "<font color=red>Failed to write backup copy, $!,FAIL</font>";
1.3 www 498: }
1.4 www 499: # ------------------------------------------------------------- IDs and indices
1.86 albertel 500:
501: my $outstring;
502: ($outstring,%allow)=&fix_ids_and_indices($logfile,$source,$target);
1.36 www 503: # ------------------------------------------------------------ Construct Allows
1.62 www 504:
1.44 www 505: $scrout.='<h3>Dependencies</h3>';
1.62 www 506: my $allowstr='';
1.73 albertel 507: foreach (sort(keys(%allow))) {
1.59 www 508: my $thisdep=$_;
1.73 albertel 509: if ($thisdep !~ /[^\s]/) { next; }
1.62 www 510: unless ($style eq 'rat') {
511: $allowstr.="\n".'<allow src="'.$thisdep.'" />';
512: }
1.44 www 513: $scrout.='<br>';
1.59 www 514: unless ($thisdep=~/\*/) {
515: $scrout.='<a href="'.$thisdep.'">';
1.44 www 516: }
1.59 www 517: $scrout.='<tt>'.$thisdep.'</tt>';
518: unless ($thisdep=~/\*/) {
1.44 www 519: $scrout.='</a>';
1.59 www 520: if (
521: &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
522: $thisdep.'.meta') eq '-1') {
1.58 www 523: $scrout.=
524: ' - <font color=red>Currently not available</font>';
1.59 www 525: } else {
526: my %temphash=(&Apache::lonnet::declutter($target).'___'.
527: &Apache::lonnet::declutter($thisdep).'___usage'
528: => time);
529: $thisdep=~/^\/res\/(\w+)\/(\w+)\//;
530: if ((defined($1)) && (defined($2))) {
531: &Apache::lonnet::put('resevaldata',\%temphash,$1,$2);
532: }
533: }
1.44 www 534: }
1.65 harris41 535: }
1.83 www 536: $outstring=~s/\n*(\<\/[^\>]+\>)\s*$/$allowstr\n$1\n/s;
1.62 www 537:
1.76 albertel 538: #Encode any High ASCII characters
539: $outstring=&HTML::Entities::encode($outstring,"\200-\377");
1.37 www 540: # ------------------------------------------------------------- Write modified
541:
1.4 www 542: {
543: my $org;
544: unless ($org=Apache::File->new('>'.$source)) {
545: print $logfile "No write permit to $source\n";
1.7 www 546: return
547: "<font color=red>No write permission to $source, FAIL</font>";
1.4 www 548: }
549: print $org $outstring;
550: }
551: $content=$outstring;
1.34 www 552:
1.37 www 553: }
1.7 www 554: # --------------------------------------------- Initial step done, now metadata
555:
556: # ---------------------------------------- Storage for metadata keys and fields
557:
1.8 www 558: %metadatafields=();
559: %metadatakeys=();
560:
561: my %oldparmstores=();
1.44 www 562:
1.84 bowersj2 563:
564: $scrout.='<h3>Metadata Information ' .
565: Apache::loncommon::help_open_topic("Metadata_Description")
566: . '</h3>';
1.7 www 567:
568: # ------------------------------------------------ First, check out environment
1.8 www 569: unless (-e $source.'.meta') {
1.7 www 570: $metadatafields{'author'}=$ENV{'environment.firstname'}.' '.
571: $ENV{'environment.middlename'}.' '.
572: $ENV{'environment.lastname'}.' '.
573: $ENV{'environment.generation'};
1.8 www 574: $metadatafields{'author'}=~s/\s+/ /g;
575: $metadatafields{'author'}=~s/\s+$//;
1.27 www 576: $metadatafields{'owner'}=$cuname.'@'.$cudom;
1.7 www 577:
578: # ------------------------------------------------ Check out directory hierachy
579:
580: my $thisdisfn=$source;
1.27 www 581: $thisdisfn=~s/^\/home\/$cuname\///;
1.7 www 582:
583: my @urlparts=split(/\//,$thisdisfn);
584: $#urlparts--;
585:
1.27 www 586: my $currentpath='/home/'.$cuname.'/';
1.7 www 587:
1.65 harris41 588: foreach (@urlparts) {
1.7 www 589: $currentpath.=$_.'/';
590: $scrout.=&metaread($logfile,$currentpath.'default.meta');
1.65 harris41 591: }
1.7 www 592:
593: # ------------------- Clear out parameters and stores (there should not be any)
594:
1.65 harris41 595: foreach (keys %metadatafields) {
1.7 www 596: if (($_=~/^parameter/) || ($_=~/^stores/)) {
597: delete $metadatafields{$_};
598: }
1.65 harris41 599: }
1.7 www 600:
1.8 www 601: } else {
1.7 www 602: # ---------------------- Read previous metafile, remember parameters and stores
603:
604: $scrout.=&metaread($logfile,$source.'.meta');
605:
1.65 harris41 606: foreach (keys %metadatafields) {
1.7 www 607: if (($_=~/^parameter/) || ($_=~/^stores/)) {
608: $oldparmstores{$_}=1;
609: delete $metadatafields{$_};
610: }
1.65 harris41 611: }
1.7 www 612:
1.8 www 613: }
1.7 www 614:
1.4 www 615: # -------------------------------------------------- Parse content for metadata
1.37 www 616: if ($style eq 'ssi') {
1.42 www 617: my $oldenv=$ENV{'request.uri'};
618:
619: $ENV{'request.uri'}=$target;
1.82 albertel 620: $allmeta=Apache::lonxml::xmlparse(undef,'meta',$content);
1.42 www 621: $ENV{'request.uri'}=$oldenv;
1.32 www 622:
1.19 albertel 623: &metaeval($allmeta);
1.37 www 624: }
1.7 www 625: # ---------------- Find and document discrepancies in the parameters and stores
626:
627: my $chparms='';
1.65 harris41 628: foreach (sort keys %metadatafields) {
1.7 www 629: if (($_=~/^parameter/) || ($_=~/^stores/)) {
630: unless ($_=~/\.\w+$/) {
631: unless ($oldparmstores{$_}) {
632: print $logfile 'New: '.$_."\n";
633: $chparms.=$_.' ';
634: }
635: }
636: }
1.65 harris41 637: }
1.7 www 638: if ($chparms) {
639: $scrout.='<p><b>New parameters or stored values:</b> '.
640: $chparms;
641: }
642:
1.70 harris41 643: $chparms='';
1.65 harris41 644: foreach (sort keys %oldparmstores) {
1.7 www 645: if (($_=~/^parameter/) || ($_=~/^stores/)) {
1.33 www 646: unless (($metadatafields{$_.'.name'}) ||
647: ($metadatafields{$_.'.package'}) || ($_=~/\.\w+$/)) {
1.7 www 648: print $logfile 'Obsolete: '.$_."\n";
649: $chparms.=$_.' ';
650: }
651: }
1.65 harris41 652: }
1.7 www 653: if ($chparms) {
654: $scrout.='<p><b>Obsolete parameters or stored values:</b> '.
655: $chparms;
656: }
1.37 www 657:
1.8 www 658: # ------------------------------------------------------- Now have all metadata
1.5 www 659:
1.8 www 660: $scrout.=
1.77 matthew 661: '<form name="pubform" action="/adm/publish" method="post">'.
1.63 albertel 662: '<p><input type="submit" value="Finalize Publication" /></p>'.
1.11 www 663: &hiddenfield('phase','two').
664: &hiddenfield('filename',$ENV{'form.filename'}).
665: &hiddenfield('allmeta',&Apache::lonnet::escape($allmeta)).
1.58 www 666: &hiddenfield('dependencies',join(',',keys %allow)).
1.10 www 667: &textfield('Title','title',$metadatafields{'title'}).
668: &textfield('Author(s)','author',$metadatafields{'author'}).
669: &textfield('Subject','subject',$metadatafields{'subject'});
1.5 www 670:
671: # --------------------------------------------------- Scan content for keywords
1.7 www 672:
1.84 bowersj2 673: my $keywords_help = Apache::loncommon::help_open_topic("Publishing_Keywords");
1.77 matthew 674: my $keywordout=<<"END";
675: <script>
676: function checkAll(field)
677: {
678: for (i = 0; i < field.length; i++)
679: field[i].checked = true ;
680: }
681:
682: function uncheckAll(field)
683: {
684: for (i = 0; i < field.length; i++)
685: field[i].checked = false ;
686: }
687: </script>
1.84 bowersj2 688: <p><b>Keywords: $keywords_help</b>
1.77 matthew 689: <input type="button" value="check all" onclick="javascript:checkAll(document.pubform.keywords)">
690: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.pubform.keywords)">
691: <br />
692: END
693: $keywordout.='<table border=2><tr>';
1.7 www 694: my $colcount=0;
1.67 www 695: my %keywords=();
1.7 www 696:
1.52 albertel 697: if (length($content)<500000) {
1.5 www 698: my $textonly=$content;
699: $textonly=~s/\<script[^\<]+\<\/script\>//g;
700: $textonly=~s/\<m\>[^\<]+\<\/m\>//g;
701: $textonly=~s/\<[^\>]*\>//g;
702: $textonly=~tr/A-Z/a-z/;
703: $textonly=~s/[\$\&][a-z]\w*//g;
704: $textonly=~s/[^a-z\s]//g;
705:
1.65 harris41 706: foreach ($textonly=~m/(\w+)/g) {
1.50 www 707: unless ($nokey{$_}) {
708: $keywords{$_}=1;
709: }
1.65 harris41 710: }
1.67 www 711: }
1.5 www 712:
1.67 www 713:
1.65 harris41 714: foreach (split(/\W+/,$metadatafields{'keywords'})) {
1.12 www 715: $keywords{$_}=1;
1.65 harris41 716: }
1.5 www 717:
1.65 harris41 718: foreach (sort keys %keywords) {
1.77 matthew 719: $keywordout.='<td><input type=checkbox name="keywords" value="'.$_.'"';
1.67 www 720: if ($metadatafields{'keywords'}) {
721: if ($metadatafields{'keywords'}=~/$_/) {
722: $keywordout.=' checked';
723: }
724: } elsif (&Apache::loncommon::keyword($_)) {
1.73 albertel 725: $keywordout.=' checked';
1.67 www 726: }
1.8 www 727: $keywordout.='>'.$_.'</td>';
1.7 www 728: if ($colcount>10) {
729: $keywordout.="</tr><tr>\n";
730: $colcount=0;
731: }
1.50 www 732: $colcount++;
1.65 harris41 733: }
1.50 www 734:
1.51 www 735: $keywordout.='</tr></table>';
736:
737: $scrout.=$keywordout;
1.9 www 738:
1.12 www 739: $scrout.=&textfield('Additional Keywords','addkey','');
740:
1.10 www 741: $scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
1.9 www 742:
743: $scrout.=
744: '<p><b>Abstract:</b><br><textarea cols=80 rows=5 name=abstract>'.
745: $metadatafields{'abstract'}.'</textarea>';
746:
1.11 www 747: $source=~/\.(\w+)$/;
748:
749: $scrout.=&hiddenfield('mime',$1);
750:
1.10 www 751: $scrout.=&selectbox('Language','language',
1.65 harris41 752: $metadatafields{'language'},
1.70 harris41 753: \&Apache::loncommon::languagedescription,
1.65 harris41 754: (&Apache::loncommon::languageids),
755: );
1.11 www 756:
757: unless ($metadatafields{'creationdate'}) {
758: $metadatafields{'creationdate'}=time;
759: }
760: $scrout.=&hiddenfield('creationdate',$metadatafields{'creationdate'});
761:
762: $scrout.=&hiddenfield('lastrevisiondate',time);
763:
1.9 www 764:
1.10 www 765: $scrout.=&textfield('Publisher/Owner','owner',
766: $metadatafields{'owner'});
1.45 www 767: # --------------------------------------------------- Correct copyright for rat
1.84 bowersj2 768:
1.45 www 769: if ($style eq 'rat') {
1.65 harris41 770: if ($metadatafields{'copyright'} eq 'public') {
771: delete $metadatafields{'copyright'};
772: }
773: $scrout.=&selectbox('Copyright/Distribution','copyright',
774: $metadatafields{'copyright'},
1.70 harris41 775: \&Apache::loncommon::copyrightdescription,
1.65 harris41 776: (grep !/^public$/,(&Apache::loncommon::copyrightids)));
777: }
778: else {
1.10 www 779: $scrout.=&selectbox('Copyright/Distribution','copyright',
1.65 harris41 780: $metadatafields{'copyright'},
1.70 harris41 781: \&Apache::loncommon::copyrightdescription,
1.65 harris41 782: (&Apache::loncommon::copyrightids));
783: }
1.84 bowersj2 784:
785: my $copyright_help = Apache::loncommon::help_open_topic("Publishing_Copyright");
786: $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;
1.8 www 787: return $scrout.
1.63 albertel 788: '<p><input type="submit" value="Finalize Publication" /></p></form>';
1.2 www 789: }
1.1 www 790:
1.12 www 791: # -------------------------------------------------------- Publication Step Two
792:
1.11 www 793: sub phasetwo {
794:
1.24 harris41 795: my ($source,$target,$style,$distarget)=@_;
1.11 www 796: my $logfile;
797: my $scrout='';
798: unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
799: return
800: '<font color=red>No write permission to user directory, FAIL</font>';
801: }
802: print $logfile
803: "\n================= Publish ".localtime()." Phase Two ================\n";
804:
805: %metadatafields=();
806: %metadatakeys=();
807:
808: &metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'}));
809:
810: $metadatafields{'title'}=$ENV{'form.title'};
811: $metadatafields{'author'}=$ENV{'form.author'};
812: $metadatafields{'subject'}=$ENV{'form.subject'};
813: $metadatafields{'notes'}=$ENV{'form.notes'};
814: $metadatafields{'abstract'}=$ENV{'form.abstract'};
815: $metadatafields{'mime'}=$ENV{'form.mime'};
816: $metadatafields{'language'}=$ENV{'form.language'};
817: $metadatafields{'creationdate'}=$ENV{'form.creationdate'};
818: $metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'};
819: $metadatafields{'owner'}=$ENV{'form.owner'};
820: $metadatafields{'copyright'}=$ENV{'form.copyright'};
1.60 www 821: $metadatafields{'dependencies'}=$ENV{'form.dependencies'};
1.12 www 822:
823: my $allkeywords=$ENV{'form.addkey'};
1.79 matthew 824: if (exists($ENV{'form.keywords'}) && (ref($ENV{'form.keywords'}))) {
1.78 matthew 825: my @Keywords = @{$ENV{'form.keywords'}};
826: foreach (@Keywords) {
827: $allkeywords.=','.$_;
828: }
1.65 harris41 829: }
1.12 www 830: $allkeywords=~s/\W+/\,/;
831: $allkeywords=~s/^\,//;
832: $metadatafields{'keywords'}=$allkeywords;
833:
834: {
835: print $logfile "\nWrite metadata file for ".$source;
836: my $mfh;
837: unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
838: return
839: '<font color=red>Could not write metadata, FAIL</font>';
1.65 harris41 840: }
841: foreach (sort keys %metadatafields) {
1.12 www 842: unless ($_=~/\./) {
843: my $unikey=$_;
844: $unikey=~/^([A-Za-z]+)/;
845: my $tag=$1;
846: $tag=~tr/A-Z/a-z/;
847: print $mfh "\n\<$tag";
1.65 harris41 848: foreach (split(/\,/,$metadatakeys{$unikey})) {
1.12 www 849: my $value=$metadatafields{$unikey.'.'.$_};
850: $value=~s/\"/\'\'/g;
851: print $mfh ' '.$_.'="'.$value.'"';
1.65 harris41 852: }
1.76 albertel 853: print $mfh '>'.
854: &HTML::Entities::encode($metadatafields{$unikey})
855: .'</'.$tag.'>';
1.12 www 856: }
1.65 harris41 857: }
1.12 www 858: $scrout.='<p>Wrote Metadata';
859: print $logfile "\nWrote metadata";
860: }
861:
1.24 harris41 862: # -------------------------------- Synchronize entry with SQL metadata database
1.64 www 863: my $warning;
864:
865: unless ($metadatafields{'copyright'} eq 'priv') {
1.25 harris41 866:
1.24 harris41 867: my $dbh;
868: {
869: unless (
1.64 www 870: $dbh = DBI->connect("DBI:mysql:loncapa","www",
871: $Apache::lonnet::perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0})
1.24 harris41 872: ) {
1.29 harris41 873: $warning='<font color=red>WARNING: Cannot connect to '.
874: 'database!</font>';
875: }
876: else {
877: my %sqldatafields;
878: $sqldatafields{'url'}=$distarget;
879: my $sth=$dbh->prepare(
880: 'delete from metadata where url like binary'.
881: '"'.$sqldatafields{'url'}.'"');
882: $sth->execute();
1.65 harris41 883: foreach ('title','author','subject','keywords','notes','abstract',
1.29 harris41 884: 'mime','language','creationdate','lastrevisiondate','owner',
1.65 harris41 885: 'copyright') {
886: my $field=$metadatafields{$_}; $field=~s/\"/\'\'/g;
887: $sqldatafields{$_}=$field;
888: }
1.29 harris41 889:
890: $sth=$dbh->prepare('insert into metadata values ('.
891: '"'.delete($sqldatafields{'title'}).'"'.','.
892: '"'.delete($sqldatafields{'author'}).'"'.','.
893: '"'.delete($sqldatafields{'subject'}).'"'.','.
894: '"'.delete($sqldatafields{'url'}).'"'.','.
895: '"'.delete($sqldatafields{'keywords'}).'"'.','.
896: '"'.'current'.'"'.','.
897: '"'.delete($sqldatafields{'notes'}).'"'.','.
898: '"'.delete($sqldatafields{'abstract'}).'"'.','.
899: '"'.delete($sqldatafields{'mime'}).'"'.','.
900: '"'.delete($sqldatafields{'language'}).'"'.','.
901: '"'.
902: sqltime(delete($sqldatafields{'creationdate'}))
903: .'"'.','.
904: '"'.
905: sqltime(delete(
906: $sqldatafields{'lastrevisiondate'})).'"'.','.
907: '"'.delete($sqldatafields{'owner'}).'"'.','.
908: '"'.delete(
909: $sqldatafields{'copyright'}).'"'.')');
910: $sth->execute();
911: $dbh->disconnect;
912: $scrout.='<p>Synchronized SQL metadata database';
913: print $logfile "\nSynchronized SQL metadata database";
1.24 harris41 914: }
915: }
916:
1.64 www 917: } else {
918: $scrout.='<p>Private Publication - did not synchronize database';
1.66 harris41 919: print $logfile "\nPrivate: Did not synchronize data into ".
920: "SQL metadata database";
1.64 www 921: }
1.12 www 922: # ----------------------------------------------------------- Copy old versions
923:
924: if (-e $target) {
925: my $filename;
926: my $maxversion=0;
927: $target=~/(.*)\/([^\/]+)\.(\w+)$/;
928: my $srcf=$2;
929: my $srct=$3;
930: my $srcd=$1;
931: unless ($srcd=~/^\/home\/httpd\/html\/res/) {
932: print $logfile "\nPANIC: Target dir is ".$srcd;
933: return "<font color=red>Invalid target directory, FAIL</font>";
934: }
935: opendir(DIR,$srcd);
936: while ($filename=readdir(DIR)) {
937: if ($filename=~/$srcf\.(\d+)\.$srct$/) {
938: $maxversion=($1>$maxversion)?$1:$maxversion;
939: }
940: }
941: closedir(DIR);
942: $maxversion++;
943: $scrout.='<p>Creating old version '.$maxversion;
944: print $logfile "\nCreating old version ".$maxversion;
945:
946: my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct;
947:
1.13 www 948: if (copy($target,$copyfile)) {
1.12 www 949: print $logfile "Copied old target to ".$copyfile."\n";
950: $scrout.='<p>Copied old target file';
951: } else {
1.13 www 952: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
953: return "<font color=red>Failed to copy old target, $!, FAIL</font>";
1.12 www 954: }
955:
956: # --------------------------------------------------------------- Copy Metadata
957:
958: $copyfile=$copyfile.'.meta';
1.13 www 959:
960: if (copy($target.'.meta',$copyfile)) {
1.14 www 961: print $logfile "Copied old target metadata to ".$copyfile."\n";
1.12 www 962: $scrout.='<p>Copied old metadata';
963: } else {
1.13 www 964: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1.14 www 965: if (-e $target.'.meta') {
966: return
1.13 www 967: "<font color=red>Failed to write old metadata copy, $!, FAIL</font>";
1.14 www 968: }
1.12 www 969: }
1.11 www 970:
971:
1.12 www 972: } else {
973: $scrout.='<p>Initial version';
974: print $logfile "\nInitial version";
975: }
976:
977: # ---------------------------------------------------------------- Write Source
978: my $copyfile=$target;
979:
980: my @parts=split(/\//,$copyfile);
981: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
982:
983: my $count;
984: for ($count=5;$count<$#parts;$count++) {
985: $path.="/$parts[$count]";
986: if ((-e $path)!=1) {
987: print $logfile "\nCreating directory ".$path;
988: $scrout.='<p>Created directory '.$parts[$count];
989: mkdir($path,0777);
990: }
991: }
992:
1.13 www 993: if (copy($source,$copyfile)) {
1.12 www 994: print $logfile "Copied original source to ".$copyfile."\n";
995: $scrout.='<p>Copied source file';
996: } else {
1.13 www 997: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
998: return "<font color=red>Failed to copy source, $!, FAIL</font>";
1.12 www 999: }
1000:
1001: # --------------------------------------------------------------- Copy Metadata
1002:
1.13 www 1003: $copyfile=$copyfile.'.meta';
1004:
1005: if (copy($source.'.meta',$copyfile)) {
1.12 www 1006: print $logfile "Copied original metadata to ".$copyfile."\n";
1007: $scrout.='<p>Copied metadata';
1008: } else {
1.13 www 1009: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1.12 www 1010: return
1.13 www 1011: "<font color=red>Failed to write metadata copy, $!, FAIL</font>";
1.12 www 1012: }
1013:
1014: # --------------------------------------------------- Send update notifications
1015:
1.85 albertel 1016: my @subscribed=&get_subscribed_hosts($target);
1017: foreach my $subhost (@subscribed) {
1018: $scrout.='<p>Notifying host '.$subhost.':';
1019: print $logfile "\nNotifying host ".$subhost.':';
1020: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
1021: $scrout.=$reply;
1022: print $logfile $reply;
1.20 www 1023: }
1024:
1025: # ---------------------------------------- Send update notifications, meta only
1026:
1.85 albertel 1027: my @subscribedmeta=&get_subscribed_hosts("$target.meta");
1028: foreach my $subhost (@subscribedmeta) {
1029: $scrout.='<p>Notifying host for metadata only '.$subhost.':';
1030: print $logfile "\nNotifying host for metadata only ".$subhost.':';
1031: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
1032: $subhost);
1033: $scrout.=$reply;
1034: print $logfile $reply;
1.12 www 1035: }
1036:
1037: # ------------------------------------------------ Provide link to new resource
1038:
1039: my $thisdistarget=$target;
1040: $thisdistarget=~s/^$docroot//;
1041:
1.22 www 1042: my $thissrc=$source;
1043: $thissrc=~s/^\/home\/(\w+)\/public_html/\/priv\/$1/;
1044:
1045: my $thissrcdir=$thissrc;
1046: $thissrcdir=~s/\/[^\/]+$/\//;
1047:
1048:
1.29 harris41 1049: return $warning.$scrout.
1.75 matthew 1050: '<hr><a href="'.$thisdistarget.'"><font size=+2>View Published Version</font></a>'.
1.22 www 1051: '<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'.
1052: '<p><a href="'.$thissrcdir.
1053: '"><font size=+2>Back to Source Directory</font></a>';
1054:
1.11 www 1055: }
1056:
1.1 www 1057: # ================================================================ Main Handler
1058:
1059: sub handler {
1060: my $r=shift;
1.2 www 1061:
1062: if ($r->header_only) {
1063: $r->content_type('text/html');
1064: $r->send_http_header;
1065: return OK;
1066: }
1067:
1.43 www 1068: # Get query string for limited number of parameters
1069:
1.80 matthew 1070: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1071: ['filename']);
1.43 www 1072:
1.2 www 1073: # -------------------------------------------------------------- Check filename
1074:
1075: my $fn=$ENV{'form.filename'};
1076:
1.27 www 1077:
1.2 www 1078: unless ($fn) {
1.27 www 1079: $r->log_reason($cuname.' at '.$cudom.
1.2 www 1080: ' trying to publish empty filename', $r->filename);
1081: return HTTP_NOT_FOUND;
1082: }
1.4 www 1083:
1.31 www 1084: ($cuname,$cudom)=
1085: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
1086: unless (($cuname) && ($cudom)) {
1.27 www 1087: $r->log_reason($cuname.' at '.$cudom.
1.4 www 1088: ' trying to publish file '.$ENV{'form.filename'}.
1.27 www 1089: ' ('.$fn.') - not authorized',
1090: $r->filename);
1091: return HTTP_NOT_ACCEPTABLE;
1092: }
1093:
1094: unless (&Apache::lonnet::homeserver($cuname,$cudom)
1095: eq $r->dir_config('lonHostID')) {
1096: $r->log_reason($cuname.' at '.$cudom.
1097: ' trying to publish file '.$ENV{'form.filename'}.
1098: ' ('.$fn.') - not homeserver ('.
1099: &Apache::lonnet::homeserver($cuname,$cudom).')',
1.4 www 1100: $r->filename);
1101: return HTTP_NOT_ACCEPTABLE;
1102: }
1.2 www 1103:
1.43 www 1104: $fn=~s/^http\:\/\/[^\/]+//;
1105: $fn=~s/^\/\~(\w+)/\/home\/$1\/public_html/;
1.2 www 1106:
1107: my $targetdir='';
1.12 www 1108: $docroot=$r->dir_config('lonDocRoot');
1.27 www 1109: if ($1 ne $cuname) {
1110: $r->log_reason($cuname.' at '.$cudom.
1.2 www 1111: ' trying to publish unowned file '.$ENV{'form.filename'}.
1112: ' ('.$fn.')',
1113: $r->filename);
1114: return HTTP_NOT_ACCEPTABLE;
1115: } else {
1.27 www 1116: $targetdir=$docroot.'/res/'.$cudom;
1.2 www 1117: }
1118:
1119:
1120: unless (-e $fn) {
1.27 www 1121: $r->log_reason($cuname.' at '.$cudom.
1.2 www 1122: ' trying to publish non-existing file '.$ENV{'form.filename'}.
1123: ' ('.$fn.')',
1124: $r->filename);
1125: return HTTP_NOT_FOUND;
1126: }
1127:
1.11 www 1128: unless ($ENV{'form.phase'} eq 'two') {
1129:
1.2 www 1130: # --------------------------------- File is there and owned, init lookup tables
1131:
1.3 www 1132: %addid=();
1133:
1134: {
1135: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab');
1136: while (<$fh>=~/(\w+)\s+(\w+)/) {
1137: $addid{$1}=$2;
1138: }
1.5 www 1139: }
1140:
1141: %nokey=();
1142:
1143: {
1144: my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab');
1.65 harris41 1145: while (<$fh>) {
1.5 www 1146: my $word=$_;
1147: chomp($word);
1148: $nokey{$word}=1;
1.65 harris41 1149: }
1.3 www 1150: }
1.11 www 1151:
1152: }
1153:
1.2 www 1154: # ----------------------------------------------------------- Start page output
1155:
1.1 www 1156: $r->content_type('text/html');
1157: $r->send_http_header;
1158:
1159: $r->print('<html><head><title>LON-CAPA Publishing</title></head>');
1.15 www 1160: $r->print(
1161: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
1.2 www 1162: my $thisfn=$fn;
1163:
1164: # ------------------------------------------------------------- Individual file
1165: {
1166: $thisfn=~/\.(\w+)$/;
1167: my $thistype=$1;
1.65 harris41 1168: my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
1.2 www 1169:
1170: my $thistarget=$thisfn;
1171:
1172: $thistarget=~s/^\/home/$targetdir/;
1173: $thistarget=~s/\/public\_html//;
1174:
1175: my $thisdistarget=$thistarget;
1176: $thisdistarget=~s/^$docroot//;
1177:
1178: my $thisdisfn=$thisfn;
1.27 www 1179: $thisdisfn=~s/^\/home\/$cuname\/public_html\///;
1.2 www 1180:
1181: $r->print('<h2>Publishing '.
1.66 harris41 1182: &Apache::loncommon::filedescription($thistype).' <tt>'.
1.2 www 1183: $thisdisfn.'</tt></h2><b>Target:</b> <tt>'.$thisdistarget.'</tt><p>');
1.27 www 1184:
1185: if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
1186: $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
1187: '</font></h3>');
1188: }
1.26 www 1189:
1.65 harris41 1190: if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
1.28 www 1191: $r->print('<br><a href="/adm/diff?filename=/~'.$cuname.'/'.
1192: $thisdisfn.
1.26 www 1193: '&versionone=priv" target=cat>Diffs with Current Version</a><p>');
1194: }
1.11 www 1195:
1.2 www 1196: # ------------ We are publishing from $thisfn to $thistarget with $thisembstyle
1197:
1.11 www 1198: unless ($ENV{'form.phase'} eq 'two') {
1.27 www 1199: $r->print(
1200: '<hr>'.&publish($thisfn,$thistarget,$thisembstyle));
1.11 www 1201: } else {
1.27 www 1202: $r->print(
1203: '<hr>'.&phasetwo($thisfn,$thistarget,$thisembstyle,$thisdistarget));
1.11 www 1204: }
1.2 www 1205:
1.11 www 1206: }
1.1 www 1207: $r->print('</body></html>');
1.15 www 1208:
1.1 www 1209: return OK;
1210: }
1211:
1212: 1;
1213: __END__
1214:
1.66 harris41 1215: =head1 NAME
1.1 www 1216:
1.66 harris41 1217: Apache::lonpublisher - Publication Handler
1.1 www 1218:
1.66 harris41 1219: =head1 SYNOPSIS
1.1 www 1220:
1.66 harris41 1221: Invoked by /etc/httpd/conf/srm.conf:
1.1 www 1222:
1.66 harris41 1223: <Location /adm/publish>
1224: PerlAccessHandler Apache::lonacc
1225: SetHandler perl-script
1226: PerlHandler Apache::lonpublisher
1227: ErrorDocument 403 /adm/login
1228: ErrorDocument 404 /adm/notfound.html
1229: ErrorDocument 406 /adm/unauthorized.html
1230: ErrorDocument 500 /adm/errorhandler
1231: </Location>
1.1 www 1232:
1.66 harris41 1233: =head1 INTRODUCTION
1.1 www 1234:
1.66 harris41 1235: This module publishes a file. This involves gathering metadata,
1236: versioning the file, copying file from construction space to
1237: publication space, and copying metadata from construction space
1238: to publication space.
1239:
1240: This is part of the LearningOnline Network with CAPA project
1241: described at http://www.lon-capa.org.
1242:
1243: =head1 HANDLER SUBROUTINE
1244:
1245: This routine is called by Apache and mod_perl.
1246:
1247: =over 4
1248:
1249: =item *
1250:
1251: Get query string for limited number of parameters
1252:
1253: =item *
1254:
1255: Check filename
1256:
1257: =item *
1258:
1259: File is there and owned, init lookup tables
1260:
1261: =item *
1262:
1263: Start page output
1264:
1265: =item *
1266:
1267: Individual file
1268:
1269: =item *
1270:
1271: publish from $thisfn to $thistarget with $thisembstyle
1272:
1273: =back
1274:
1275: =head1 OTHER SUBROUTINES
1276:
1277: =over 4
1278:
1279: =item *
1280:
1281: metaeval() : Evaluate string with metadata
1282:
1283: =item *
1284:
1285: metaread() : Read a metadata file
1286:
1287: =item *
1288:
1289: sqltime() : convert 'time' format into a datetime sql format
1290:
1291: =item *
1292:
1293: textfield() : form field
1294:
1295: =item *
1296:
1297: hiddenfield() : form field
1298:
1299: =item *
1300:
1301: selectbox() : form field
1302:
1303: =item *
1304:
1305: urlfixup() : fixup URL (Publication Step One)
1306:
1307: =item *
1308:
1309: publish() : publish (Publication Step One)
1310:
1311: =item *
1312:
1313: phasetwo() : render second interface showing status of publication steps
1314: (Publication Step Two)
1315:
1316: =back
1317:
1318: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>