--- loncom/xml/lonxml.pm 2008/10/27 19:15:35 1.488 +++ loncom/xml/lonxml.pm 2009/11/30 23:22:47 1.503 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.488 2008/10/27 19:15:35 raeburn Exp $ +# $Id: lonxml.pm,v 1.503 2009/11/30 23:22:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,6 +37,25 @@ # to any other parties under any circumstances. # +=pod + +=head1 NAME + +Apache::lonxml + +=head1 SYNOPSIS + +XML Parsing Module + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + + +=head1 SUBROUTINES + +=cut + + package Apache::lonxml; use vars @@ -90,7 +109,9 @@ use Apache::lonfeedback(); use Apache::lonmsg(); use Apache::loncacc(); use Apache::lonmaxima(); +use Apache::lonr(); use Apache::lonlocal; +use Apache::lonhtmlcommon(); #==================================== Main subroutine: xmlparse @@ -658,6 +679,7 @@ sub setup_globals { $Apache::lonxml::request=$request; $errorcount=0; $warningcount=0; + $Apache::lonxml::internal_error=0; $Apache::lonxml::default_homework_loaded=0; $Apache::lonxml::usestyle=1; &init_counter(); @@ -735,6 +757,13 @@ sub init_safespace { $safehole->wrap(\&Apache::lonmaxima::maxima_cas_formula_fix,$safeeval, '&maxima_cas_formula_fix'); + $safehole->wrap(\&Apache::lonr::r_eval,$safeeval,'&r_eval'); + $safehole->wrap(\&Apache::lonr::Rentry,$safeeval,'&Rentry'); + $safehole->wrap(\&Apache::lonr::Rarray,$safeeval,'&Rarray'); + $safehole->wrap(\&Apache::lonr::r_check,$safeeval,'&r_check'); + $safehole->wrap(\&Apache::lonr::r_cas_formula_fix,$safeeval, + '&r_cas_formula_fix'); + $safehole->wrap(\&Apache::caparesponse::capa_formula_fix,$safeeval, '&capa_formula_fix'); @@ -1015,7 +1044,7 @@ sub get_id { my ($parstack,$safeeval)=@_; my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); if ($env{'request.state'} eq 'construct' && $id =~ /([._]|[^\w\d\s[:punct:]])/) { - &error(&mt("ID "[_1]" contains invalid characters, IDs are only allowed to contain letters, numbers, spaces and -",''.$id.'')); + &error(&mt('ID [_1] contains invalid characters. IDs are only allowed to contain letters, numbers, spaces and -','"'.$id.'"')); } if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; } return $id; @@ -1484,6 +1513,15 @@ SIMPLECONTENT return $filecontents; } +sub createnewjs { + my $filecontents=(< + + +SIMPLECONTENT + return $filecontents; +} + sub verify_html { my ($filecontents)=@_; if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) { @@ -1509,12 +1547,16 @@ sub renderingoptions { = &Apache::loncommon::plainlanguagedescription($_); } } - return - ''. - &mt('Language:').' '. - &Apache::loncommon::select_form($env{'form.languages'},'languages', - %langchoices).' - + my $output; + unless ($env{'form.forceedit'}) { + $output .= ' + '. + &mt('Language:').' '. + &Apache::loncommon::select_form($env{'form.languages'},'languages', + %langchoices).' + '; + } + $output .= ' '. &mt('Math Rendering:').' '. &Apache::loncommon::select_form($env{'form.texengine'},'texengine', @@ -1523,6 +1565,7 @@ sub renderingoptions { 'jsMath' => 'jsMath', 'mimetex' => 'mimetex (Convert to Images)')).' '; + return $output; } sub inserteditinfo { @@ -1531,6 +1574,7 @@ sub inserteditinfo { my $xml_help = ''; my $initialize=''; my $textarea_id = 'filecont'; + my $dragmath_button; my ($add_to_onload, $add_to_onresize); $initialize=&Apache::lonhtmlcommon::spellheader(); if ($filetype eq 'html' @@ -1568,6 +1612,10 @@ FULLPAGE } FULLPAGE + if ($filetype eq 'html' || $filetype eq 'tex') { + $initialize .= "\n".&Apache::lonhtmlcommon::dragmath_js('EditMathPopup'); + $dragmath_button = &Apache::lonhtmlcommon::dragmath_button('filecont',1); + } } $add_to_onload = 'initDocument();'; @@ -1578,6 +1626,7 @@ FULLPAGE } my $titledisplay=&display_title(); + my $wysiwyglink; my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', @@ -1586,9 +1635,19 @@ FULLPAGE my $spelllink .=&Apache::lonhtmlcommon::spelllink('xmledit','filecont'); my $textarea_events = &Apache::edit::element_change_detection(); my $form_events = &Apache::edit::form_change_detection(); - my $htmlerror=&verify_html($filecontents); - if ($htmlerror) { - $htmlerror=''.$htmlerror.''; + my $htmlerror; + if ($filetype eq 'html') { + $htmlerror=&verify_html($filecontents); + if ($htmlerror) { + $htmlerror=''.$htmlerror.''; + } + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + if (&Apache::lonhtmlcommon::htmlareablocked()) { + $wysiwyglink = &Apache::lonhtmlcommon::enablelink($textarea_id); + } else { + $wysiwyglink = &Apache::lonhtmlcommon::disablelink($textarea_id); + } + } } my $editfooter=(< - $spelllink $htmlerror + $dragmath_button $spelllink $htmlerror
@@ -1613,6 +1672,7 @@ $initialize
+ $wysiwyglink
$titledisplay
@@ -1651,9 +1711,8 @@ sub get_target { sub handler { my $request=shift; - + my $target=&get_target(); - $Apache::lonxml::debug=$env{'user.debug'}; &Apache::loncommon::content_type($request,'text/html'); @@ -1662,18 +1721,47 @@ sub handler { $request->set_last_modified(&Apache::lonnet::metadata($request->uri, 'lastrevisiondate')); } + # Embedded Flash movies from Camtasia served from https will not display in IE + # if XML config file has expired from cache. + if ($ENV{'SERVER_PORT'} == 443) { + if ($request->uri =~ /\.xml$/) { + my ($httpbrowser,$clientbrowser) = + &Apache::loncommon::decode_user_agent($request); + if ($clientbrowser =~ /^explorer$/i) { + delete $request->headers_out->{'Cache-control'}; + delete $request->headers_out->{'Pragma'}; + my $expiration = time + 60; + my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime($expiration)); + $request->headers_out->set("Expires" => $date); + } + } + } $request->send_http_header; return OK if $request->header_only; my $file=&Apache::lonnet::filelocation("",$request->uri); - my $filetype; - if ($file =~ /\.sty$/) { - $filetype='sty'; + my ($filetype,$breadcrumbtext); + if ($file =~ /\.(sty|css|js|txt|tex)$/) { + $filetype=$1; } else { $filetype='html'; } + if ($filetype eq 'sty') { + $breadcrumbtext = 'Style File Editor'; + } elsif ($filetype eq 'js') { + $breadcrumbtext = 'Javascript Editor'; + } elsif ($filetype eq 'css') { + $breadcrumbtext = 'CSS Editor'; + } elsif ($filetype eq 'txt') { + $breadcrumbtext = 'Text Editor'; + } elsif ($filetype eq 'tex') { + $breadcrumbtext = 'TeX Editor'; + } else { + $breadcrumbtext = 'HTML Editor'; + } + # # Edit action? Save file. # @@ -1692,17 +1780,22 @@ sub handler { if ($filecontents eq -1) { my $start_page=&Apache::loncommon::start_page('File Error'); my $end_page=&Apache::loncommon::end_page(); - my $fnf=&mt('File not found'); + my $errormsg='

' + .&mt('File not found: [_1]' + ,''.$file.'') + .'

'; $result=(<$fnf: $file +$errormsg $end_page ENDNOTFOUND $filecontents=''; if ($env{'request.state'} ne 'published') { if ($filetype eq 'sty') { $filecontents=&createnewsty(); - } else { + } elsif ($filetype eq 'js') { + $filecontents=&createnewjs(); + } elsif ($filetype ne 'css' && $filetype ne 'txt' && $filetype ne 'tex') { $filecontents=&createnewhtml(); } $env{'form.editmode'}='Edit'; #force edit mode @@ -1718,28 +1811,67 @@ ENDNOTFOUND ['editmode']); } if (!$env{'form.editmode'} || $env{'form.viewmode'} || $env{'form.discardview'}) { - &Apache::structuretags::reset_problem_globals(); - $result = &Apache::lonxml::xmlparse($request,$target,$filecontents, - '',%mystyle); + if ($filetype eq 'html' || $filetype eq 'sty') { + &Apache::structuretags::reset_problem_globals(); + $result = &Apache::lonxml::xmlparse($request,$target, + $filecontents,'',%mystyle); # .html files may contain or need to clean # up if it did - &Apache::structuretags::reset_problem_globals(); - &Apache::lonhomework::finished_parsing(); + &Apache::structuretags::reset_problem_globals(); + &Apache::lonhomework::finished_parsing(); + } elsif ($filetype eq 'tex') { + $result = &Apache::lontexconvert::converted(\$filecontents, + $env{'form.texengine'}); + if ($env{'form.return_only_error_and_warning_counts'}) { + if (&verify_html(''.$result.'')) { + $errorcount++; + } + $result = "$errorcount:$warningcount"; + } + } else { + $result = $filecontents; + } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rawmode']); if ($env{'form.rawmode'}) { $result = $filecontents; } - if ($filetype eq 'sty') { - my $controls = - ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls() - : ''; - my %options = ('bgcolor' => '#FFFFFF'); - $result = - &Apache::loncommon::start_page(undef,undef,\%options). - $controls. - $result. - &Apache::loncommon::end_page(); - } - } + if (($filetype ne 'html') && + (!$env{'form.return_only_error_and_warning_counts'})) { + my $nochgview = 1; + my $controls = ''; + if ($env{'request.state'} eq 'construct') { + $controls = &Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader() + .&Apache::londefdef::edit_controls($nochgview)); + } + if ($filetype ne 'sty' && $filetype ne 'tex') { + $result =~ s//>/g; + $result = ''. + '
'.$result.
+                              '
'; + } + if ($env{'environment.remote'} eq 'off') { + my $brcrum; + if ($env{'request.state'} eq 'construct') { + $brcrum = [{'href' => &Apache::loncommon::authorspace(), + 'text' => 'Construction Space'}, + {'href' => '', + 'text' => $breadcrumbtext}]; + } else { + $brcrum = ''; # FIXME: Where are we? + } + my %options = ('bread_crumbs' => $brcrum, + 'bgcolor' => '#FFFFFF'); + $result = + &Apache::loncommon::start_page(undef,undef,\%options) + .$controls + .$result + .&Apache::loncommon::end_page(); + } else { + $result = $controls.$result; + } + } + } } # @@ -1756,9 +1888,18 @@ ENDNOTFOUND my %options = ('add_entries' => - {'onresize' => $add_to_onresize, - 'onload' => $add_to_onload, }); - + {'onresize' => $add_to_onresize, + 'onload' => $add_to_onload, }); + my $header; + if ($env{'request.state'} eq 'construct') { + $options{'bread_crumbs'} = [{ + 'href' => &Apache::loncommon::authorspace(), + 'text' => 'Construction Space'}, + {'href' => '', + 'text' => $breadcrumbtext}]; + $header = &Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader()); + } if ($env{'environment.remote'} ne 'off') { $options{'bgcolor'} = '#FFFFFF'; $options{'only_body'} = 1; @@ -1768,14 +1909,15 @@ ENDNOTFOUND &Apache::loncommon::resize_textarea_js(); my $start_page = &Apache::loncommon::start_page(undef,$js, \%options); - $result=$start_page. - &Apache::lonxml::message_location(). - $edit_info. - &Apache::loncommon::end_page(); - } + $result = $start_page + .$header + .&Apache::lonxml::message_location() + .$edit_info + .&Apache::loncommon::end_page(); + } } if ($filetype eq 'html') { &writeallows($request->uri); } - + &Apache::lonxml::add_messages(\$result); $request->print($result); @@ -1828,6 +1970,8 @@ sub error { $errorcount++; + $Apache::lonxml::internal_error=1; + if (defined($Apache::inputtags::part)) { if ( @Apache::inputtags::response ) { push(@errors,