version 1.321, 2012/01/04 23:31:36
|
version 1.323, 2012/01/06 01:59:53
|
Line 763 sub discussion_link {
|
Line 763 sub discussion_link {
|
my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; |
my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; |
if ($flag) { $link .= '&previous='.$prev; } |
if ($flag) { $link .= '&previous='.$prev; } |
if ($adds) { $link .= $adds; } |
if ($adds) { $link .= $adds; } |
return &Apache::loncommon::modal_link($link,$linktext,600,600); |
my $width=600; |
|
my $height=600; |
|
if (($cmd eq 'hide') || ($cmd eq 'unhide') || ($cmd eq 'like') || ($cmd eq 'unlike')) { |
|
$width=300; |
|
$height=200; |
|
} |
|
return &Apache::loncommon::modal_link($link,$linktext,$width,$height); |
} |
} |
|
|
|
|
Line 925 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', |
|
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
|
$env{'course.'.$env{'request.course.id'}.'.num'}, |
|
'^'.$symb.':'); |
|
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 948 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 1090 sub build_posting_display {
|
Line 1105 sub build_posting_display {
|
@{$$namesort{$lastname}{$firstname}} = ("$idx"); |
@{$$namesort{$lastname}{$firstname}} = ("$idx"); |
} |
} |
if ($outputtarget ne 'tex') { |
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)).')'; |
|
} |
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 3554 sub handler {
|
Line 3581 sub handler {
|
# --------------------------- Get query string for limited number of parameters |
# --------------------------- Get query string for limited number of parameters |
|
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['modal','hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); |
['like','unlike','modal','hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); |
my $group = $env{'form.group'}; |
my $group = $env{'form.group'}; |
my %attachmax = ( |
my %attachmax = ( |
text => &mt('(128 KB max size)'), |
text => &mt('(128 KB max size)'), |
Line 3834 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); |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
# |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
# Likes and unlikes are in db-file "disclikes" of the course |
$env{'course.'.$env{'request.course.id'}.'.num'}); |
# The prefix is the $symb to identify the resource discussion, |
|
# and the $idx to identify the entry |
|
# |
|
my $prefix=$symb.':'.$idx.':'; |
|
my %contrib=&Apache::lonnet::dump('disclikes', |
|
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
|
$env{'course.'.$env{'request.course.id'}.'.num'}, |
|
'^'.$prefix); |
# Get all who like or unlike this |
# Get all who like or unlike this |
my $currentlikers=$contrib{$idx.':likers'}; |
my $currentlikers=$contrib{$prefix.'likers'}; |
my $currentunlikers=$contrib{$idx.':unlikers'}; |
my $currentunlikers=$contrib{$prefix.'unlikers'}; |
my $likes=$contrib{$idx.':likes'}; |
# Get the current "likes" count |
|
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'}) { |
if ($currentlikers=~/\.\Q$thisuser\E\./) { |
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
$alreadyflag=1; |
$alreadyflag=1; |
} else { |
} else { |
$currentunlikers=~s/\.\Q$thisuser\E\.//; |
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
$currentlikers.='.'.$thisuser.'.'; |
$currentunlikers=~s/\,\Q$thisuser\E\,//g; |
|
} else { |
|
$currentlikers.=','.$thisuser.','; |
|
} |
$likes++; |
$likes++; |
} |
} |
} else { |
} else { |
if ($currentunlikers=~/\.\Q$thisuser\E\./) { |
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
$alreadyflag=1; |
$alreadyflag=1; |
} else { |
} else { |
$currentlikers=~s/\.\Q$thisuser\E\.//; |
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
$currentunlikers.='.'.$thisuser.'.'; |
$currentlikers=~s/\,\Q$thisuser\E\,//g; |
|
} else { |
|
$currentunlikers.=','.$thisuser.','; |
|
} |
$likes--; |
$likes--; |
} |
} |
} |
} |
my $result; |
my $result; |
|
# $alreadyflag would be 1 if they tried to double-like or double-unlike |
unless ($alreadyflag) { |
unless ($alreadyflag) { |
my %newhash=($idx.':likes' => $likes, |
my %newhash=($prefix.'likes' => $likes, |
$idx.':likers' => $currentlikers, |
$prefix.'likers' => $currentlikers, |
$idx.':unlikers' => $currentunlikers); |
$prefix.'unlikers' => $currentunlikers); |
if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, |
# Store data in db-file "disclikes" |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
if (&Apache::lonnet::put('disclikes', |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
\%newhash, |
|
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
|
$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 3877 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"); |
} |
} |
} |
} |