--- loncom/publisher/lonpubdir.pm 2002/01/18 16:48:41 1.20
+++ loncom/publisher/lonpubdir.pm 2011/11/14 00:20:31 1.137
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
-# (Publication Handler
+# Construction Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.20 2002/01/18 16:48:41 albertel Exp $
+# $Id: lonpubdir.pm,v 1.137 2011/11/14 00:20:31 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,20 +25,6 @@
#
# http://www.lon-capa.org/
#
-#
-# (TeX Content Handler
-#
-# YEAR=2000
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
-# YEAR=2001
-# 03/23 Guy Albertelli
-# 03/24,03/29 Gerd Kortemeyer)
-# 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
-# 12/15 Scott Harrison
-# 12/28 Gerd Kortemeyer
-#
###
package Apache::lonpubdir;
@@ -49,80 +35,68 @@ use File::Copy;
use Apache::Constants qw(:common :http :methods);
use Apache::loncacc;
use Apache::loncommon();
+use Apache::lonhtmlcommon();
+use Apache::londiff();
+use Apache::lonlocal;
+use Apache::lonmsg;
+use Apache::lonmenu;
+use Apache::lonnet;
+use LONCAPA;
sub handler {
my $r=shift;
- my $fn;
-
- if ($ENV{'form.filename'}) {
- $fn=$ENV{'form.filename'};
- $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
- $fn=~s/\/[^\/]+$//;
- } else {
- $fn=$r->filename();
- }
+ # Validate access to the construction space and get username@domain.
my $uname;
my $udom;
- ($uname,$udom)=
- &Apache::loncacc::constructaccess(
- $fn,$r->dir_config('lonDefDomain'));
+ ($uname,$udom)=&Apache::loncacc::constructaccess($r->uri);
unless (($uname) && ($udom)) {
- $r->log_reason($uname.' at '.$udom.
- ' trying to publish file '.$ENV{'form.filename'}.
- ' ('.$fn.') - not authorized',
- $r->filename);
return HTTP_NOT_ACCEPTABLE;
}
-
- $fn=~s/\/$//;
-
- unless ($fn) {
- $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
- ' trying to list empty directory', $r->filename);
- return HTTP_NOT_FOUND;
- }
# ----------------------------------------------------------- Start page output
-
- $r->content_type('text/html');
- $r->send_http_header;
-
- $r->print('
LON-CAPA Construction Space');
-
- $r->print(
- '');
+ my $fn=$r->filename;
+ $fn=~s/\/$//;
my $thisdisfn=$fn;
- $thisdisfn=~s/^\/home\/$uname\/public_html//;
-
- $r->print('
Construction Space Directory '.$thisdisfn.'/
');
-
- if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
- $r->print('
Co-Author: '.$uname.' at '.$udom.
- '
');
- }
-
+ my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
+ $thisdisfn=~s/^\Q$docroot\E\/priv//;
- my $docroot=$r->dir_config('lonDocRoot');
+ my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory
+ my $targetdir='/res'.$thisdisfn; # Publication target directory.
+ my $linkdir='/priv'.$thisdisfn; # Full URL name of constr space.
+
+ my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
+
+ &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
+ &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory,
+ # browse/upload + new file page.
+ &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc.
- my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
- my $targetdir=$udom.'/'.$uname.$thisdisfn;
- my $linkdir='/~'.$uname.$thisdisfn;
-
- $r->print('
'.
- '
Filename
Metadata
Modified
'.
- '
Status
');
+ my $numdir = 0;
+ my $numres = 0;
+
+ # Start off the directory table.
+ $r->print(&Apache::loncommon::start_data_table()
+ .&Apache::loncommon::start_data_table_header_row()
+ .'
'.&mt('Type').'
'
+ .'
'.&mt('Actions').'
'
+ .'
'.&mt('Name').'
'
+ .'
'.&mt('Title').'
'
+ .'
'.&mt('Status').'
'
+ .'
'.&mt('Last Modified').'
'
+ .&Apache::loncommon::end_data_table_header_row()
+ );
my $filename;
- my $dirptr=16384;
+ my $dirptr=16384; # Mask indicating a directory in stat.cmode.
opendir(DIR,$fn);
- my @files=sort(readdir(DIR));
+ my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
foreach my $filename (@files) {
my ($cdev,$cino,$cmode,$cnlink,
$cuid,$cgid,$crdev,$csize,
@@ -132,78 +106,600 @@ sub handler {
my $extension='';
if ($filename=~/\.(\w+)$/) { $extension=$1; }
if ($cmode&$dirptr) {
- my $disfilename=$filename;
- if ($filename eq '..') {
- $disfilename='Parent Directory';
- }
- unless ((($filename eq '..') && ($thisdisfn eq '')) ||
- ($filename eq '.')) {
- $r->print('
'.
+ &Apache::loncommon::end_data_table_row()
+ );
+ return OK;
+}
+
+sub create_pubselect {
+ my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
+ $$pub_select = '
+';
+ $$numres ++;
+}
+
+sub check_for_versions {
+ my ($r,$fn,$udom,$uname) = @_;
+ my $versions = 0;
+ my $docroot=$r->dir_config('lonDocRoot');
+ my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
+ my $resdir=$resfn;
+ $resdir=~s/\/[^\/]+$/\//;
+ $fn=~/\/([^\/]+)\.(\w+)$/;
+ my $main=$1;
+ my $suffix=$2;
+ opendir(DIR,$resdir);
+ while (my $filename=readdir(DIR)) {
+ if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
+ $versions ++;
+ }
+ }
+ return $versions;
+}
+
1;
__END__
+
=head1 NAME
-Apache::lonpubdir - Publication Handler for Directories
+Apache::lonpubdir - Construction space directory lister
=head1 SYNOPSIS
Invoked (for various locations) by /etc/httpd/conf/srm.conf:
-
+
PerlAccessHandler Apache::loncacc
SetHandler perl-script
PerlHandler Apache::lonpubdir
@@ -250,4 +746,48 @@ run through list of files and attempt to
=back
+=head1 SUBROUTINES:
+
+=over
+
+=item startpage($r, $uame, $udom, $thisdisfn)
+
+Output the header of the page. This includes:
+ - The HTML header
+ - The H1/H3 stuff which includes the directory.
+
+ startpage($r, $uame, $udom, $thisdisfn);
+ $r - The apache request object.
+ $uname - User name.
+ $udom - Domain name the user is logged in under.
+ $thisdisfn - Displayable version of the filename.
+
+=item getTitleString($fullname)
+
+ Get the title string or "[untitled]" if the file has no title metadata:
+ Without the latter substitution, it's impossible to examine metadata for
+ untitled resources. Resources may be legitimately untitled, to prevent
+ searches from locating them.
+
+ $str = getTitleString($fullname);
+ $fullname - Fully qualified filename to check.
+
+=item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
+ $numdir)
+
+ Put out a directory table row:
+
+ $r - Apache request object.
+ $reqfile - File in request.
+ $here - Where we are in directory tree.
+ $dirname - Name of directory special file.
+ $modtime - Encoded modification time.
+ targetdir - Publication target directory.
+ bombs - Reference to hash of URLs with runtime error messages.
+ numdir - Reference to scalar used to track number of sub-directories
+ in directory (used in form name for each "actions" dropdown).
+
+=back
+
=cut
+