';
+ $discussion .= '">'.&mt('Export').'';
+ if ($seehidden) {
+ $discussion .= ' ';
+ $discussion .=''.&mt('Undelete all deleted entries').'';
+ }
+ $discussion.='';
if ($newpostsflag) {
if (!$markondisp) {
$discussion .='
-
+
$lt{'note'}
-$lt{'title'}:
+$lt{'title'}:
ENDDISCUSS
if ($env{'form.origpage'}) {
@@ -925,7 +999,7 @@ ENDDISCUSS
}
sub build_posting_display {
- my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_;
+ my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$ressymb,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_;
my @original=();
my @index=();
my $skip_group_check = 0;
@@ -935,14 +1009,20 @@ sub build_posting_display {
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
+ my (%likes,%userlikes,%userunlikes,@theselikes,$oneplus,$twoplus,$oneminus,$twominus);
+ my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
+ if ($seeid || $canvote) {
# And these are the likes/unlikes
- my %likes=&Apache::lonnet::dump('disclikes',
+ %likes=&Apache::lonnet::dump('disclikes',
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'},
'^'.$symb.':');
- my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
# Array with likes to figure out averages, etc.
- my @theselikes=();
+ @theselikes=();
+# Hashes containing likes and unlikes for this user.
+ %userlikes=();
+ %userunlikes=();
+ }
# Is the user allowed to see the real name behind anonymous postings?
my $see_anonymous =
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
@@ -976,41 +1056,79 @@ sub build_posting_display {
&filter_regexp($rolefilter,$sectionpick,$statusfilter);
$rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
}
+ my %votestyle;
+ if ($seeid || $canvote) {
# We need to go through this twice, first to get the likes/dislikes, then to actually build the display
- for (my $id=1;$id<=$contrib{'version'};$id++) {
- my $idx=$id;
- next if ($contrib{$idx.':deleted'});
- next if ($contrib{$idx.':hidden'});
- unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
- push(@theselikes,$likes{$symb.':'.$idx.':likes'});
+ for (my $id=1;$id<=$contrib{'version'};$id++) {
+ my $idx=$id;
+ next if ($contrib{$idx.':deleted'});
+ next if ($contrib{$idx.':hidden'});
+ unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
+ push(@theselikes,$likes{$symb.':'.$idx.':likes'});
+ if ($likes{$symb.':'.$idx.':likes'} ne '') {
+ if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') {
+ if (exists($likes{$symb.':'.$idx.':likers'}{$thisuser})) {
+ $userlikes{$idx} = 1;
+ }
+ }
+ if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') {
+ if (exists($likes{$symb.':'.$idx.':unlikers'}{$thisuser})) {
+ $userunlikes{$idx} = 1;
+ }
+ }
+ }
+ }
}
- }
-# Figure out average likes and standard deviation if there are enough discussions to warrant that
- my $ave=0;
- my $stddev=10000;
- if ($#theselikes>1) {
- my $sum=0;
- my $num=$#theselikes+1;
- foreach my $thislike (@theselikes) {
- $sum+=$thislike;
- }
- $ave=$sum/$num;
- my $sumsq=0;
- foreach my $thislike (@theselikes) {
- $sumsq+=($thislike-$ave)*($thislike-$ave);
+# Figure out average likes and standard deviation if there are enough
+# discussions to warrant that
+ my $ave=0;
+ my $stddev=10000;
+ if ($#theselikes>1) {
+ my $sum=0;
+ my $num=$#theselikes+1;
+ foreach my $thislike (@theselikes) {
+ $sum+=$thislike;
+ }
+ $ave=$sum/$num;
+ my $sumsq=0;
+ foreach my $thislike (@theselikes) {
+ $sumsq+=($thislike-$ave)*($thislike-$ave);
+ }
+ $stddev=sqrt($sumsq/$num);
}
- $stddev=sqrt($sumsq/$num);
- }
# Now we know the average likes $ave and the standard deviation $stddev
# Get the boundaries for markup
- my $oneplus=$ave+$stddev;
- my $twoplus=$ave+2.*$stddev;
- my $oneminus=$ave-$stddev;
- my $twominus=$ave-2.*$stddev;
-# &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev $twominus $oneminus $oneplus $twoplus");
+ $oneplus=$ave+$stddev;
+ $twoplus=$ave+2.*$stddev;
+ $oneminus=$ave-$stddev;
+ $twominus=$ave-2.*$stddev;
+ if ($#theselikes>1) {
+ foreach my $class ('twoplus','oneplus','zero','oneminus','twominus') {
+ my $fontstyle = $env{'course.'.$env{'request.course.id'}.'.discussion_post_fonts_'.$class};
+ if ($fontstyle ne '') {
+ my ($size,$weight,$style,$other) = split(/,/,$fontstyle);
+ if ($size ne '') {
+ $votestyle{$class} .= 'font-size: '.$size.';';
+ }
+ if ($weight ne '') {
+ $votestyle{$class} .= 'font-weight: '.$weight.';';
+ }
+ if ($style ne '') {
+ $votestyle{$class} .= 'font-style: '.$style.';';
+ }
+ if ($other ne '') {
+ $votestyle{$class} .= $other;
+ }
+ if ($votestyle{$class} ne '') {
+ $votestyle{$class} = 'style="'.$votestyle{$class}.'"';
+ }
+ }
+ }
+ }
+ }
#
# This is now the real loop. Go through all entries, pick up what we need
-#
+#
for (my $id=1;$id<=$contrib{'version'};$id++) {
my $idx=$id;
next if ($contrib{$idx.':deleted'});
@@ -1025,7 +1143,8 @@ sub build_posting_display {
my $origindex='0.';
my $numoldver=0;
if ($contrib{$idx.':replyto'}) {
- if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+ if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) ||
+ ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
# this is a follow-up message
$original[$idx]=$original[$contrib{$idx.':replyto'}];
$$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
@@ -1045,7 +1164,7 @@ sub build_posting_display {
} else {
$$replies[$$depth[$idx]]=1;
}
- unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx})) {
+ unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) {
$$visible++;
if ($contrib{$idx.':history'}) {
if ($contrib{$idx.':history'} =~ /:/) {
@@ -1060,7 +1179,7 @@ sub build_posting_display {
my %subjects = ();
my %attachtxt = ();
my %allattachments = ();
- my ($screenname,$plainname);
+ my ($screenname,$plainname,$showaboutme);
my $sender = &mt('Anonymous');
# Anonymous users getting number within a discussion
# Since idx is in static order, this should give the same sequence every time.
@@ -1070,7 +1189,7 @@ sub build_posting_display {
$$anonhash{$key}=&mt('Anonymous').' '.$anoncnt;
}
my ($message,$subject,$vgrlink,$ctlink);
- &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver);
+ &get_post_contents(\%contrib,$idx,$seeid,$seehidden,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver);
# Set up for sorting by subject
@@ -1100,12 +1219,18 @@ sub build_posting_display {
}
}
if (!$contrib{$idx.':anonymous'} || $see_anonymous) {
- $sender=&Apache::loncommon::aboutmewrapper(
- $plainname,
- $contrib{$idx.':sendername'},
- $contrib{$idx.':senderdomain'}).' ('.
- $contrib{$idx.':sendername'}.':'.
- $contrib{$idx.':senderdomain'}.')';
+ if ($showaboutme) {
+ $sender = &Apache::loncommon::aboutmewrapper(
+ $plainname,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'});
+ } else {
+ $sender = $plainname;
+ }
+ if ($see_anonymous) {
+ $sender .= ' ('.$contrib{$idx.':sendername'}.':'.
+ $contrib{$idx.':senderdomain'}.')';
+ }
$sender = ''.$sender.'';
if ($contrib{$idx.':anonymous'}) {
$sender.=' ['.$$anonhash{$key}.'] '.
@@ -1144,30 +1269,24 @@ sub build_posting_display {
@{$$namesort{$lastname}{$firstname}} = ("$idx");
}
if ($outputtarget ne 'tex') {
- unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) {
- $sender.=' '.&discussion_link($symb,&mt('Like'),'like',$idx,$$newpostsflag,$prevread,&group_args($group));
- }
- unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {
- $sender.=' '.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group));
- }
- my $thislikes=$likes{$symb.':'.$idx.':likes'};
- if ($thislikes>0) {
- $sender.=' ('.&mt("[_1] likes",$thislikes).')';
- } elsif ($thislikes<0) {
- $sender.=' ('.&mt("[_1] unlikes",abs($thislikes)).')';
+# Add karma stars
+ my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
+ for (my $i=1;$i<=$karma;$i++) {
+ $sender.='';
}
+# Can people edit this?
if (&editing_allowed($escsymb.':::'.$idx,$group)) {
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
$sender.=' '.
&discussion_link($symb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group));
- unless ($seeid) {
+ unless ($seehidden) {
my $grpargs = &group_args($group);
$sender.=" ';
}
}
}
- if ($seeid) {
+ if ($seehidden) {
if ($hiddens{$idx}) {
unless ($studenthidden) {
$sender.=' '.
@@ -1238,7 +1357,8 @@ sub build_posting_display {
}
if ($outputtarget eq 'export' || $message) {
my $thisindex=$idx;
- if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+ if ( ((!$env{'environment.unthreadeddiscussion'}) && ($sortposts eq '')) ||
+ ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
$thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
}
$$alldiscussion{$thisindex}=$idx;
@@ -1270,14 +1390,15 @@ sub build_posting_display {
} else {
if ($message) {
my $spansize = 2;
+ my ($uname,$udom);
if ($showonlyunread && $prevread > $posttime) {
$$notshown{$idx} = 1;
} elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
$$notshown{$idx} = 1;
} else {
# apply filters
- my $uname = $contrib{$idx.':sendername'};
- my $udom = $contrib{$idx.':senderdomain'};
+ $uname = $contrib{$idx.':sendername'};
+ $udom = $contrib{$idx.':senderdomain'};
my $poster = $uname.':'.$udom;
if ($env{'form.totposters'} ne '') {
if ($totposters == 0) {
@@ -1338,27 +1459,74 @@ sub build_posting_display {
if ($$dischash{$toggkey}) {
$$discussionitems[$idx].=' '.$ctlink;
}
-# Figure out size based on likes
my $thislikes=$likes{$symb.':'.$idx.':likes'};
- my $likesize="100";
- if ($thislikes>$twoplus) {
- $likesize="200";
- } elsif ($thislikes>$oneplus) {
- $likesize="150";
- }
- if ($thislikes<$twominus) {
- $likesize="50";
- } elsif ($thislikes<$oneminus) {
- $likesize="75";
+ my $likestyle;
+ if ($seeid || $canvote) {
+# Figure out size based on likes
+ my $class = 'zero';
+ my $thislikes=$likes{$symb.':'.$idx.':likes'};
+ if ($thislikes>$twoplus) {
+ $class = 'twoplus';
+ } elsif ($thislikes>$oneplus) {
+ $class = 'oneplus';
+ }
+ if ($thislikes<$twominus) {
+ $class = 'twominus';
+ } elsif ($thislikes<$oneminus) {
+ $class = 'oneminus';
+ }
+ $likestyle = $votestyle{$class};
}
+# Actually glue in the message itself
$$discussionitems[$idx].= '