--- loncom/xml/lonxml.pm 2013/05/05 00:10:16 1.539 +++ loncom/xml/lonxml.pm 2014/12/15 17:39:24 1.551 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.539 2013/05/05 00:10:16 raeburn Exp $ +# $Id: lonxml.pm,v 1.551 2014/12/15 17:39:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -144,7 +144,7 @@ $metamode = 0; # turns on and of run::evaluate actually derefencing var refs $evaluate = 1; -# data structure for eidt mode, determines what tags can go into what other tags +# data structure for edit mode, determines what tags can go into what other tags %insertlist=(); # stores the list of active tag namespaces @@ -229,11 +229,10 @@ sub xmlend { } sub printalltags { - my $temp; - foreach $temp (sort keys %Apache::lonxml::alltags) { - &Apache::lonxml::debug("$temp -- ". - join(',',@{ $Apache::lonxml::alltags{$temp} })); - } + foreach my $temp (sort(keys(%Apache::lonxml::alltags))) { + &Apache::lonxml::debug("$temp -- ". + join(',',@{ $Apache::lonxml::alltags{$temp} })); + } } sub xmlparse { @@ -306,8 +305,12 @@ sub xmlparse { &clean_safespace($safeeval); if (@script_var_displays) { - my $scriptoutput = join('',@script_var_displays); - $finaloutput=~s{(\s*)\s*$}{$scriptoutput$1}s; + if ($finaloutput =~ m{\s*\s*$}s) { + my $scriptoutput = join('',@script_var_displays); + $finaloutput=~s{(\s*)\s*$}{$scriptoutput$1}s; + } else { + $finaloutput .= join('',@script_var_displays); + } undef(@script_var_displays); } &init_state(); @@ -651,7 +654,7 @@ sub init_safespace { my ($target,$safeeval,$safehole,$safeinit) = @_; $safeeval->reval('use LaTeX::Table;'); $safeeval->deny_only(':dangerous'); - $safeeval->reval('use Math::Complex;'); + $safeeval->reval('use LONCAPA::LCMathComplex;'); $safeeval->permit_only(":default"); $safeeval->permit("entereval"); $safeeval->permit(":base_math"); @@ -1323,7 +1326,7 @@ sub extlink { if (!$exact) { $res=&Apache::lonnet::hreflocation($Apache::lonxml::pwd[-1],$res); } - push(@Apache::lonxml::extlinks,$res) + push(@Apache::lonxml::extlinks,$res); } sub writeallows { @@ -1359,7 +1362,9 @@ sub do_registered_ssi { sub add_script_result { my ($display) = @_; - push(@script_var_displays, $display); + if ($display ne '') { + push(@script_var_displays, $display); + } } # @@ -1510,53 +1515,61 @@ sub renderingoptions { } sub inserteditinfo { - my ($filecontents,$filetype,$filename,$symb,$itemtitle,$folderpath,$uri) = @_; + my ($filecontents,$filetype,$filename,$symb,$itemtitle,$folderpath,$uri,$action) = @_; $filecontents = &HTML::Entities::encode($filecontents,'<>&"'); my $xml_help = ''; my $initialize=''; my $textarea_id = 'filecont'; - my ($dragmath_button,$deps_button); - my ($add_to_onload, $add_to_onresize); + my ($dragmath_button,$deps_button,$context,$cnum,$cdom,$add_to_onload, + $add_to_onresize,$init_dragmath); $initialize=&Apache::lonhtmlcommon::spellheader(); - if (($filetype eq 'html') && (&Apache::lonhtmlcommon::htmlareabrowser())) { - my $lang = &Apache::lonhtmlcommon::htmlarea_lang(); - my %textarea_args = ( - fullpage => 'true', - dragmath => 'math', - ); - $initialize .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); + if ($filetype eq 'html') { + if ($env{'request.course.id'}) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($uri =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus/\E}) { + $context = 'syllabus'; + } + } + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + my $lang = &Apache::lonhtmlcommon::htmlarea_lang(); + my %textarea_args = ( + fullpage => 'true', + dragmath => 'math', + ); + $initialize .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); + if ($context eq 'syllabus') { + $init_dragmath = "editmath_visibility('filecont','none')"; + } + } } $initialize .= (< // FULLPAGE + my $textareaclass; if ($filetype eq 'html') { - my $context; - if ($env{'request.course.id'}) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if ($uri =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus/\E}) { - $context = 'syllabus'; - $deps_button = &Apache::lonhtmlcommon::dependencies_button()."\n"; - $initialize .= - &Apache::lonhtmlcommon::dependencycheck_js(undef,&mt('Syllabus'), - $uri,undef, - "/public/$cdom/$cnum/syllabus"). - "\n"; - } - } - unless ($context eq 'syllabus') { - if ($symb || $folderpath) { - $deps_button = &Apache::lonhtmlcommon::dependencies_button()."\n"; - $initialize .= - &Apache::lonhtmlcommon::dependencycheck_js($symb,$itemtitle, - undef,$folderpath,$uri)."\n"; + if ($context eq 'syllabus') { + $deps_button = &Apache::lonhtmlcommon::dependencies_button()."\n"; + $initialize .= + &Apache::lonhtmlcommon::dependencycheck_js(undef,&mt('Syllabus'), + $uri,undef, + "/public/$cdom/$cnum/syllabus"). + "\n"; + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + $textareaclass = 'class="LC_richDefaultOn"'; } + } elsif ($symb || $folderpath) { + $deps_button = &Apache::lonhtmlcommon::dependencies_button()."\n"; + $initialize .= + &Apache::lonhtmlcommon::dependencycheck_js($symb,$itemtitle, + undef,$folderpath,$uri)."\n"; } $dragmath_button = ''.&Apache::lonhtmlcommon::dragmath_button('filecont',1).''; $initialize .= "\n".&Apache::lonhtmlcommon::dragmath_js('EditMathPopup'); @@ -1565,11 +1578,14 @@ FULLPAGE $add_to_onresize = "resize_textarea('$textarea_id','LC_aftertextarea');"; if ($filetype eq 'html') { - $xml_help=&Apache::loncommon::helpLatexCheatsheet(); + my $not_author; + if ($uri =~ m{^/uploaded/}) { + $not_author = 1; + } + $xml_help=&Apache::loncommon::helpLatexCheatsheet(undef,undef,$not_author); } my $titledisplay=&display_title(); - my $textareaclass; my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', @@ -1585,13 +1601,19 @@ FULLPAGE $htmlerror=''.$htmlerror.''; } if (&Apache::lonhtmlcommon::htmlareabrowser()) { - $textareaclass = 'class="LC_richDefaultOff"'; + unless ($textareaclass) { + $textareaclass = 'class="LC_richDefaultOff"'; + } } } + my $undo; + unless ($uri =~ m{^/uploaded/}) { + $undo = ''."\n"; + } my $editfooter=(< -
+
$filename @@ -1601,8 +1623,7 @@ $initialize
- - $htmlerror $deps_button $dragmath_button + $undo $htmlerror $deps_button $dragmath_button
@@ -1615,7 +1636,6 @@ $initialize $titledisplay
- ENDFOOTER return ($editfooter,$add_to_onload,$add_to_onresize);; } @@ -1691,6 +1711,19 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['todocs']); } + my ($cdom,$cnum); + if ($env{'request.course.id'}) { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($filetype eq 'html') { + if ($request->uri =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus/\E.+$}) { + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['editmode']); + } + } + } + } if ($filetype eq 'sty') { $breadcrumbtext = 'Style File Editor'; } elsif ($filetype eq 'js') { @@ -1717,6 +1750,7 @@ sub handler { } } } + my $inhibit_menu; my %mystyle; my $result = ''; my $filecontents=&Apache::lonnet::getfile($file); @@ -1774,8 +1808,15 @@ ENDNOTFOUND &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rawmode']); if ($env{'form.rawmode'}) { $result = $filecontents; } + if (($env{'request.state'} eq 'construct') && + (($filetype eq 'css') || ($filetype eq 'js')) && ($ENV{'HTTP_REFERER'})) { + if ($ENV{'HTTP_REFERER'} =~ m{^https?\://[^\/]+/priv/$LONCAPA::match_domain/$LONCAPA::match_username/[^\?]+\.(x?html?|swf)(|\?)[^\?]*$}) { + $inhibit_menu = 1; + } + } if (($filetype ne 'html') && - (!$env{'form.return_only_error_and_warning_counts'})) { + (!$env{'form.return_only_error_and_warning_counts'}) && + (!$inhibit_menu)) { my $nochgview = 1; my $controls = ''; if ($env{'request.state'} eq 'construct') { @@ -1793,7 +1834,7 @@ ENDNOTFOUND my $brcrum; if ($env{'request.state'} eq 'construct') { $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), - 'text' => 'Construction Space'}, + 'text' => 'Authoring Space'}, {'href' => '', 'text' => $breadcrumbtext}]; } else { @@ -1813,20 +1854,24 @@ ENDNOTFOUND # # Edit action? Insert editing commands # - unless ($env{'request.state'} eq 'published') { + unless (($env{'request.state'} eq 'published') || ($inhibit_menu)) { if ($env{'form.editmode'} && (!($env{'form.viewmode'})) && (!($env{'form.discardview'}))) { - my ($displayfile,$url,$symb,$itemtitle); + my ($displayfile,$url,$symb,$itemtitle,$action); $displayfile=$request->uri; if ($request->uri =~ m{^/uploaded/}) { if ($env{'request.course.id'}) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; if ($request->uri =~ m{^\Q/uploaded/$cdom/$cnum/supplemental/\E}) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['folderpath','title']); } elsif ($request->uri =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) { - $displayfile = &mt('Syllabus file: [_1]',$1); + my $filename = $1; + if ($1 eq 'loncapa.html') { + $displayfile = &mt('Syllabus (minimal template)'); + $action = $request->uri.'?forceedit=1'; + } else { + $displayfile = &mt('Syllabus file: [_1]',$1); + } $itemtitle = &mt('Syllabus'); } } @@ -1842,7 +1887,7 @@ ENDNOTFOUND my ($edit_info, $add_to_onload, $add_to_onresize)= &inserteditinfo($filecontents,$filetype,$displayfile,$symb, - $itemtitle,$env{'form.folderpath'},$request->uri); + $itemtitle,$env{'form.folderpath'},$request->uri,$action); my %options = ('add_entries' => @@ -1852,7 +1897,7 @@ ENDNOTFOUND if ($env{'request.state'} eq 'construct') { $options{'bread_crumbs'} = [{ 'href' => &Apache::loncommon::authorspace($request->uri), - 'text' => 'Construction Space'}, + 'text' => 'Authoring Space'}, {'href' => '', 'text' => $breadcrumbtext}]; $header = &Apache::loncommon::head_subbox( @@ -1887,7 +1932,7 @@ sub display_title { $title = substr($title, rindex($title, '/') + 1); } $result = ""; + .&mt('Authoring Space')."';"; } return $result; } @@ -2008,7 +2053,7 @@ sub error { my $declutter=&Apache::lonnet::declutter($env{'request.filename'}); my $baseurl = &Apache::lonnet::clutter($declutter); my @userlist; - foreach (keys %users) { + foreach (keys(%users)) { my ($user,$domain) = split(/:/, $_); push(@userlist,"$user:$domain"); my $key=$declutter.'_'.$user.'_'.$domain; @@ -2266,7 +2311,7 @@ sub description { sub helpinfo { my ($token)=@_; my $tag = &get_tag($token); - return ($insertlist{$tag.'.helpfile'}, $insertlist{$tag.'.helpdesc'}); + return ($insertlist{$tag.'.helpfile'}, &mt($insertlist{$tag.'.helpdesc'})); } sub get_tag {