--- loncom/xml/londefdef.pm 2010/02/02 15:34:58 1.403.4.1
+++ loncom/xml/londefdef.pm 2011/09/15 19:03:19 1.432
@@ -1,7 +1,8 @@
+
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.403.4.1 2010/02/02 15:34:58 raeburn Exp $
+# $Id: londefdef.pm,v 1.432 2011/09/15 19:03:19 raeburn Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -43,11 +44,11 @@ use Apache::lonnet;
use strict;
use Apache::lonxml;
use Apache::lontable;
-use Apache::File();
use Image::Magick;
use Apache::lonmenu();
use Apache::lonmeta();
use Apache::lonlocal;
+use Apache::loncommon();
use Apache::Constants qw(:common);
use File::Basename;
use LONCAPA();
@@ -383,6 +384,9 @@ sub start_meta {
} else {
$currentstring = $token->[4];
}
+ if ($env{'form.grade_imsexport'}) {
+ $currentstring = '';
+ }
} elsif ($target eq 'meta') {
unless (&Apache::lonxml::get_param
('http-equiv',$parstack,$safeeval,undef,1)) {
@@ -538,29 +542,58 @@ sub start_body {
my $extra_head = &generate_css_links();
+ # Breadcrumbs
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ if ($env{'request.state'} eq 'construct') {
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'Construction Space',
+ 'href' => &Apache::loncommon::authorspace(),
+ });
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'HTML Editor',
+ 'href' => '',
+ });
+ # breadcrumbs (and tools) will be created
+ # in start_page->bodytag->innerregister
+ } else {
+ # FIXME Where are we?
+ }
+
$currentstring =
&Apache::loncommon::start_page($Apache::londefdef::title,
$Apache::londefdef::head
.$extra_head,
{'add_entries' => $token->[2],
- 'no_title' => 1,
+# 'no_title' => 1,
'force_register' => 1});
- if ($env{'request.state'} ne 'published') {
- $currentstring.=&Apache::lonmenu::constspaceform();
- $currentstring.=&Apache::londefdef::edit_controls();
- }
- $currentstring.=&Apache::lonxml::message_location();
+ my $header = '';
+ if ($env{'request.state'} ne 'published' &&
+ $env{'request.state'} ne 'construct') {
+ $header=&Apache::lonmenu::constspaceform();
+ }
+ if ($env{'request.state'} ne 'published') {
+ $header.=&Apache::londefdef::edit_controls();
+ }
+ if ($env{'request.state'} eq 'construct') {
+ $currentstring.=&Apache::loncommon::head_subbox(
+ &Apache::loncommon::CSTR_pageheader()
+ .$header);
+ } elsif ($env{'request.state'} eq 'edit') {
+ $currentstring.=&Apache::loncommon::head_subbox($header);
+ }
+ $currentstring.=&Apache::lonxml::message_location();
} elsif ($target eq 'tex') {
- $currentstring = ''; # '\begin{document}' is in header.
- }
+ $currentstring = ''; # '\begin{document}' is in header.
+ }
+
return $currentstring;
}
sub edit_controls {
my ($nochgview) = @_;
my $result .= '
-
- # $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
- $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';
- if ($#Apache::londefdef::table > 0) {
- my $inmemory = $Apache::londefdef::table[-1]{'output'};
- # Figure out max/and min width by summing us and then
- # apply that to the current column of the table we nest in
- # if it's larger than the current width or the current width
- # is undefined.
- #
- my $min_nested_width = 0;
- my $max_nested_width = 0;
- for (my $col = 0; $col <= $Apache::londefdef::table[-1]{'counter_columns'}; $col++) {
- $min_nested_width += $min_len[$col];
- $max_nested_width += $max_len[$col];
-
- }
- # Fudge in an extra 5 mm for borders etc:
-
- $min_nested_width += 5;
- $max_nested_width += 5;
-
- my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'};
- my $outer_row = $Apache::londefdef::table[-2]{'row_number'};
- if ($min_nested_width > $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column]) {
- $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column] = $min_nested_width;
- }
- if ($max_nested_width > $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column]) {
- $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column] = $max_nested_width;
- }
-
- pop @Apache::londefdef::table;
- push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
- } else {
- $currentstring .= $Apache::londefdef::table[-1]{'output'};
- pop @Apache::londefdef::table;
- undef @Apache::londefdef::table;
- }
- }
- &enable_para();
- }
+
}
return $currentstring;
}
@@ -2692,17 +2247,26 @@ sub tag_check {
#
sub cell_config_hash {
- my ($align, $rowspan, $colspan) = @_;
+ my ($align, $rowspan, $colspan, $width) = @_;
+ if ($rowspan ne '') {
+ $rowspan =~ s/^\s+|\s+$//g;
+ }
+ if ($colspan ne '') {
+ $colspan =~ s/^\s+|\s+$//g;
+ }
my %config;
if ($align ne '') {
$config{'halign'} = $align;
}
- if ($colspan ne "") {
+ if (($colspan =~ /^\d+$/) && ($colspan > 0)) {
$config{'colspan'} = $colspan;
}
- if ($rowspan ne '') {
+ if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {
$config{'rowspan'} = $rowspan;
}
+ if ($width ne '') {
+ $config{'width'} = $width;
+ }
return \%config;
}
@@ -2714,11 +2278,11 @@ sub start_td_tex {
# attributes, but empty of text. end_td_tex will
# fetch the contents from the recursive parse and
# fill the cell with them:
- my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
- my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
- my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
-
- my $config = &cell_config_hash($align, $rowspan, $colspan);
+ my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval);
+ my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);
+ my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);
+ my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);
+ my $config = &cell_config_hash($align, $rowspan, $colspan, $width);
my $table = $Apache::londefdef::table[-1];
$table->add_cell('', $config);
@@ -3129,24 +2693,13 @@ sub start_img {
# Render unto browsers that which are the browser's...
if ($target eq 'web' || $target eq 'webgrade') {
- if ($env{'browser.imagesuppress'} ne 'on') {
- my $enc = ('yes' eq
- lc(&Apache::lonxml::get_param('encrypturl',$parstack,
- $safeeval)));
- $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
- $enc);
- } else {
- my $alttag = &Apache::lonxml::get_param('alt',$parstack,$safeeval,
- undef,1);
- if (!$alttag) {
- $alttag = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
- $src);
- }
- $currentstring.='[IMAGE: '.$alttag.']';
- }
-
- # and render unto TeX that which is LaTeX
+ my $enc = ('yes' eq
+ lc(&Apache::lonxml::get_param('encrypturl',$parstack,
+ $safeeval)));
+ $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
+ $enc);
+ # and render unto TeX that which is LaTeX
} elsif ($target eq 'tex') {
#
# The alignment will require some superstructure to be put around
@@ -3245,21 +2798,28 @@ sub start_img {
['','bottom','middle','top','left','right'],$token,5);
$currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
+ my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
+ my $enc= &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
+
$currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
['no','yes'], $token, 2);
+ if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
+ $currentstring.='
'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'';
+ }
$currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
- my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
if ($token->[2]{'src'}=~/\$/) {
- $currentstring.='Variable image source';
- } else {
+ $currentstring.=&mt('Variable image source');
+ } elsif ($token->[2]{'src'}=~/\S/) {
$currentstring .= '
$code,
- 'archive'=>$archive}
- );
- } else {
- my $alttag= &Apache::lonxml::get_param('alt',$parstack,
- $safeeval,undef,1);
- unless ($alttag) {
- $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
- $code);
- }
- $currentstring='[APPLET: '.$alttag.']';
- }
+ $currentstring = &Apache::lonenc::encrypt_ref($token,
+ {'code'=>$code,
+ 'archive'=>$archive}
+ );
} elsif ($target eq 'tex') {
- # Turn off some stuff we can't be inside thank you LaTeX
-
+ # Turn off some stuff we can't be inside thank you LaTeX
my $restart_sub = 0;
my $restart_sup = 0;
@@ -3408,16 +2957,7 @@ sub start_embed {
&Apache::lonxml::extlink($src);
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- if ($env{'browser.embedsuppress'} ne 'on') {
- $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
- } else {
- my $alttag=&Apache::lonxml::get_param
- ('alt',$parstack,$safeeval,undef,1);
- unless ($alttag) {
- $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
- }
- $currentstring='[EMBED: '.$alttag.']';
- }
+ $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
} elsif ($target eq 'tex') {
}
return $currentstring;
@@ -3427,9 +2967,10 @@ sub end_embed {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
- } elsif ($target eq 'tex') {
- }
+ $currentstring = $token->[2];
+ } elsif ($target eq 'tex') {
+ # ./.
+ }
return $currentstring;
}
@@ -3508,7 +3049,7 @@ sub start_frameset {
&Apache::loncommon::start_page($Apache::londefdef::title,
$Apache::londefdef::head,
{'add_entries' => $token->[2],
- 'no_title' => 1,
+# 'no_title' => 1,
'force_register' => 1,
'frameset' => 1,});
@@ -3848,13 +3389,34 @@ sub end_col {
return $currentstring;
}
-#--
tag (end tag optional)
+#-- [4];
}
+ if ($target eq 'tex') {
+ # TODO: Ensure this tag is in a table:
+
+ # Fetch the attributes and build the hash for the
+ # call to define_colgroup.
+
+ my $span = &Apache::lonxml::get_param('span', $parstack, $safeeval);
+ my $halign = &Apache::lonxml::get_param('halign', $parstack, $safeeval);
+
+ my %colgroup_params;
+ if ($span ne '') {
+ $colgroup_params{'span'} = $span;
+ }
+ if ($halign ne '') {
+ $colgroup_params{'halign'} = $halign;
+ }
+
+ my $table = $Apache::londefdef::table[-1];
+ $table->define_colgroup(\%colgroup_params);
+
+ }
return $currentstring;
}
@@ -3867,12 +3429,16 @@ sub end_colgroup {
return $currentstring;
}
+
#-- tag (end tag required)
sub start_del {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
+ } elsif ($target eq 'tex') {
+ &disable_para();
+ $currentstring .= '\st{';
}
return $currentstring;
}
@@ -3881,7 +3447,10 @@ sub end_del {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
+ } elsif ($target eq 'tex') {
+ &enable_para();
+ $currentstring = '}';
}
return $currentstring;
}
@@ -4341,6 +3910,12 @@ sub start_tbody {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
}
+ if ($target eq 'tex') {
+ # TODO: Ensure this tag is within a table:
+
+ my $table = $Apache::londefdef::table[-1];
+ $table->start_body();
+ }
return $currentstring;
}
@@ -4350,6 +3925,12 @@ sub end_tbody {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
}
+ if($target eq 'tex') {
+ # TODO: Ensure this tag is within a table:
+
+ my $table = $Apache::londefdef::table[-1];
+ $table->end_body();
+ }
return $currentstring;
}
@@ -4360,6 +3941,11 @@ sub start_tfoot {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
}
+ if ($target eq 'tex') {
+ # TODO: ensure this is within a table tag.
+ my $table = $Apache::londefdef::table[-1];
+ $table->start_foot();
+ }
return $currentstring;
}
@@ -4369,6 +3955,11 @@ sub end_tfoot {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
}
+ if ($target eq 'tex') {
+ # TODO: Ensure this is in side a table
+ my $table = $Apache::londefdef::table[-1];
+ $table->end_foot();
+ }
return $currentstring;
}
@@ -4379,6 +3970,11 @@ sub start_thead {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[4];
}
+ if ($target eq 'tex') {
+ # Assume we're in a table... TODO: Verify that and ignore tag if not.
+ my $table = $Apache::londefdef::table[-1];
+ $table->start_head();
+ }
return $currentstring;
}
@@ -4388,6 +3984,12 @@ sub end_thead {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
}
+ if ($target eq 'tex') {
+ # TODO: Verify we are in a table and ignore tag if not.
+
+ my $table = $Apache::londefdef::table[-1];
+ $table->end_head();
+ }
return $currentstring;
}
@@ -4590,13 +4192,13 @@ sub get_eps_image {
#if replication failed try to produce eps file dynamically
$src=~s/\.ps$/\.eps/;
- my $temp_file;
- open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
- my $newsrc=$orig_src;
- $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
- &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
- print FILE ("$newsrc\n");
- close(FILE);
+ if (open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat")) {
+ my $newsrc=$orig_src;
+ $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
+ &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
+ print FILE ("$newsrc\n");
+ close(FILE);
+ }
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
if ($sext ne "") { # Put the ext. back in to uniquify.
@@ -4629,8 +4231,10 @@ sub get_eps_image {
sub eps_generation {
my ($src,$file,$width_param) = @_;
my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
- my $temp_file = Apache::File->new('>>'.$filename);
- print $temp_file "$src\n";
+ if (open(my $tmpfile,">>$filename")) {
+ print $tmpfile "$src\n";
+ close($tmpfile);
+ }
my $newsrc = $src;
$newsrc =~ s/(\.bmp|\.gif|\.jpg|\.jpeg)$/\.eps/i;
$newsrc=~s{/home/httpd/html/res}{};
@@ -4817,6 +4421,7 @@ sub latex_header {
"\\usepackage{xcolor}\n".
'\usepackage{calc}'.
'\usepackage{amsmath}'.
+ '\usepackage{soul}',
'\usepackage{amssymb}'.
'\usepackage{amsfonts}'.
'\usepackage{amsthm}'.