--- loncom/interface/lonfeedback.pm 2009/11/26 05:21:43 1.280 +++ loncom/interface/lonfeedback.pm 2010/03/10 21:25:50 1.291 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.280 2009/11/26 05:21:43 faziophi Exp $ +# $Id: lonfeedback.pm,v 1.291 2010/03/10 21:25:50 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::lonnavmaps; use Apache::lonenc(); use Apache::lonrss(); use HTML::LCParser(); +#use HTML::Tidy::libXML; use Apache::lonspeller(); use Apache::longroup; use Cwd; @@ -272,10 +273,6 @@ sub list_discussion { my %anonhash=(); my $anoncnt=0; my $target=''; - unless ($env{'browser.interface'} eq 'textual' || - $env{'environment.remote'} eq 'off' ) { - $target='target="LONcom"'; - } my $now = time; $discinfo{$visitkey} = $visit; @@ -356,10 +353,10 @@ sub list_discussion { $togglink = 'toggoff'; } - $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; + $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink; if ($newpostsflag) { - $chglink .= '&previous='.$prevread; + $chglink .= '&previous='.$prevread; } $chglink.=&group_args($group); @@ -402,8 +399,7 @@ sub list_discussion { my $manifestfilename = $tempexport.$manifest; if ($manifestfile = Apache::File->new('>'.$manifestfilename)) { $manifestok=1; - print $manifestfile qq| - + print $manifestfile qq| - |; + |); $discussion.='
'. "\n".''; $discussion .= &action_links_bar($colspan,$ressymb,$visible, @@ -450,7 +445,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ $discussion.="\n".''; } $discussion .= (<2) { $discussion .= ''.&mt('Threaded View').'  '. ''.&mt('Chronological View').'   '.&mt('Sorting/Filtering options').''.(' ' x2); } $discussion .=''.&mt('Export').'?  '; @@ -815,7 +810,7 @@ sub action_links_bar { &mt('Preferences on what is marked as NEW'). '
'.&mt('Mark NEW posts no longer new').''; + $discussion .= '">'.&mt('Mark NEW posts no longer new').''; } else { $discussion .= '
'; } @@ -848,7 +843,7 @@ sub postingform_display {
$lt{'note'}
$lt{'title'}: 

