version 1.322, 2012/01/05 21:18:49
|
version 1.323, 2012/01/06 01:59:53
|
Line 931 sub build_posting_display {
|
Line 931 sub build_posting_display {
|
my $skip_group_check = 0; |
my $skip_group_check = 0; |
my $symb=&Apache::lonenc::check_decrypt($ressymb); |
my $symb=&Apache::lonenc::check_decrypt($ressymb); |
my $escsymb=&escape($ressymb); |
my $escsymb=&escape($ressymb); |
|
# These are the discussion contributions |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}); |
$env{'course.'.$env{'request.course.id'}.'.num'}); |
|
# And these are the likes/unlikes |
my %likes=&Apache::lonnet::dump('disclikes', |
my %likes=&Apache::lonnet::dump('disclikes', |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}, |
'^'.$symb.':'); |
'^'.$symb.':'); |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
|
# Is the user allowed to see the real name behind anonymous postings? |
my $see_anonymous = |
my $see_anonymous = |
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); |
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); |
|
|
if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) { |
if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) { |
$skip_group_check = 1; |
$skip_group_check = 1; |
} |
} |
|
# Deletions and hiddens are just lists. Split them up into a hash for quicker lookup |
my (%deletions,%hiddens); |
my (%deletions,%hiddens); |
if ($contrib{'deleted'}) { |
if ($contrib{'deleted'}) { |
my $deleted = $contrib{'deleted'}; |
my $deleted = $contrib{'deleted'}; |
Line 959 sub build_posting_display {
|
Line 962 sub build_posting_display {
|
$hidden =~ s/\.$//; |
$hidden =~ s/\.$//; |
%hiddens = map { $_ => 1 } (split(/\.\./,$hidden)); |
%hiddens = map { $_ => 1 } (split(/\.\./,$hidden)); |
} |
} |
|
# Versions ... |
if ($contrib{'version'}) { |
if ($contrib{'version'}) { |
my $oldest = $contrib{'1:timestamp'}; |
my $oldest = $contrib{'1:timestamp'}; |
if ($prevread eq '0') { |
if ($prevread eq '0') { |
Line 1107 sub build_posting_display {
|
Line 1111 sub build_posting_display {
|
unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { |
unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { |
$sender.=' '.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group)); |
$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)).')'; |
|
} |
if (&editing_allowed($escsymb.':::'.$idx,$group)) { |
if (&editing_allowed($escsymb.':::'.$idx,$group)) { |
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { |
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { |
$sender.=' '. |
$sender.=' '. |
Line 3851 ENDREDIR
|
Line 3861 ENDREDIR
|
my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; |
my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; |
my ($symb,$idx)=split(/\:\:\:/,$entry); |
my ($symb,$idx)=split(/\:\:\:/,$entry); |
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); |
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); |
|
# |
|
# Likes and unlikes are in db-file "disclikes" of the course |
|
# The prefix is the $symb to identify the resource discussion, |
|
# and the $idx to identify the entry |
|
# |
my $prefix=$symb.':'.$idx.':'; |
my $prefix=$symb.':'.$idx.':'; |
my %contrib=&Apache::lonnet::dump('disclikes', |
my %contrib=&Apache::lonnet::dump('disclikes', |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
Line 3859 ENDREDIR
|
Line 3874 ENDREDIR
|
# Get all who like or unlike this |
# Get all who like or unlike this |
my $currentlikers=$contrib{$prefix.'likers'}; |
my $currentlikers=$contrib{$prefix.'likers'}; |
my $currentunlikers=$contrib{$prefix.'unlikers'}; |
my $currentunlikers=$contrib{$prefix.'unlikers'}; |
|
# Get the current "likes" count |
my $likes=$contrib{$prefix.'likes'}; |
my $likes=$contrib{$prefix.'likes'}; |
# Find out if they already voted |
# Find out if they already voted |
|
# Users cannot like a post twice, or unlike it twice. They can change their mind, though |
my $alreadyflag=0; |
my $alreadyflag=0; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
if ($env{'form.like'}) { |
if ($env{'form.like'}) { |
Line 3868 ENDREDIR
|
Line 3885 ENDREDIR
|
$alreadyflag=1; |
$alreadyflag=1; |
} else { |
} else { |
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
$currentunlikers=~s/\,\Q$thisuser\E\,//; |
$currentunlikers=~s/\,\Q$thisuser\E\,//g; |
} else { |
} else { |
$currentlikers.=','.$thisuser.','; |
$currentlikers.=','.$thisuser.','; |
} |
} |
Line 3879 ENDREDIR
|
Line 3896 ENDREDIR
|
$alreadyflag=1; |
$alreadyflag=1; |
} else { |
} else { |
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
$currentlikers=~s/\,\Q$thisuser\E\,//; |
$currentlikers=~s/\,\Q$thisuser\E\,//g; |
} else { |
} else { |
$currentunlikers.=','.$thisuser.','; |
$currentunlikers.=','.$thisuser.','; |
} |
} |
Line 3887 ENDREDIR
|
Line 3904 ENDREDIR
|
} |
} |
} |
} |
my $result; |
my $result; |
|
# $alreadyflag would be 1 if they tried to double-like or double-unlike |
unless ($alreadyflag) { |
unless ($alreadyflag) { |
my %newhash=($prefix.'likes' => $likes, |
my %newhash=($prefix.'likes' => $likes, |
$prefix.'likers' => $currentlikers, |
$prefix.'likers' => $currentlikers, |
$prefix.'unlikers' => $currentunlikers); |
$prefix.'unlikers' => $currentunlikers); |
|
# Store data in db-file "disclikes" |
if (&Apache::lonnet::put('disclikes', |
if (&Apache::lonnet::put('disclikes', |
\%newhash, |
\%newhash, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
|
# Also store with the person who posted the liked/unliked entry |
if ($env{'form.like'}) { |
if ($env{'form.like'}) { |
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
$result=&mt("Registered 'Like'"); |
$result=&mt("Registered 'Like'"); |
Line 3903 ENDREDIR
|
Line 3923 ENDREDIR
|
$result=&mt("Registered 'Unlike'"); |
$result=&mt("Registered 'Unlike'"); |
} |
} |
} else { |
} else { |
|
# Oops, something went wrong |
$result=&mt("Failed to register vote"); |
$result=&mt("Failed to register vote"); |
} |
} |
} |
} |