[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm londependencies.pm lonhtmlcommon.pm lonsyllabus.pm
raeburn
raeburn at source.lon-capa.org
Fri May 3 17:57:14 EDT 2013
raeburn Fri May 3 21:57:14 2013 EDT
Modified files:
/loncom/interface loncommon.pm londependencies.pm lonhtmlcommon.pm
lonsyllabus.pm
Log:
- Provide the ability to edit an HTML file uploaded as the syllabus, i.e.,
a user supplied file, instead of the templated syllabus, and to manage
dependencies (e.g., images etc.)
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1125 loncom/interface/loncommon.pm:1.1126
--- loncom/interface/loncommon.pm:1.1125 Fri May 3 14:28:35 2013
+++ loncom/interface/loncommon.pm Fri May 3 21:57:13 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1125 2013/05/03 14:28:35 raeburn Exp $
+# $Id: loncommon.pm,v 1.1126 2013/05/03 21:57:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -9616,10 +9616,17 @@
if (ref($args) eq 'HASH') {
$url = $args->{'docs_url'};
$title = $args->{'docs_title'};
- $toplevel = "/$url";
+ $toplevel = $url;
+ unless ($toplevel =~ m{^/}) {
+ $toplevel = "/$url";
+ }
($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
- ($path) =
- ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
+ if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
+ $path = $1;
+ } else {
+ ($path) =
+ ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
+ }
$fileloc = &Apache::lonnet::filelocation('',$toplevel);
$fileloc =~ s{^/}{};
($filename) = ($fileloc =~ m{.+/([^/]+)$});
@@ -9635,7 +9642,13 @@
$fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
$fileloc =~ s{^/}{};
}
- foreach my $embed_file (keys(%{$allfiles})) {
+ foreach my $file (keys(%{$allfiles})) {
+ my $embed_file;
+ if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
+ $embed_file = $1;
+ } else {
+ $embed_file = $file;
+ }
my $absolutepath;
if ($embed_file =~ m{^\w+://}) {
$newfiles{$embed_file} = 1;
@@ -9799,12 +9812,14 @@
($file eq $filename.'.bak') ||
($dependencies{$file})) {
if ($actionurl eq '/adm/dependencies') {
- next if (($rem ne '') &&
- (($env{"httpref.$rem".$file} ne '') ||
- (ref($navmap) &&
- (($navmap->getResourceByUrl($rem.$file) ne '') ||
- (($file =~ /^(.*\.s?html?)\.bak$/i) &&
- ($navmap->getResourceByUrl($rem.$1)))))));
+ unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
+ next if (($rem ne '') &&
+ (($env{"httpref.$rem".$file} ne '') ||
+ (ref($navmap) &&
+ (($navmap->getResourceByUrl($rem.$file) ne '') ||
+ (($file =~ /^(.*\.s?html?)\.bak$/i) &&
+ ($navmap->getResourceByUrl($rem.$1)))))));
+ }
}
$unused{$file} = 1;
}
@@ -10197,9 +10212,10 @@
}
}
} elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
+ my $extendedsubdir = $dirpath.'/'.$subdir;
+ $extendedsubdir =~ s{/+$}{};
my $result =
- &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,
- $dirpath.'/'.$subdir);
+ &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
if ($result !~ m|^/uploaded/|) {
$output .= '<span class="LC_error">'
.&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
@@ -10359,7 +10375,7 @@
}
my (%allfiles,%codebase,$output,$content);
my @changes = &get_env_multiple('form.namechange');
- unless (@changes > 0) {
+ unless ((@changes > 0) || ($context eq 'syllabus')) {
if (wantarray) {
return ('',0,0);
} else {
Index: loncom/interface/londependencies.pm
diff -u loncom/interface/londependencies.pm:1.3 loncom/interface/londependencies.pm:1.4
--- loncom/interface/londependencies.pm:1.3 Thu Nov 29 20:37:07 2012
+++ loncom/interface/londependencies.pm Fri May 3 21:57:13 2013
@@ -2,7 +2,7 @@
# Handler to manage dependencies for HTML files uploaded directly
# to a course.
#
-# $Id: londependencies.pm,v 1.3 2012/11/29 20:37:07 raeburn Exp $
+# $Id: londependencies.pm,v 1.4 2013/05/03 21:57:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -103,7 +103,8 @@
my ($mimetype,$numpathchgs,$numrefchanges,%allfiles,%codebase,$url);
if ($symb) {
(undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
- } elsif (($docs_url) && ($env{'httpref.'.$docs_url} ne '')) {
+ } elsif (($docs_url) && (($env{'httpref.'.$docs_url} ne '') ||
+ ($docs_url =~ m{^\Q/uploaded/$cdom/$cnum/\E(portfolio/syllabus)/}))) {
$url = $docs_url;
$url =~ s{^/}{};
}
@@ -113,8 +114,15 @@
'<input type="hidden" name="title" value="'.$docs_title.'" />'."\n".
'<input type="hidden" name="url" value="'.$docs_url.'" />'."\n";
my $dir_root = '/userfiles';
- my ($destination) =
- ($url =~ m{^\Quploaded/$cdom/$cnum/\E((?:docs|supplemental)/(?:default|\d+)/\d+)/});
+ my ($destination,$context);
+ if ($url =~ m{^\Quploaded/$cdom/$cnum/\E(portfolio/syllabus)/}) {
+ $destination = $1;
+ $context = 'syllabus';
+ } else {
+ ($destination) =
+ ($url =~ m{^\Quploaded/$cdom/$cnum/\E((?:docs|supplemental)/(?:default|\d+)/\d+)/});
+ $context = 'coursedoc';
+ }
my $js = &Apache::loncommon::ask_embedded_js();
my $output = &Apache::loncommon::start_page($title,$js,
{'only_body' => 1});
@@ -126,7 +134,7 @@
$numrefchanges = $count + $codebasecount;
} elsif ($action eq 'process_changes') {
(my $result,$numpathchgs) =
- &process_changes($cdom,$cnum,$chome,$url,$destination,$dir_root,$state);
+ &process_changes($cdom,$cnum,$chome,$url,$destination,$dir_root,$state,$context);
$output .= $result;
}
unless ((($action eq 'process_changes') && ($numpathchgs > 0)) ||
@@ -148,7 +156,7 @@
}
sub process_changes {
- my ($cdom,$cnum,$chome,$url,$destination,$dir_root,$state) = @_;
+ my ($cdom,$cnum,$chome,$url,$destination,$dir_root,$state,$context) = @_;
my ($output,$numpathchgs);
my ($numnew,$numtodelete,$numtomod) = (0,0,0);
my $url_root = "/uploaded/$cdom/$cnum";
@@ -199,11 +207,20 @@
}
if ((@modifications > 0) || ($numnew > 0)) {
(my $result,my $flag,$numpathchgs) =
- &Apache::loncommon::upload_embedded('coursedoc',$destination,$cnum,$cdom,
+ &Apache::loncommon::upload_embedded($context,$destination,$cnum,$cdom,
$dir_root,$url_root,undef,undef,undef,
$state,'/adm/dependencies');
$output .= '<h4>'.&mt('Uploaded files').'</h4>'.
$result;
+ unless ($numpathchgs) {
+ if ($context eq 'syllabus') {
+ my $modres =
+ &Apache::loncommon::modify_html_refs($context,'portfolio/syllabus',
+ $cnum,$cdom,
+ '/userfiles',"/$url");
+ $result .= $modres;
+ }
+ }
}
} else {
$output .= '<span class="LC_warning">'.
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.343 loncom/interface/lonhtmlcommon.pm:1.344
--- loncom/interface/lonhtmlcommon.pm:1.343 Tue Apr 30 15:10:22 2013
+++ loncom/interface/lonhtmlcommon.pm Fri May 3 21:57:13 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.343 2013/04/30 15:10:22 bisitz Exp $
+# $Id: lonhtmlcommon.pm,v 1.344 2013/05/03 21:57:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -216,6 +216,8 @@
} elsif ($folderpath) {
$link = '/adm/dependencies?folderpath='.&HTML::Entities::encode($folderpath,'<>&"');
$url = $uri;
+ } elsif ($uri =~ m{^/public/$match_domain/$match_courseid/syllabus$}) {
+ $link = '/adm/dependencies';
}
$link .= (($link=~/\?/)?'&':'?').'title='.
&HTML::Entities::encode($title,'<>&"');
Index: loncom/interface/lonsyllabus.pm
diff -u loncom/interface/lonsyllabus.pm:1.117 loncom/interface/lonsyllabus.pm:1.118
--- loncom/interface/lonsyllabus.pm:1.117 Wed Apr 24 02:43:59 2013
+++ loncom/interface/lonsyllabus.pm Fri May 3 21:57:13 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Syllabus
#
-# $Id: lonsyllabus.pm,v 1.117 2013/04/24 02:43:59 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.118 2013/05/03 21:57:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -530,7 +530,7 @@
.'</p>'
.'</div>');
my $lonhost = $r->dir_config('lonHostID');
- $r->print(&chooser($external,$uploaded,$lonhost,\%syllabusfields,\%syllabus));
+ $r->print(&chooser($external,$uploaded,$cdom,$cnum,$lonhost,\%syllabusfields,\%syllabus));
}
} else {
#--------------------------------------------- Print last update unless editing
@@ -737,7 +737,7 @@
}
sub chooser {
- my ($external,$uploaded,$lonhost,$fields,$values) = @_;
+ my ($external,$uploaded,$cdom,$cnum,$lonhost,$fields,$values) = @_;
my %lt = &Apache::lonlocal::texthash(
'type' => 'Syllabus Type',
'url' => 'External URL',
@@ -797,9 +797,36 @@
$protocol = 'http' if ($protocol ne 'https');
my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$uploaded;
my ($filename) = ($uploaded =~ m{([^/]+)$});
+ my $file=&Apache::lonnet::filelocation("",$uploaded);
+ my $depbutton;
+ if ($file =~ /\.html?$/) {
+ my $filecontents=&Apache::lonnet::getfile($file);
+ unless ($filecontents eq -1) {
+ my $mm = new File::MMagic;
+ my $mimetype = $mm->checktype_contents($filecontents);
+ if ($mimetype eq 'text/html') {
+ my (%codebase,%allfiles);
+ my $parse_result = &Apache::lonnet::extract_embedded_items($uploaded,\%allfiles,
+ \%codebase,\$filecontents);
+ my $actionurl = "/public/$cdom/$cnum/syllabus";
+ my ($ignore,$num,$numpathchanges,$existing,$mapping) =
+ &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
+ \%codebase,
+ {'context' => 'rewrites',
+ 'ignore_remote_references' => 1,});
+ if (keys(%allfiles)) {
+ $depbutton = (' ' x 3).
+ &editfile_button().
+ &editbutton_js($uploaded);
+ }
+ }
+ }
+ }
+
$output .= '<span class="LC_nobreak">'.$lt{'curr'}.' '.
'<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
- '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span><br /><br />'.$lt{'rep'};
+ '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
+ '<br /><br />'.$lt{'rep'};
} else {
$output .= $lt{'upl'};
}
@@ -960,5 +987,25 @@
'</a></p>';
}
+sub editfile_button {
+ my $buttontext=&mt('Edit');
+ return <<"END";
+ <input type="button" value="$buttontext" onclick="javascript:gotoeditor();" />
+END
+}
+
+sub editbutton_js {
+ my ($url) = @_;
+ return <<ENDJS;
+ <script type="text/javascript">
+ // <![CDATA[
+ function gotoeditor() {
+ document.location.href = '$url?forceedit=1';
+ }
+ // ]]>
+ </script>
+ENDJS
+}
+
1;
__END__
More information about the LON-CAPA-cvs
mailing list