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