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