--- loncom/xml/lonxml.pm 2008/12/07 23:41:02 1.490 +++ loncom/xml/lonxml.pm 2009/04/17 01:00:20 1.494 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.490 2008/12/07 23:41:02 www Exp $ +# $Id: lonxml.pm,v 1.494 2009/04/17 01:00:20 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -109,6 +109,7 @@ use Apache::lonfeedback(); use Apache::lonmsg(); use Apache::loncacc(); use Apache::lonmaxima(); +use Apache::lonr(); use Apache::lonlocal; #==================================== Main subroutine: xmlparse @@ -755,6 +756,11 @@ 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::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'); @@ -1504,6 +1510,15 @@ SIMPLECONTENT return $filecontents; } +sub createnewjs { + my $filecontents=(< + + +SIMPLECONTENT + return $filecontents; +} + sub verify_html { my ($filecontents)=@_; if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) { @@ -1551,6 +1566,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' @@ -1588,6 +1604,10 @@ FULLPAGE } FULLPAGE + if ($filetype eq 'html') { + $initialize .= "\n".&Apache::lonhtmlcommon::dragmath_js('EditMathPopup'); + $dragmath_button = &Apache::lonhtmlcommon::dragmath_button('filecont',1); + } } $add_to_onload = 'initDocument();'; @@ -1606,9 +1626,12 @@ 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.''; + } } my $editfooter=(< - $spelllink $htmlerror + $dragmath_button $spelllink $htmlerror
@@ -1671,9 +1694,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'); @@ -1689,11 +1711,12 @@ sub handler { my $file=&Apache::lonnet::filelocation("",$request->uri); my $filetype; - if ($file =~ /\.sty$/) { - $filetype='sty'; + if ($file =~ /\.(sty|css|js|txt)$/) { + $filetype=$1; } else { $filetype='html'; } + # # Edit action? Save file. # @@ -1722,7 +1745,9 @@ ENDNOTFOUND 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')) { $filecontents=&createnewhtml(); } $env{'form.editmode'}='Edit'; #force edit mode @@ -1738,27 +1763,43 @@ 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(); + } else { + $result = $filecontents; + } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rawmode']); if ($env{'form.rawmode'}) { $result = $filecontents; } - if ($filetype eq 'sty') { + if ($filetype ne 'html') { + my $nochgview = 1; my $controls = - ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls() + ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls($nochgview) : ''; - my %options = ('bgcolor' => '#FFFFFF'); - $result = - &Apache::loncommon::start_page(undef,undef,\%options). - $controls. - $result. - &Apache::loncommon::end_page(); - } + if ($filetype ne 'sty') { + $result =~ s//>/g; + $result = ''. + '
'.$result.
+                              '
'; + } + if ($env{'environment.remote'} eq 'off') { + my %options = ('bgcolor' => '#FFFFFF'); + $result = + &Apache::loncommon::start_page(undef,undef,\%options). + $controls. + $result. + &Apache::loncommon::end_page(); + } else { + $result = $controls.$result; + } + } } } @@ -1792,7 +1833,7 @@ ENDNOTFOUND &Apache::lonxml::message_location(). $edit_info. &Apache::loncommon::end_page(); - } + } } if ($filetype eq 'html') { &writeallows($request->uri); }