Annotation of loncom/publisher/lonpublisher.pm, revision 1.88
1.1 www 1: # The LearningOnline Network with CAPA
2: # Publication Handler
1.54 albertel 3: #
1.88 ! albertel 4: # $Id: lonpublisher.pm,v 1.87 2002/08/07 19:50:22 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(.*)/) {
1.88 ! albertel 319: #&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);
! 320: #&Apache::lonnet::logthis('Result is :'.$1);
1.87 albertel 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: if ($key =~ /^$type$/i) {
385: $parms{$key}=&set_allow(\%allow,$logfile,
386: $target,$tag,
387: $parms{$key});
388: }
389: }
390: }
391: # probably a <randomlabel> image type <label>
392: if ($lctag eq 'label' && defined($parms{'description'})) {
393: my $next_token=$parser[-1]->get_token();
394: if ($next_token->[0] eq 'T') {
395: $next_token->[1]=&set_allow(\%allow,$logfile,
396: $target,$tag,
397: $next_token->[1]);
398: }
399: $parser[-1]->unget_token($next_token);
400: }
401: if ($lctag eq 'applet') {
402: my $codebase='';
403: if (defined($parms{'codebase'})) {
404: my $oldcodebase=$parms{'codebase'};
405: unless ($oldcodebase=~/\/$/) {
406: $oldcodebase.='/';
407: }
408: $codebase=&urlfixup($oldcodebase,$target);
409: $codebase=~s/\/$//;
410: if ($codebase ne $oldcodebase) {
411: $parms{'codebase'}=$codebase;
412: print $logfile 'URL codebase: '.$tag.':'.
413: $oldcodebase.' - '.
414: $codebase."\n";
415: }
416: $allow{&absoluteurl($codebase,$target).'/*'}=1;
417: } else {
418: foreach ('archive','code','object') {
419: if (defined($parms{$_})) {
420: my $oldurl=$parms{$_};
421: my $newurl=&urlfixup($oldurl,$target);
422: $newurl=~s/\/[^\/]+$/\/\*/;
423: print $logfile 'Allow: applet '.$_.':'.
424: $oldurl.' allows '.
425: $newurl."\n";
426: $allow{&absoluteurl($newurl,$target)}=1;
427: }
428: }
429: }
430: }
431: my $newparmstring='';
432: my $endtag='';
433: foreach (keys %parms) {
434: if ($_ eq '/') {
435: $endtag=' /';
436: } else {
437: my $quote=($parms{$_}=~/\"/?"'":'"');
438: $newparmstring.=' '.$_.'='.$quote.$parms{$_}.$quote;
439: }
440: }
441: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
442: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1.87 albertel 443: if ($lctag eq 'm') {
444: $outstring.=&get_all_text_unbalanced('/m',\@parser);
445: }
1.86 albertel 446: } elsif ($token->[0] eq 'E') {
447: if ($token->[2]) {
448: unless ($token->[1] eq 'allow') {
449: $outstring.='</'.$token->[1].'>';
450: }
451: }
452: } else {
453: $outstring.=$token->[1];
454: }
455: }
456: pop(@parser);
457: }
458:
459: if ($needsfixup) {
460: print $logfile "End of ID and/or index fixup\n".
461: "Max ID : $maxid (min 10)\n".
462: "Max Index: $maxindex (min 10)\n";
463: } else {
464: print $logfile "Does not need ID and/or index fixup\n";
465: }
466:
467: return ($outstring,%allow);
468: }
469:
1.2 www 470: sub publish {
1.50 www 471:
1.2 www 472: my ($source,$target,$style)=@_;
473: my $logfile;
1.4 www 474: my $scrout='';
1.23 www 475: my $allmeta='';
476: my $content='';
1.36 www 477: my %allow=();
1.4 www 478:
1.2 www 479: unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
1.7 www 480: return
481: '<font color=red>No write permission to user directory, FAIL</font>';
1.2 www 482: }
483: print $logfile
1.11 www 484: "\n\n================= Publish ".localtime()." Phase One ================\n";
1.2 www 485:
1.3 www 486: if (($style eq 'ssi') || ($style eq 'rat')) {
487: # ------------------------------------------------------- This needs processing
1.4 www 488:
489: # ----------------------------------------------------------------- Backup Copy
1.3 www 490: my $copyfile=$source.'.save';
1.13 www 491: if (copy($source,$copyfile)) {
1.3 www 492: print $logfile "Copied original file to ".$copyfile."\n";
493: } else {
1.13 www 494: print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";
495: return "<font color=red>Failed to write backup copy, $!,FAIL</font>";
1.3 www 496: }
1.4 www 497: # ------------------------------------------------------------- IDs and indices
1.86 albertel 498:
499: my $outstring;
500: ($outstring,%allow)=&fix_ids_and_indices($logfile,$source,$target);
1.36 www 501: # ------------------------------------------------------------ Construct Allows
1.62 www 502:
1.44 www 503: $scrout.='<h3>Dependencies</h3>';
1.62 www 504: my $allowstr='';
1.73 albertel 505: foreach (sort(keys(%allow))) {
1.59 www 506: my $thisdep=$_;
1.73 albertel 507: if ($thisdep !~ /[^\s]/) { next; }
1.62 www 508: unless ($style eq 'rat') {
509: $allowstr.="\n".'<allow src="'.$thisdep.'" />';
510: }
1.44 www 511: $scrout.='<br>';
1.59 www 512: unless ($thisdep=~/\*/) {
513: $scrout.='<a href="'.$thisdep.'">';
1.44 www 514: }
1.59 www 515: $scrout.='<tt>'.$thisdep.'</tt>';
516: unless ($thisdep=~/\*/) {
1.44 www 517: $scrout.='</a>';
1.59 www 518: if (
519: &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
520: $thisdep.'.meta') eq '-1') {
1.58 www 521: $scrout.=
522: ' - <font color=red>Currently not available</font>';
1.59 www 523: } else {
524: my %temphash=(&Apache::lonnet::declutter($target).'___'.
525: &Apache::lonnet::declutter($thisdep).'___usage'
526: => time);
527: $thisdep=~/^\/res\/(\w+)\/(\w+)\//;
528: if ((defined($1)) && (defined($2))) {
529: &Apache::lonnet::put('resevaldata',\%temphash,$1,$2);
530: }
531: }
1.44 www 532: }
1.65 harris41 533: }
1.83 www 534: $outstring=~s/\n*(\<\/[^\>]+\>)\s*$/$allowstr\n$1\n/s;
1.62 www 535:
1.76 albertel 536: #Encode any High ASCII characters
537: $outstring=&HTML::Entities::encode($outstring,"\200-\377");
1.37 www 538: # ------------------------------------------------------------- Write modified
539:
1.4 www 540: {
541: my $org;
542: unless ($org=Apache::File->new('>'.$source)) {
543: print $logfile "No write permit to $source\n";
1.7 www 544: return
545: "<font color=red>No write permission to $source, FAIL</font>";
1.4 www 546: }
547: print $org $outstring;
548: }
549: $content=$outstring;
1.34 www 550:
1.37 www 551: }
1.7 www 552: # --------------------------------------------- Initial step done, now metadata
553:
554: # ---------------------------------------- Storage for metadata keys and fields
555:
1.8 www 556: %metadatafields=();
557: %metadatakeys=();
558:
559: my %oldparmstores=();
1.44 www 560:
1.84 bowersj2 561:
562: $scrout.='<h3>Metadata Information ' .
563: Apache::loncommon::help_open_topic("Metadata_Description")
564: . '</h3>';
1.7 www 565:
566: # ------------------------------------------------ First, check out environment
1.8 www 567: unless (-e $source.'.meta') {
1.7 www 568: $metadatafields{'author'}=$ENV{'environment.firstname'}.' '.
569: $ENV{'environment.middlename'}.' '.
570: $ENV{'environment.lastname'}.' '.
571: $ENV{'environment.generation'};
1.8 www 572: $metadatafields{'author'}=~s/\s+/ /g;
573: $metadatafields{'author'}=~s/\s+$//;
1.27 www 574: $metadatafields{'owner'}=$cuname.'@'.$cudom;
1.7 www 575:
576: # ------------------------------------------------ Check out directory hierachy
577:
578: my $thisdisfn=$source;
1.27 www 579: $thisdisfn=~s/^\/home\/$cuname\///;
1.7 www 580:
581: my @urlparts=split(/\//,$thisdisfn);
582: $#urlparts--;
583:
1.27 www 584: my $currentpath='/home/'.$cuname.'/';
1.7 www 585:
1.65 harris41 586: foreach (@urlparts) {
1.7 www 587: $currentpath.=$_.'/';
588: $scrout.=&metaread($logfile,$currentpath.'default.meta');
1.65 harris41 589: }
1.7 www 590:
591: # ------------------- Clear out parameters and stores (there should not be any)
592:
1.65 harris41 593: foreach (keys %metadatafields) {
1.7 www 594: if (($_=~/^parameter/) || ($_=~/^stores/)) {
595: delete $metadatafields{$_};
596: }
1.65 harris41 597: }
1.7 www 598:
1.8 www 599: } else {
1.7 www 600: # ---------------------- Read previous metafile, remember parameters and stores
601:
602: $scrout.=&metaread($logfile,$source.'.meta');
603:
1.65 harris41 604: foreach (keys %metadatafields) {
1.7 www 605: if (($_=~/^parameter/) || ($_=~/^stores/)) {
606: $oldparmstores{$_}=1;
607: delete $metadatafields{$_};
608: }
1.65 harris41 609: }
1.7 www 610:
1.8 www 611: }
1.7 www 612:
1.4 www 613: # -------------------------------------------------- Parse content for metadata
1.37 www 614: if ($style eq 'ssi') {
1.42 www 615: my $oldenv=$ENV{'request.uri'};
616:
617: $ENV{'request.uri'}=$target;
1.82 albertel 618: $allmeta=Apache::lonxml::xmlparse(undef,'meta',$content);
1.42 www 619: $ENV{'request.uri'}=$oldenv;
1.32 www 620:
1.19 albertel 621: &metaeval($allmeta);
1.37 www 622: }
1.7 www 623: # ---------------- Find and document discrepancies in the parameters and stores
624:
625: my $chparms='';
1.65 harris41 626: foreach (sort keys %metadatafields) {
1.7 www 627: if (($_=~/^parameter/) || ($_=~/^stores/)) {
628: unless ($_=~/\.\w+$/) {
629: unless ($oldparmstores{$_}) {
630: print $logfile 'New: '.$_."\n";
631: $chparms.=$_.' ';
632: }
633: }
634: }
1.65 harris41 635: }
1.7 www 636: if ($chparms) {
637: $scrout.='<p><b>New parameters or stored values:</b> '.
638: $chparms;
639: }
640:
1.70 harris41 641: $chparms='';
1.65 harris41 642: foreach (sort keys %oldparmstores) {
1.7 www 643: if (($_=~/^parameter/) || ($_=~/^stores/)) {
1.33 www 644: unless (($metadatafields{$_.'.name'}) ||
645: ($metadatafields{$_.'.package'}) || ($_=~/\.\w+$/)) {
1.7 www 646: print $logfile 'Obsolete: '.$_."\n";
647: $chparms.=$_.' ';
648: }
649: }
1.65 harris41 650: }
1.7 www 651: if ($chparms) {
652: $scrout.='<p><b>Obsolete parameters or stored values:</b> '.
653: $chparms;
654: }
1.37 www 655:
1.8 www 656: # ------------------------------------------------------- Now have all metadata
1.5 www 657:
1.8 www 658: $scrout.=
1.77 matthew 659: '<form name="pubform" action="/adm/publish" method="post">'.
1.63 albertel 660: '<p><input type="submit" value="Finalize Publication" /></p>'.
1.11 www 661: &hiddenfield('phase','two').
662: &hiddenfield('filename',$ENV{'form.filename'}).
663: &hiddenfield('allmeta',&Apache::lonnet::escape($allmeta)).
1.58 www 664: &hiddenfield('dependencies',join(',',keys %allow)).
1.10 www 665: &textfield('Title','title',$metadatafields{'title'}).
666: &textfield('Author(s)','author',$metadatafields{'author'}).
667: &textfield('Subject','subject',$metadatafields{'subject'});
1.5 www 668:
669: # --------------------------------------------------- Scan content for keywords
1.7 www 670:
1.84 bowersj2 671: my $keywords_help = Apache::loncommon::help_open_topic("Publishing_Keywords");
1.77 matthew 672: my $keywordout=<<"END";
673: <script>
674: function checkAll(field)
675: {
676: for (i = 0; i < field.length; i++)
677: field[i].checked = true ;
678: }
679:
680: function uncheckAll(field)
681: {
682: for (i = 0; i < field.length; i++)
683: field[i].checked = false ;
684: }
685: </script>
1.84 bowersj2 686: <p><b>Keywords: $keywords_help</b>
1.77 matthew 687: <input type="button" value="check all" onclick="javascript:checkAll(document.pubform.keywords)">
688: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.pubform.keywords)">
689: <br />
690: END
691: $keywordout.='<table border=2><tr>';
1.7 www 692: my $colcount=0;
1.67 www 693: my %keywords=();
1.7 www 694:
1.52 albertel 695: if (length($content)<500000) {
1.5 www 696: my $textonly=$content;
697: $textonly=~s/\<script[^\<]+\<\/script\>//g;
698: $textonly=~s/\<m\>[^\<]+\<\/m\>//g;
699: $textonly=~s/\<[^\>]*\>//g;
700: $textonly=~tr/A-Z/a-z/;
701: $textonly=~s/[\$\&][a-z]\w*//g;
702: $textonly=~s/[^a-z\s]//g;
703:
1.65 harris41 704: foreach ($textonly=~m/(\w+)/g) {
1.50 www 705: unless ($nokey{$_}) {
706: $keywords{$_}=1;
707: }
1.65 harris41 708: }
1.67 www 709: }
1.5 www 710:
1.67 www 711:
1.65 harris41 712: foreach (split(/\W+/,$metadatafields{'keywords'})) {
1.12 www 713: $keywords{$_}=1;
1.65 harris41 714: }
1.5 www 715:
1.65 harris41 716: foreach (sort keys %keywords) {
1.77 matthew 717: $keywordout.='<td><input type=checkbox name="keywords" value="'.$_.'"';
1.67 www 718: if ($metadatafields{'keywords'}) {
719: if ($metadatafields{'keywords'}=~/$_/) {
720: $keywordout.=' checked';
721: }
722: } elsif (&Apache::loncommon::keyword($_)) {
1.73 albertel 723: $keywordout.=' checked';
1.67 www 724: }
1.8 www 725: $keywordout.='>'.$_.'</td>';
1.7 www 726: if ($colcount>10) {
727: $keywordout.="</tr><tr>\n";
728: $colcount=0;
729: }
1.50 www 730: $colcount++;
1.65 harris41 731: }
1.50 www 732:
1.51 www 733: $keywordout.='</tr></table>';
734:
735: $scrout.=$keywordout;
1.9 www 736:
1.12 www 737: $scrout.=&textfield('Additional Keywords','addkey','');
738:
1.10 www 739: $scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
1.9 www 740:
741: $scrout.=
742: '<p><b>Abstract:</b><br><textarea cols=80 rows=5 name=abstract>'.
743: $metadatafields{'abstract'}.'</textarea>';
744:
1.11 www 745: $source=~/\.(\w+)$/;
746:
747: $scrout.=&hiddenfield('mime',$1);
748:
1.10 www 749: $scrout.=&selectbox('Language','language',
1.65 harris41 750: $metadatafields{'language'},
1.70 harris41 751: \&Apache::loncommon::languagedescription,
1.65 harris41 752: (&Apache::loncommon::languageids),
753: );
1.11 www 754:
755: unless ($metadatafields{'creationdate'}) {
756: $metadatafields{'creationdate'}=time;
757: }
758: $scrout.=&hiddenfield('creationdate',$metadatafields{'creationdate'});
759:
760: $scrout.=&hiddenfield('lastrevisiondate',time);
761:
1.9 www 762:
1.10 www 763: $scrout.=&textfield('Publisher/Owner','owner',
764: $metadatafields{'owner'});
1.45 www 765: # --------------------------------------------------- Correct copyright for rat
1.84 bowersj2 766:
1.45 www 767: if ($style eq 'rat') {
1.65 harris41 768: if ($metadatafields{'copyright'} eq 'public') {
769: delete $metadatafields{'copyright'};
770: }
771: $scrout.=&selectbox('Copyright/Distribution','copyright',
772: $metadatafields{'copyright'},
1.70 harris41 773: \&Apache::loncommon::copyrightdescription,
1.65 harris41 774: (grep !/^public$/,(&Apache::loncommon::copyrightids)));
775: }
776: else {
1.10 www 777: $scrout.=&selectbox('Copyright/Distribution','copyright',
1.65 harris41 778: $metadatafields{'copyright'},
1.70 harris41 779: \&Apache::loncommon::copyrightdescription,
1.65 harris41 780: (&Apache::loncommon::copyrightids));
781: }
1.84 bowersj2 782:
783: my $copyright_help = Apache::loncommon::help_open_topic("Publishing_Copyright");
784: $scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;
1.8 www 785: return $scrout.
1.63 albertel 786: '<p><input type="submit" value="Finalize Publication" /></p></form>';
1.2 www 787: }
1.1 www 788:
1.12 www 789: # -------------------------------------------------------- Publication Step Two
790:
1.11 www 791: sub phasetwo {
792:
1.24 harris41 793: my ($source,$target,$style,$distarget)=@_;
1.11 www 794: my $logfile;
795: my $scrout='';
796: unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
797: return
798: '<font color=red>No write permission to user directory, FAIL</font>';
799: }
800: print $logfile
801: "\n================= Publish ".localtime()." Phase Two ================\n";
802:
803: %metadatafields=();
804: %metadatakeys=();
805:
806: &metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'}));
807:
808: $metadatafields{'title'}=$ENV{'form.title'};
809: $metadatafields{'author'}=$ENV{'form.author'};
810: $metadatafields{'subject'}=$ENV{'form.subject'};
811: $metadatafields{'notes'}=$ENV{'form.notes'};
812: $metadatafields{'abstract'}=$ENV{'form.abstract'};
813: $metadatafields{'mime'}=$ENV{'form.mime'};
814: $metadatafields{'language'}=$ENV{'form.language'};
815: $metadatafields{'creationdate'}=$ENV{'form.creationdate'};
816: $metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'};
817: $metadatafields{'owner'}=$ENV{'form.owner'};
818: $metadatafields{'copyright'}=$ENV{'form.copyright'};
1.60 www 819: $metadatafields{'dependencies'}=$ENV{'form.dependencies'};
1.12 www 820:
821: my $allkeywords=$ENV{'form.addkey'};
1.79 matthew 822: if (exists($ENV{'form.keywords'}) && (ref($ENV{'form.keywords'}))) {
1.78 matthew 823: my @Keywords = @{$ENV{'form.keywords'}};
824: foreach (@Keywords) {
825: $allkeywords.=','.$_;
826: }
1.65 harris41 827: }
1.12 www 828: $allkeywords=~s/\W+/\,/;
829: $allkeywords=~s/^\,//;
830: $metadatafields{'keywords'}=$allkeywords;
831:
832: {
833: print $logfile "\nWrite metadata file for ".$source;
834: my $mfh;
835: unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
836: return
837: '<font color=red>Could not write metadata, FAIL</font>';
1.65 harris41 838: }
839: foreach (sort keys %metadatafields) {
1.12 www 840: unless ($_=~/\./) {
841: my $unikey=$_;
842: $unikey=~/^([A-Za-z]+)/;
843: my $tag=$1;
844: $tag=~tr/A-Z/a-z/;
845: print $mfh "\n\<$tag";
1.65 harris41 846: foreach (split(/\,/,$metadatakeys{$unikey})) {
1.12 www 847: my $value=$metadatafields{$unikey.'.'.$_};
848: $value=~s/\"/\'\'/g;
849: print $mfh ' '.$_.'="'.$value.'"';
1.65 harris41 850: }
1.76 albertel 851: print $mfh '>'.
852: &HTML::Entities::encode($metadatafields{$unikey})
853: .'</'.$tag.'>';
1.12 www 854: }
1.65 harris41 855: }
1.12 www 856: $scrout.='<p>Wrote Metadata';
857: print $logfile "\nWrote metadata";
858: }
859:
1.24 harris41 860: # -------------------------------- Synchronize entry with SQL metadata database
1.64 www 861: my $warning;
862:
863: unless ($metadatafields{'copyright'} eq 'priv') {
1.25 harris41 864:
1.24 harris41 865: my $dbh;
866: {
867: unless (
1.64 www 868: $dbh = DBI->connect("DBI:mysql:loncapa","www",
869: $Apache::lonnet::perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0})
1.24 harris41 870: ) {
1.29 harris41 871: $warning='<font color=red>WARNING: Cannot connect to '.
872: 'database!</font>';
873: }
874: else {
875: my %sqldatafields;
876: $sqldatafields{'url'}=$distarget;
877: my $sth=$dbh->prepare(
878: 'delete from metadata where url like binary'.
879: '"'.$sqldatafields{'url'}.'"');
880: $sth->execute();
1.65 harris41 881: foreach ('title','author','subject','keywords','notes','abstract',
1.29 harris41 882: 'mime','language','creationdate','lastrevisiondate','owner',
1.65 harris41 883: 'copyright') {
884: my $field=$metadatafields{$_}; $field=~s/\"/\'\'/g;
885: $sqldatafields{$_}=$field;
886: }
1.29 harris41 887:
888: $sth=$dbh->prepare('insert into metadata values ('.
889: '"'.delete($sqldatafields{'title'}).'"'.','.
890: '"'.delete($sqldatafields{'author'}).'"'.','.
891: '"'.delete($sqldatafields{'subject'}).'"'.','.
892: '"'.delete($sqldatafields{'url'}).'"'.','.
893: '"'.delete($sqldatafields{'keywords'}).'"'.','.
894: '"'.'current'.'"'.','.
895: '"'.delete($sqldatafields{'notes'}).'"'.','.
896: '"'.delete($sqldatafields{'abstract'}).'"'.','.
897: '"'.delete($sqldatafields{'mime'}).'"'.','.
898: '"'.delete($sqldatafields{'language'}).'"'.','.
899: '"'.
900: sqltime(delete($sqldatafields{'creationdate'}))
901: .'"'.','.
902: '"'.
903: sqltime(delete(
904: $sqldatafields{'lastrevisiondate'})).'"'.','.
905: '"'.delete($sqldatafields{'owner'}).'"'.','.
906: '"'.delete(
907: $sqldatafields{'copyright'}).'"'.')');
908: $sth->execute();
909: $dbh->disconnect;
910: $scrout.='<p>Synchronized SQL metadata database';
911: print $logfile "\nSynchronized SQL metadata database";
1.24 harris41 912: }
913: }
914:
1.64 www 915: } else {
916: $scrout.='<p>Private Publication - did not synchronize database';
1.66 harris41 917: print $logfile "\nPrivate: Did not synchronize data into ".
918: "SQL metadata database";
1.64 www 919: }
1.12 www 920: # ----------------------------------------------------------- Copy old versions
921:
922: if (-e $target) {
923: my $filename;
924: my $maxversion=0;
925: $target=~/(.*)\/([^\/]+)\.(\w+)$/;
926: my $srcf=$2;
927: my $srct=$3;
928: my $srcd=$1;
929: unless ($srcd=~/^\/home\/httpd\/html\/res/) {
930: print $logfile "\nPANIC: Target dir is ".$srcd;
931: return "<font color=red>Invalid target directory, FAIL</font>";
932: }
933: opendir(DIR,$srcd);
934: while ($filename=readdir(DIR)) {
935: if ($filename=~/$srcf\.(\d+)\.$srct$/) {
936: $maxversion=($1>$maxversion)?$1:$maxversion;
937: }
938: }
939: closedir(DIR);
940: $maxversion++;
941: $scrout.='<p>Creating old version '.$maxversion;
942: print $logfile "\nCreating old version ".$maxversion;
943:
944: my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct;
945:
1.13 www 946: if (copy($target,$copyfile)) {
1.12 www 947: print $logfile "Copied old target to ".$copyfile."\n";
948: $scrout.='<p>Copied old target file';
949: } else {
1.13 www 950: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
951: return "<font color=red>Failed to copy old target, $!, FAIL</font>";
1.12 www 952: }
953:
954: # --------------------------------------------------------------- Copy Metadata
955:
956: $copyfile=$copyfile.'.meta';
1.13 www 957:
958: if (copy($target.'.meta',$copyfile)) {
1.14 www 959: print $logfile "Copied old target metadata to ".$copyfile."\n";
1.12 www 960: $scrout.='<p>Copied old metadata';
961: } else {
1.13 www 962: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1.14 www 963: if (-e $target.'.meta') {
964: return
1.13 www 965: "<font color=red>Failed to write old metadata copy, $!, FAIL</font>";
1.14 www 966: }
1.12 www 967: }
1.11 www 968:
969:
1.12 www 970: } else {
971: $scrout.='<p>Initial version';
972: print $logfile "\nInitial version";
973: }
974:
975: # ---------------------------------------------------------------- Write Source
976: my $copyfile=$target;
977:
978: my @parts=split(/\//,$copyfile);
979: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
980:
981: my $count;
982: for ($count=5;$count<$#parts;$count++) {
983: $path.="/$parts[$count]";
984: if ((-e $path)!=1) {
985: print $logfile "\nCreating directory ".$path;
986: $scrout.='<p>Created directory '.$parts[$count];
987: mkdir($path,0777);
988: }
989: }
990:
1.13 www 991: if (copy($source,$copyfile)) {
1.12 www 992: print $logfile "Copied original source to ".$copyfile."\n";
993: $scrout.='<p>Copied source file';
994: } else {
1.13 www 995: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
996: return "<font color=red>Failed to copy source, $!, FAIL</font>";
1.12 www 997: }
998:
999: # --------------------------------------------------------------- Copy Metadata
1000:
1.13 www 1001: $copyfile=$copyfile.'.meta';
1002:
1003: if (copy($source.'.meta',$copyfile)) {
1.12 www 1004: print $logfile "Copied original metadata to ".$copyfile."\n";
1005: $scrout.='<p>Copied metadata';
1006: } else {
1.13 www 1007: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1.12 www 1008: return
1.13 www 1009: "<font color=red>Failed to write metadata copy, $!, FAIL</font>";
1.12 www 1010: }
1011:
1012: # --------------------------------------------------- Send update notifications
1013:
1.85 albertel 1014: my @subscribed=&get_subscribed_hosts($target);
1015: foreach my $subhost (@subscribed) {
1016: $scrout.='<p>Notifying host '.$subhost.':';
1017: print $logfile "\nNotifying host ".$subhost.':';
1018: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
1019: $scrout.=$reply;
1020: print $logfile $reply;
1.20 www 1021: }
1022:
1023: # ---------------------------------------- Send update notifications, meta only
1024:
1.85 albertel 1025: my @subscribedmeta=&get_subscribed_hosts("$target.meta");
1026: foreach my $subhost (@subscribedmeta) {
1027: $scrout.='<p>Notifying host for metadata only '.$subhost.':';
1028: print $logfile "\nNotifying host for metadata only ".$subhost.':';
1029: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
1030: $subhost);
1031: $scrout.=$reply;
1032: print $logfile $reply;
1.12 www 1033: }
1034:
1035: # ------------------------------------------------ Provide link to new resource
1036:
1037: my $thisdistarget=$target;
1038: $thisdistarget=~s/^$docroot//;
1039:
1.22 www 1040: my $thissrc=$source;
1041: $thissrc=~s/^\/home\/(\w+)\/public_html/\/priv\/$1/;
1042:
1043: my $thissrcdir=$thissrc;
1044: $thissrcdir=~s/\/[^\/]+$/\//;
1045:
1046:
1.29 harris41 1047: return $warning.$scrout.
1.75 matthew 1048: '<hr><a href="'.$thisdistarget.'"><font size=+2>View Published Version</font></a>'.
1.22 www 1049: '<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'.
1050: '<p><a href="'.$thissrcdir.
1051: '"><font size=+2>Back to Source Directory</font></a>';
1052:
1.11 www 1053: }
1054:
1.1 www 1055: # ================================================================ Main Handler
1056:
1057: sub handler {
1058: my $r=shift;
1.2 www 1059:
1060: if ($r->header_only) {
1061: $r->content_type('text/html');
1062: $r->send_http_header;
1063: return OK;
1064: }
1065:
1.43 www 1066: # Get query string for limited number of parameters
1067:
1.80 matthew 1068: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1069: ['filename']);
1.43 www 1070:
1.2 www 1071: # -------------------------------------------------------------- Check filename
1072:
1073: my $fn=$ENV{'form.filename'};
1074:
1.27 www 1075:
1.2 www 1076: unless ($fn) {
1.27 www 1077: $r->log_reason($cuname.' at '.$cudom.
1.2 www 1078: ' trying to publish empty filename', $r->filename);
1079: return HTTP_NOT_FOUND;
1080: }
1.4 www 1081:
1.31 www 1082: ($cuname,$cudom)=
1083: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
1084: unless (($cuname) && ($cudom)) {
1.27 www 1085: $r->log_reason($cuname.' at '.$cudom.
1.4 www 1086: ' trying to publish file '.$ENV{'form.filename'}.
1.27 www 1087: ' ('.$fn.') - not authorized',
1088: $r->filename);
1089: return HTTP_NOT_ACCEPTABLE;
1090: }
1091:
1092: unless (&Apache::lonnet::homeserver($cuname,$cudom)
1093: eq $r->dir_config('lonHostID')) {
1094: $r->log_reason($cuname.' at '.$cudom.
1095: ' trying to publish file '.$ENV{'form.filename'}.
1096: ' ('.$fn.') - not homeserver ('.
1097: &Apache::lonnet::homeserver($cuname,$cudom).')',
1.4 www 1098: $r->filename);
1099: return HTTP_NOT_ACCEPTABLE;
1100: }
1.2 www 1101:
1.43 www 1102: $fn=~s/^http\:\/\/[^\/]+//;
1103: $fn=~s/^\/\~(\w+)/\/home\/$1\/public_html/;
1.2 www 1104:
1105: my $targetdir='';
1.12 www 1106: $docroot=$r->dir_config('lonDocRoot');
1.27 www 1107: if ($1 ne $cuname) {
1108: $r->log_reason($cuname.' at '.$cudom.
1.2 www 1109: ' trying to publish unowned file '.$ENV{'form.filename'}.
1110: ' ('.$fn.')',
1111: $r->filename);
1112: return HTTP_NOT_ACCEPTABLE;
1113: } else {
1.27 www 1114: $targetdir=$docroot.'/res/'.$cudom;
1.2 www 1115: }
1116:
1117:
1118: unless (-e $fn) {
1.27 www 1119: $r->log_reason($cuname.' at '.$cudom.
1.2 www 1120: ' trying to publish non-existing file '.$ENV{'form.filename'}.
1121: ' ('.$fn.')',
1122: $r->filename);
1123: return HTTP_NOT_FOUND;
1124: }
1125:
1.11 www 1126: unless ($ENV{'form.phase'} eq 'two') {
1127:
1.2 www 1128: # --------------------------------- File is there and owned, init lookup tables
1129:
1.3 www 1130: %addid=();
1131:
1132: {
1133: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab');
1134: while (<$fh>=~/(\w+)\s+(\w+)/) {
1135: $addid{$1}=$2;
1136: }
1.5 www 1137: }
1138:
1139: %nokey=();
1140:
1141: {
1142: my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab');
1.65 harris41 1143: while (<$fh>) {
1.5 www 1144: my $word=$_;
1145: chomp($word);
1146: $nokey{$word}=1;
1.65 harris41 1147: }
1.3 www 1148: }
1.11 www 1149:
1150: }
1151:
1.2 www 1152: # ----------------------------------------------------------- Start page output
1153:
1.1 www 1154: $r->content_type('text/html');
1155: $r->send_http_header;
1156:
1157: $r->print('<html><head><title>LON-CAPA Publishing</title></head>');
1.15 www 1158: $r->print(
1159: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
1.2 www 1160: my $thisfn=$fn;
1161:
1162: # ------------------------------------------------------------- Individual file
1163: {
1164: $thisfn=~/\.(\w+)$/;
1165: my $thistype=$1;
1.65 harris41 1166: my $thisembstyle=&Apache::loncommon::fileembstyle($thistype);
1.2 www 1167:
1168: my $thistarget=$thisfn;
1169:
1170: $thistarget=~s/^\/home/$targetdir/;
1171: $thistarget=~s/\/public\_html//;
1172:
1173: my $thisdistarget=$thistarget;
1174: $thisdistarget=~s/^$docroot//;
1175:
1176: my $thisdisfn=$thisfn;
1.27 www 1177: $thisdisfn=~s/^\/home\/$cuname\/public_html\///;
1.2 www 1178:
1179: $r->print('<h2>Publishing '.
1.66 harris41 1180: &Apache::loncommon::filedescription($thistype).' <tt>'.
1.2 www 1181: $thisdisfn.'</tt></h2><b>Target:</b> <tt>'.$thisdistarget.'</tt><p>');
1.27 www 1182:
1183: if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
1184: $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
1185: '</font></h3>');
1186: }
1.26 www 1187:
1.65 harris41 1188: if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
1.28 www 1189: $r->print('<br><a href="/adm/diff?filename=/~'.$cuname.'/'.
1190: $thisdisfn.
1.26 www 1191: '&versionone=priv" target=cat>Diffs with Current Version</a><p>');
1192: }
1.11 www 1193:
1.2 www 1194: # ------------ We are publishing from $thisfn to $thistarget with $thisembstyle
1195:
1.11 www 1196: unless ($ENV{'form.phase'} eq 'two') {
1.27 www 1197: $r->print(
1198: '<hr>'.&publish($thisfn,$thistarget,$thisembstyle));
1.11 www 1199: } else {
1.27 www 1200: $r->print(
1201: '<hr>'.&phasetwo($thisfn,$thistarget,$thisembstyle,$thisdistarget));
1.11 www 1202: }
1.2 www 1203:
1.11 www 1204: }
1.1 www 1205: $r->print('</body></html>');
1.15 www 1206:
1.1 www 1207: return OK;
1208: }
1209:
1210: 1;
1211: __END__
1212:
1.66 harris41 1213: =head1 NAME
1.1 www 1214:
1.66 harris41 1215: Apache::lonpublisher - Publication Handler
1.1 www 1216:
1.66 harris41 1217: =head1 SYNOPSIS
1.1 www 1218:
1.66 harris41 1219: Invoked by /etc/httpd/conf/srm.conf:
1.1 www 1220:
1.66 harris41 1221: <Location /adm/publish>
1222: PerlAccessHandler Apache::lonacc
1223: SetHandler perl-script
1224: PerlHandler Apache::lonpublisher
1225: ErrorDocument 403 /adm/login
1226: ErrorDocument 404 /adm/notfound.html
1227: ErrorDocument 406 /adm/unauthorized.html
1228: ErrorDocument 500 /adm/errorhandler
1229: </Location>
1.1 www 1230:
1.66 harris41 1231: =head1 INTRODUCTION
1.1 www 1232:
1.66 harris41 1233: This module publishes a file. This involves gathering metadata,
1234: versioning the file, copying file from construction space to
1235: publication space, and copying metadata from construction space
1236: to publication space.
1237:
1238: This is part of the LearningOnline Network with CAPA project
1239: described at http://www.lon-capa.org.
1240:
1241: =head1 HANDLER SUBROUTINE
1242:
1243: This routine is called by Apache and mod_perl.
1244:
1245: =over 4
1246:
1247: =item *
1248:
1249: Get query string for limited number of parameters
1250:
1251: =item *
1252:
1253: Check filename
1254:
1255: =item *
1256:
1257: File is there and owned, init lookup tables
1258:
1259: =item *
1260:
1261: Start page output
1262:
1263: =item *
1264:
1265: Individual file
1266:
1267: =item *
1268:
1269: publish from $thisfn to $thistarget with $thisembstyle
1270:
1271: =back
1272:
1273: =head1 OTHER SUBROUTINES
1274:
1275: =over 4
1276:
1277: =item *
1278:
1279: metaeval() : Evaluate string with metadata
1280:
1281: =item *
1282:
1283: metaread() : Read a metadata file
1284:
1285: =item *
1286:
1287: sqltime() : convert 'time' format into a datetime sql format
1288:
1289: =item *
1290:
1291: textfield() : form field
1292:
1293: =item *
1294:
1295: hiddenfield() : form field
1296:
1297: =item *
1298:
1299: selectbox() : form field
1300:
1301: =item *
1302:
1303: urlfixup() : fixup URL (Publication Step One)
1304:
1305: =item *
1306:
1307: publish() : publish (Publication Step One)
1308:
1309: =item *
1310:
1311: phasetwo() : render second interface showing status of publication steps
1312: (Publication Step Two)
1313:
1314: =back
1315:
1316: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>