Annotation of loncom/publisher/londiff.pm, revision 1.8

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to show differences between file versions
                      3: #
1.8     ! stredwic    4: # $Id: londiff.pm,v 1.7 2001/12/13 14:02:54 harris41 Exp $
1.6       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: #
                     28: #
1.1       www        29: # (Handler to retrieve an old version of a file
                     30: #
                     31: # (Publication Handler
                     32: # 
                     33: # (TeX Content Handler
                     34: #
                     35: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     36: #
                     37: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
                     38: # 03/23 Guy Albertelli
                     39: # 03/24,03/29 Gerd Kortemeyer)
                     40: #
                     41: # 03/31,04/03 Gerd Kortemeyer)
                     42: #
1.5       www        43: # 05/02/01,05/09 Gerd Kortemeyer
1.7       harris41   44: # 12/13 Scott Harrison
                     45: #
                     46: ###
1.1       www        47: 
                     48: package Apache::londiff;
                     49: 
                     50: use strict;
                     51: use Apache::File;
                     52: use File::Copy;
                     53: use Algorithm::Diff qw(diff);
                     54: use Apache::Constants qw(:common :http :methods);
1.5       www        55: use Apache::loncacc;
1.7       harris41   56: use Apache::lonnet();
                     57: use Apache::loncommon();
1.1       www        58: 
                     59: sub handler {
                     60: 
                     61:   my $r=shift;
                     62: 
                     63: # Get query string for limited number of parameters
                     64: 
1.8     ! stredwic   65:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        !            66:                                        ['filename','versiontwo','versionone']);
1.1       www        67: # Get the files
                     68: 
1.5       www        69:   my $cuname=$ENV{'user.name'};
                     70:   my $cudom=$ENV{'user.domain'};
                     71: 
                     72:   unless (($cuname,$cudom)=
                     73:     &Apache::loncacc::constructaccess($ENV{'form.filename'},
                     74:                                       $r->dir_config('lonDefDomain'))) {
                     75:      $r->log_reason($cuname.' at '.$cudom.
                     76:          ' trying to get diffs file '.$ENV{'form.filename'}.
                     77:          '  - not authorized', 
                     78:          $r->filename); 
                     79:      return HTTP_NOT_ACCEPTABLE;
                     80:   }
                     81: 
                     82:   my $efn=$ENV{'form.filename'};
                     83: 
                     84:   $efn=~s/\/\~(\w+)//g;
                     85: 
1.1       www        86:   my @f1=();
                     87:   my @f2=();
                     88: 
1.2       www        89:   $r->content_type('text/html');
                     90:   $r->send_http_header;
                     91: 
                     92:   $r->print('<html><head><title>LON-CAPA Construction Diffs</title></head>');
                     93: 
                     94:   $r->print('<body bgcolor="#FFFFFF">');
                     95: 
                     96:   
1.5       www        97:   $r->print('<h1>Compare versions of <tt>'.$efn.'</tt></h1>');
                     98:    
                     99:        if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
                    100:           $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
                    101:                '</font></h3>');
                    102:       }
                    103: 
1.2       www       104: 
1.7       harris41  105:  if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq
1.2       www       106:       'ssi') {
1.1       www       107:   if ($ENV{'form.versionone'} eq 'priv') {
1.5       www       108:       my $fn='/home/'.$cuname.'/public_html/'.$efn;
1.1       www       109:       if (-e $fn) {
                    110: 	  my $fh=Apache::File->new($fn);
                    111:           my $line;
                    112:           while($line=<$fh>) {
                    113:              chomp($line);
                    114:              $f1[$#f1+1]=$line;
                    115: 	 }
                    116:       }
1.4       www       117:       $r->print('<h3>Construction Space Version</h3>');
1.1       www       118:   } else {
                    119:       my $fn=
1.5       www       120:        '/home/httpd/html//res/'.$cudom.'/'.$cuname.'/';
1.1       www       121:       if ($ENV{'form.versionone'}) {
1.5       www       122:          my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
1.1       www       123:          $fn.=$main.'.'.$ENV{'form.versionone'}.'.'.$suffix;
1.4       www       124: 	 $r->print('<h3>Version '.$ENV{'form.versionone'}.'</h3>');
1.1       www       125:       } else {
1.5       www       126:          $fn.=$efn;
1.4       www       127: 	 $r->print('<h3>Current Version</h3>');
1.1       www       128:       }
                    129:       @f1=split(/\n/,&Apache::lonnet::getfile($fn));      
                    130:   }
                    131: 
1.4       www       132:   $r->print('versus');
1.1       www       133: 
                    134:   if ($ENV{'form.versiontwo'} eq 'priv') {
1.5       www       135:       my $fn='/home/'.$cuname.'/public_html/'.$efn;
1.1       www       136:       if (-e $fn) {
                    137: 	  my $fh=Apache::File->new($fn);
                    138:           my $line;
                    139:           while($line=<$fh>) {
                    140:              chomp($line);
                    141:              $f2[$#f2+1]=$line;
                    142: 	 }
                    143:       }
1.4       www       144:       $r->print('<h3>Construction Space Version</h3>');
1.1       www       145:   } else {
                    146:       my $fn=
1.5       www       147:        '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
1.1       www       148:       if ($ENV{'form.versiontwo'}) {
1.5       www       149:          my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
1.1       www       150:          $fn.=$main.'.'.$ENV{'form.versiontwo'}.'.'.$suffix;
1.4       www       151: 	 $r->print('<h3>Version '.$ENV{'form.versiontwo'}.'</h3>');
1.1       www       152:       } else {
1.5       www       153:          $fn.=$efn;
1.4       www       154: 	 $r->print('<h3>Current Version</h3>');
1.1       www       155:       }
                    156:       @f2=split(/\n/,&Apache::lonnet::getfile($fn));      
                    157:   }
                    158: 
                    159: # Run diff
                    160: 
                    161:   my $diffs = diff(\@f1, \@f2);
                    162: 
                    163: # Start page output
                    164: 
                    165:   my $chunk;
                    166:   my $line;
                    167: 
1.3       www       168:   $r->print('<pre>');
                    169: 
1.1       www       170:   foreach $chunk (@$diffs) {
1.3       www       171: 
1.1       www       172:     foreach $line (@$chunk) {
                    173:       my ($sign, $lineno, $text) = @$line;
                    174:       $text=~s/\</\&lt\;/g;
                    175:       $text=~s/\>/\&gt\;/g;
1.3       www       176:       $lineno=substr($lineno.'        ',0,7);
                    177:       $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
                    178:                 $sign.' '.$lineno.' '.$text."</font>\n");
1.1       www       179:     }
1.3       www       180:     $r->print("<hr>\n");
1.1       www       181:   }
1.3       www       182:   $r->print('</pre>');
1.1       www       183: 
1.2       www       184: } else {
                    185:     $r->print('<h1><font color=red>Binary File</font></h1>');
                    186: }
1.1       www       187:   $r->print('</body></html>');
                    188:   return OK;  
                    189: }
                    190: 
                    191: 
                    192: 1;
                    193: __END__
1.2       www       194: 
1.1       www       195: 
                    196: 
                    197: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>