- + ENDDISCUSS if ($env{'form.origpage'}) { $postingform .= '['.$$anonhash{$key}.'] '. $screenname; @@ -1057,7 +1053,7 @@ sub build_posting_display { $sender.=' '.&mt('Edit').''; @@ -1075,7 +1071,7 @@ sub build_posting_display { $sender.=' '.&mt('Make Visible').''; } @@ -1083,7 +1079,7 @@ sub build_posting_display { $sender.=' '.&mt('Hide').''; @@ -1099,6 +1095,7 @@ sub build_posting_display { } else { $sender=''.$$anonhash{$key}.''; } + $sender = ''.$sender.''; # Set up for sorting by domain, then username for anonymous unless (defined($$usernamesort{'__anon'})) { %{$$usernamesort{'__anon'}} = (); @@ -1124,7 +1121,7 @@ sub build_posting_display { $sender.=' '.&mt('Reply').''; @@ -1135,13 +1132,13 @@ sub build_posting_display { $sender.=' '.&mt('Reply').''; } } if ($viewgrades) { - $vgrlink=&Apache::loncommon::submlink('Submissions', + $vgrlink=&Apache::loncommon::submlink(&mt('Submissions'), $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb); } if ($$dischash{$readkey}=~/\.$idx\./) { @@ -1245,24 +1242,24 @@ sub build_posting_display { if ($prevread > 0 && $prevread <= $posttime) { $$newitem{$idx} = 1; $$discussionitems[$idx] .= ' -

'. ''.&mt('Show all posts').' '.&mt('to display').' '. @@ -530,11 +525,11 @@ imscp_v1p1.xsd http://www.imsglobal.org/ print $manifestfile "\n". ''. - ''.$imsitems{$alldiscussion{$post}}{'title'}.''; + ''.$imsitems{$alldiscussion{$post}}{'title'}.''; $imsresources .= "\n". ''."\n". ''."\n". - $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}."\n". + $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}.''."\n". ''; } my $postingfile; @@ -569,7 +564,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/ + $lt{'cuse'}:
- $lt{'cuse'}:   END @@ -591,7 +586,7 @@ END   - $lt{'chgt'}? + $lt{'chgt'}?
@@ -646,7 +641,7 @@ END $discussion.='
'. ''."\n". ''."\n". + ' onclick="this.form.submit();" />'."\n". ' 
+
'; } else { $$newitem{$idx} = 0; $$discussionitems[$idx] .= ' -

'.&mt('NEW').'
+
'; } $$discussionitems[$idx] .= ''; if ($$dischash{$toggkey}) { $$discussionitems[$idx].=''; } $$discussionitems[$idx].= '
   '. ''.$subject.'  '. - $sender.' '.$vgrlink.' ('. + $sender.' '.$vgrlink.' ('. &Apache::lonlocal::locallocaltime($posttime).')  '. $ctlink.'
'. - $message.'

'; + $message.''; if ($contrib{$idx.':history'}) { my @postversions = (); $$discussionitems[$idx] .= &mt('This post has been edited by the author.'); @@ -1397,7 +1394,9 @@ sub get_post_contents { my ($timesent,$attachmsg); my %currattach = (); $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]); - &newline_to_br(\$messages->{$i}); + unless (&contains_block_html($messages->{$i})) { + &newline_to_br(\$messages->{$i}); + } $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i}); $$subjects{$i}=~s/\n/\
/g; $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i}); @@ -1411,7 +1410,7 @@ sub get_post_contents { foreach my $key (sort(keys(%currattach))) { if ($$allattachments{$key}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) { my $fname = $1.$3.'/'.$4; - $$imsfiles{$idx}{$i} .= ''."\n"; + $$imsfiles{$idx}{$i} .= ''."\n"; $$attachtxt{$i}.= ''.$4.'
'; } } @@ -1676,7 +1675,10 @@ END 'bread_crumbs' => $brcrum,}); if ($quote ne '') { - &newline_to_br(\$quote); + $quote = &HTML::Entities::decode($quote); + unless (&contains_block_html($quote)) { + &newline_to_br(\$quote); + } $quote='
'.&Apache::lontexconvert::msgtexconverted($quote).'
'; } @@ -1708,9 +1710,8 @@ $latexHelp

$lt{'title'}:

-

-

END if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) { if ($env{'form.origpage'}) { @@ -1732,6 +1733,7 @@ END } } else { $r->print(< $lt{'atta'} $attachmaxtext:

END @@ -1745,7 +1747,7 @@ END $r->print(< - +

END @@ -1952,9 +1954,9 @@ END $r->print(<$lt{'disa'} $lt{$discdisp} - +
- + END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1969,7 +1971,7 @@ END $r->print(<$lt{'dotm'} $lt{$disctogg} - + END my $save = &mt('Save'); $r->print(&Apache::loncommon::end_data_table_row()); @@ -1983,7 +1985,7 @@ END - + END if (exists($env{'form.group'})) { $r->print(''); @@ -2136,17 +2138,17 @@ $start_page

- - - - - - - - - - - + + + + + + + + + + +
$lt{'soor'} $lt{'sprs'} $lt{'spur'} $lt{'spse'} $lt{'spgr'} $lt{'psub'}$lt{'soor'} $lt{'sprs'} $lt{'spur'} $lt{'spse'} $lt{'spgr'} $lt{'psub'}
@@ -2201,7 +2203,7 @@ $start_page
- + END if (exists($env{'form.group'})) { $r->print(''); @@ -2324,7 +2326,7 @@ END
- + $end_page END @@ -2396,7 +2398,7 @@ sub fail_redirect { my ($r,$feedurl) = @_; if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' }; my %lt = &Apache::lonlocal::texthash( - 'sorr' => 'Sorry, no recipients ...', + 'sorr' => 'Sorry, no recipients ...', ); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); $r->print(&Apache::loncommon::start_page('Feedback not sent',undef, @@ -2427,7 +2429,7 @@ sub redirect_back { if ($previous > 0) { $qrystr = 'previous='.$previous; if ($feedurl =~ /\?register=1/) { - $feedurl .= '&'.$qrystr; + $feedurl .= '&'.$qrystr; } else { $feedurl .= '?'.$qrystr; } @@ -2436,18 +2438,18 @@ sub redirect_back { if (defined($sort)) { my $sortqry = 'sortposts='.$sort; if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) { - $feedurl .= '&'.$sortqry; + $feedurl .= '&'.$sortqry; } else { $feedurl .= '?'.$sortqry; } $sorttag = ''; if (defined($numpicks)) { my $userpickqry = 'totposters='.$numpicks; - $feedurl .= '&'.$userpickqry; + $feedurl .= '&'.$userpickqry; $userpicktag = ''; } else { if (ref($sectionpick) eq 'ARRAY') { - $feedurl .= '§ionpick='; + $feedurl .= '&sectionpick='; $sectag .= ''; } else { - $feedurl .= '§ionpick='.$sectionpick; + $feedurl .= '&sectionpick='.$sectionpick; $sectag = ''; } if (ref($grouppick) eq 'ARRAY') { - $feedurl .= '&grouppick='; + $feedurl .= '&grouppick='; $sectag .= ''; } else { - $feedurl .= '&grouppick='.$grouppick; + $feedurl .= '&grouppick='.$grouppick; $grptag = ''; } if (ref($rolefilter) eq 'ARRAY') { - $feedurl .= '&rolefilter='; + $feedurl .= '&rolefilter='; $roletag .= ''; } else { - $feedurl .= '&rolefilter='.$rolefilter; + $feedurl .= '&rolefilter='.$rolefilter; $roletag = ''; } - $feedurl .= '&statusfilter='.$statusfilter; + $feedurl .= '&statusfilter='.$statusfilter; $statustag =''; } } @@ -2509,10 +2511,6 @@ sub redirect_back { &Apache::lonenc::check_encrypt(\$feedurl); my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); my %onload; - if ($env{'environment.remote'} ne 'off') { - $onload{'onload'} = - "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }"; - } my $start_page= &Apache::loncommon::start_page('Feedback sent',undef, {'redirect' => [0,$feedurl], @@ -2543,13 +2541,9 @@ ENDREDIR sub no_redirect_back { my ($r,$feedurl) = @_; - my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); + my $nofeed=&mt('Sorry, no feedback possible on this resource ...'); my %onload; - if ($env{'environment.remote'} ne 'off') { - $onload{'onload'} = - "if (window.name!='loncapaclient') { self.window.close(); }"; - } my %body_options = ('only_body' => 1, 'bgcolor' => '#FFFFFF', @@ -2647,7 +2641,7 @@ sub screen_header { .$msgoptions; } if ($discussoptions) { - $discussoptions='

' + $discussoptions='

' .' '.&mt('Discussion Contributions').'

'.&Apache::lonhtmlcommon::coursepreflink(&mt('Discussion Settings'),'discussion').'

' .$discussoptions; } @@ -2679,11 +2673,12 @@ sub clear_out_html { ($override)) { # allows


      • #

        - # + # %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1, BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1, M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1, - H1=>1, H2=>1, H3=>1, H4=>1, H5=>1); + H1=>1, H2=>1, H3=>1, H4=>1, H5=>1, H6=>1, + TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1); } # Do the substitution of everything that is not explicitly allowed $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/ @@ -2950,18 +2945,31 @@ sub show_preview { } sub contains_block_html { + my ($message)=@_; + return ($message =~ m{ + <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div) + \s* + (\w+\=['"]\w+['"])* + \s* + ( + \s*/>| + >.* + )}xs + ); +} + +sub tidy_html { my ($message)=@_; - return ($message =~ m/ - <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div) - [\s]* - ([\w]+\=['"][\w]+['"])* - [\s]* - ( - [\s]*[\/]>| - >.*<\/\1[\s]*> - )/x ); +# my $tidy = HTML::Tidy::libXML->new(); +# my $xhtml = $tidy->clean($message, 'utf-8', 1); +# $xhtml =~ m/(.*)<\/body>/is; +# my $clean = $1; +# # remove any empty block-level tags +# $clean =~ s/<(table|p|div|tbody|blockquote|m|pre|algebra|center|ol|ul|span|h1|h2|h3|h4|h5|h6)\s*\/>//i; +# $message=$clean; + return $message; } - + sub newline_to_br { my ($message)=@_; my $newmessage; @@ -2994,7 +3002,7 @@ sub generate_preview_button { +onclick="if (typeof(document.$formname.onsubmit)=='function') {document.$formname.onsubmit();};this.form.comment.value=document.$formname.$fieldname.value;this.form.subject.value=document.$formname.subject.value;this.form.submit();" /> ENDPREVIEW } @@ -3053,7 +3061,7 @@ $toolarge
        @@ -3104,7 +3112,7 @@ END $r->print(''."\n"); } $r->print(< + $end_page END @@ -3151,7 +3159,7 @@ sub generate_attachments_button {
        $lt{'clic'}: send_http_header; my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif'); my %onload; - if ($env{'environment.remote'} ne 'off') { - $onload{'onload'} = - "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }"; - } my $start_page= &Apache::loncommon::start_page('New posts marked as read',undef, @@ -4146,6 +4150,8 @@ None =item newline_to_br() +=item tidy_html() + =item generate_preview_button() =item modify_attachments()
        - Subject: $subject

        + Subject: $subject

        END if ($idx) { if ($attachmenturls) { @@ -3081,7 +3089,7 @@ END
        - $lt{'adda'} + $lt{'adda'}