diff --git a/docs/gotcha.txt b/docs/gotcha.txt
index 0d62cf628..82b4baf2c 100644
--- a/docs/gotcha.txt
+++ b/docs/gotcha.txt
@@ -7,6 +7,14 @@ upgrading from one version to the next, or even between multiple
versions. Be sure to heed the warnings contained herein as they will
save you many hours of grief.
+4.2.0
+--------------------------------------------------------------------
+ * All Discussion properties have been reset to enable the new
+ discussion moderation features. If you are using discussions
+ on your site, you'll need to set these properties back to
+ whatever you were using. Note that none of the actual
+ discussion data has been changed or lost.
+
4.1.0
--------------------------------------------------------------------
* Between 3.6.5 and now, much of the WebGUI filesystem has changed
@@ -18,7 +26,6 @@ save you many hours of grief.
files (like conf files) from WebGUI.old to your new WebGUI
folder.
-
3.10.0 && 3.10.1
--------------------------------------------------------------------
* Be very very careful when applying the patch files for these
diff --git a/docs/upgrades/upgrade_4.1.0-4.2.0.sql b/docs/upgrades/upgrade_4.1.0-4.2.0.sql
index 4398a8ef9..538f02ae2 100644
--- a/docs/upgrades/upgrade_4.1.0-4.2.0.sql
+++ b/docs/upgrades/upgrade_4.1.0-4.2.0.sql
@@ -2,3 +2,66 @@ insert into webguiVersion values ('4.2.0','upgrade',unix_timestamp());
insert into international values (6,'Item','English','Edit Item');
insert into settings values ('runOnRegistration','');
insert into international values (559,'WebGUI','English','Run On Registration');
+alter table discussion add column locked int not null default 0;
+alter table discussion add column status varchar(30) not null default 'Approved';
+update international set internationalId=560, namespace='WebGUI' where internationalId=7 and namespace='UserSubmission';
+update international set internationalId=561, namespace='WebGUI' where internationalId=8 and namespace='UserSubmission';
+update international set internationalId=562, namespace='WebGUI' where internationalId=9 and namespace='UserSubmission';
+update international set internationalId=563, namespace='WebGUI' where internationalId=10 and namespace='UserSubmission';
+update international set internationalId=564, namespace='WebGUI' where internationalId=3 and namespace='MessageBoard';
+update international set internationalId=565, namespace='WebGUI' where internationalId=21 and namespace='MessageBoard';
+update international set internationalId=566, namespace='WebGUI' where internationalId=5 and namespace='MessageBoard';
+delete from international where internationalId=19 and namespace='Article';
+delete from international where internationalId=20 and namespace='Article';
+delete from international where internationalId=21 and namespace='Article';
+delete from international where namespace='UserSubmission' and internationalId=30;
+delete from international where namespace='UserSubmission' and internationalId=49;
+delete from international where namespace='UserSubmission' and internationalId=50;
+delete from international where namespace='UserSubmission' and internationalId=44;
+insert into international values (567,'WebGUI','English','Pre-emptive');
+insert into international values (568,'WebGUI','English','After-the-fact');
+insert into international values (569,'WebGUI','English','Moderation Type');
+alter table wobject add column groupToPost int not null default 2;
+alter table wobject add column editTimeout int not null default 1;
+alter table wobject add column groupToModerate int not null default 4;
+alter table wobject add column karmaPerPost int not null default 0;
+alter table wobject add column moderationType varchar(30) not null default 'after';
+alter table MessageBoard drop column editTimeout;
+alter table MessageBoard drop column groupToModerate;
+alter table MessageBoard drop column groupToPost;
+alter table MessageBoard drop column karmaPerPost;
+alter table UserSubmission drop column groupToPost;
+alter table UserSubmission drop column groupToModerate;
+alter table UserSubmission drop column editTimeout;
+alter table UserSubmission drop column karmaPerPost;
+alter table Article drop column karmaPerPost;
+alter table Article drop column editTimeout;
+alter table Article drop column groupToModerate;
+alter table Article drop column groupToPost;
+insert into international values (570,'WebGUI','English','Lock Thread');
+insert into international values (571,'WebGUI','English','Unlock Thread');
+update international set internationalId=572, namespace='WebGUI' where namespace='UserSubmission' and internationalId=24;
+update international set internationalId=573, namespace='WebGUI' where namespace='UserSubmission' and internationalId=25;
+update international set internationalId=574, namespace='WebGUI' where namespace='UserSubmission' and internationalId=26;
+insert into international values (575,'WebGUI','English','Edit');
+insert into international values (576,'WebGUI','English','Delete');
+update international set internationalId=577, namespace='WebGUI' where namespace='MessageBoard' and internationalId=13;
+delete from international where namespace='UserSubmission' and internationalId=42;
+delete from international where namespace='UserSubmission' and internationalId=43;
+delete from international where namespace='Article' and internationalId=25;
+delete from international where namespace='Article' and internationalId=26;
+insert into international values (578,'WebGUI','English','You have a pending message to approve.');
+insert into international values (579,'WebGUI','English','Your message has been approved.');
+insert into international values (580,'WebGUI','English','Your message has been denied.');
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/WebGUI/Discussion.pm b/lib/WebGUI/Discussion.pm
index 6fcbc6e70..646fb6e5b 100644
--- a/lib/WebGUI/Discussion.pm
+++ b/lib/WebGUI/Discussion.pm
@@ -16,13 +16,19 @@ use WebGUI::DateTime;
use WebGUI::HTML;
use WebGUI::HTMLForm;
use WebGUI::International;
+use WebGUI::MessageLog;
use WebGUI::Paginator;
+use WebGUI::Privilege;
use WebGUI::Search;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::User;
+our %status =("Approved"=>WebGUI::International::get(560),
+ "Denied"=>WebGUI::International::get(561),
+ "Pending"=>WebGUI::International::get(562));
+
#-------------------------------------------------------------------
sub _deleteReplyTree {
my ($sth, %data, $messageId);
@@ -49,6 +55,85 @@ sub _duplicateReplyTree {
$sth->finish;
}
+#-------------------------------------------------------------------
+sub _lockReplyTree {
+ my ($sth, %data, $messageId);
+ tie %data, 'Tie::CPHash';
+ $sth = WebGUI::SQL->read("select messageId from discussion where pid=$_[0] order by messageId");
+ while (%data = $sth->hash) {
+ _lockReplyTree($data{messageId});
+ WebGUI::SQL->write("update discussion set locked=1 where messageId=$data{messageId}");
+ }
+ $sth->finish;
+}
+
+#-------------------------------------------------------------------
+sub _unlockReplyTree {
+ my ($sth, %data, $messageId);
+ tie %data, 'Tie::CPHash';
+ $sth = WebGUI::SQL->read("select messageId from discussion where pid=$_[0] order by messageId");
+ while (%data = $sth->hash) {
+ _unlockReplyTree($data{messageId});
+ WebGUI::SQL->write("update discussion set locked=0 where messageId=$data{messageId}");
+ }
+ $sth->finish;
+}
+
+#-------------------------------------------------------------------
+sub approvePost {
+ my (%message);
+ tie %message, 'Tie::CPHash';
+ %message = getMessage($session{form}{mid});
+ WebGUI::SQL->write("update discussion set status='Approved' where messageId=$session{form}{mid}");
+ WebGUI::MessageLog::addInternationalizedEntry($message{userId},'',
+ WebGUI::URL::page('func=showMessage&wid='.$session{form}{wid}.'&sid='
+ .$session{form}{sid}.'&mid='.$session{form}{mid}), 579);
+ WebGUI::MessageLog::completeEntry($session{form}{mlog});
+ return WebGUI::Operation::www_viewMessageLog();
+}
+
+#-------------------------------------------------------------------
+sub canEditMessage {
+ my (%message);
+ tie %message, 'Tie::CPHash';
+ %message = getMessage($_[1]);
+ if ( # is the message owner
+ (
+ (time()-$message{dateOfPost}) < 3600*$_[0]->get("editTimeout")
+ && $message{userId} eq $session{user}{userId}
+ && !($message{locked})
+ )
+ # is a moderator
+ || WebGUI::Privilege::isInGroup($_[0]->get("groupToModerate"))
+ ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+#-------------------------------------------------------------------
+sub canPostReply {
+ if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost")) && !(${$_[1]}{locked}) && ${$_[1]}{status} eq "Approved") {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+#-------------------------------------------------------------------
+sub denyPost {
+ my (%message);
+ tie %message, 'Tie::CPHash';
+ %message = getMessage($session{form}{mid});
+ WebGUI::SQL->write("update discussion set status='Denied' where messageId=$session{form}{mid}");
+ WebGUI::MessageLog::addInternationalizedEntry($message{userId},'',
+ WebGUI::URL::page('func=showMessage&wid='.$session{form}{wid}.'&sid='
+ .$session{form}{sid}.'&mid='.$session{form}{mid}), 580);
+ WebGUI::MessageLog::completeEntry($session{form}{mlog});
+ return WebGUI::Operation::www_viewMessageLog();
+}
+
#-------------------------------------------------------------------
sub duplicate {
my ($sth, %data, $newMessageId, $oldSubId, $newSubId);
@@ -57,7 +142,9 @@ sub duplicate {
$sth = WebGUI::SQL->read("select * from discussion where wobjectId=$_[0] and pid=0 and subId=$oldSubId order by messageId");
while (%data = $sth->hash) {
$newMessageId = getNextId("messageId");
- WebGUI::SQL->write("insert into discussion values ($newMessageId, $newMessageId, $_[1], 0, $data{userId}, ".quote($data{username}).", ".quote($data{subject}).", ".quote($data{message}).", $data{dateOfPost}, $newSubId)");
+ WebGUI::SQL->write("insert into discussion values ($newMessageId, $newMessageId, $_[1], 0,
+ $data{userId}, ".quote($data{username}).", ".quote($data{subject}).", "
+ .quote($data{message}).", $data{dateOfPost}, $newSubId)");
_duplicateReplyTree($data{messageId},$newMessageId,$newMessageId,$_[1],$newSubId);
}
$sth->finish;
@@ -99,6 +186,7 @@ sub formatHeader {
'.$_[2].'
' if ($_[1] && $_[2] ne "");
$output .= "".WebGUI::International::get(239)." ".epochToHuman($_[3],"%z %Z")."
" if ($_[3]);
$output .= "".WebGUI::International::get(514).": ".$_[4]."
" if ($_[4]);
+ $output .= "".WebGUI::International::get(553).": ".$_[6]."
" if ($_[6]);
return $output;
}
@@ -129,6 +217,13 @@ sub getMessage {
return %message;
}
+#-------------------------------------------------------------------
+sub lockThread {
+ _lockReplyTree($session{form}{mid});
+ WebGUI::SQL->write("update discussion set locked=1 where messageId=$session{form}{mid}");
+ return "";
+}
+
#-------------------------------------------------------------------
sub post {
my ($html, $header, $footer, $f, %message);
@@ -137,30 +232,32 @@ sub post {
if ($session{form}{replyTo} ne "") { # is a reply
$header = WebGUI::International::get(234);
%message = getMessage($session{form}{replyTo});
- $footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views})
+ $footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views},
+ '',$message{status})
.'
'.formatMessage($message{message}); $message{message} = ""; $message{subject} = formatSubject("Re: ".$message{subject}) unless ($message{subject} =~ /^Re:/); $session{form}{mid} = "new"; $f->hidden("replyTo",$session{form}{replyTo}); - if ($session{user}{userId} == 1) { - $f->text("visitorName",WebGUI::International::get(438)); + if ($session{user}{userId} == 1) { + $f->text("visitorName",WebGUI::International::get(438)); } } elsif ($session{form}{mid} eq "new") { # is an entirely new thread $header = WebGUI::International::get(231); if ($session{user}{userId} == 1) { - $f->text("visitorName",WebGUI::International::get(438)); - } + $f->text("visitorName",WebGUI::International::get(438)); + } } else { # is editing an existing message $header = WebGUI::International::get(228); %message = getMessage($session{form}{mid}); - $footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views}) + $footer = formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views}, + '',$message{status}) .'
'.formatMessage($message{message}); $message{subject} = formatSubject($message{subject}); } - $f->hidden("func","postSave"); + $f->hidden("func","postSave"); $f->hidden("wid",$session{form}{wid}); - $f->hidden("sid",$session{form}{sid}); + $f->hidden("sid",$session{form}{sid}); $f->hidden("mid",$session{form}{mid}); $f->text("subject",WebGUI::International::get(229),$message{subject}); $f->HTMLArea("message",WebGUI::International::get(230),$message{message}); @@ -173,21 +270,21 @@ sub post { #------------------------------------------------------------------- sub postSave { - my ($u, $rid, $username, $pid); + my ($u, $rid, $status, $username, $pid); if ($session{form}{subject} eq "") { $session{form}{subject} = WebGUI::International::get(232); } if ($session{form}{message} eq "") { - $session{form}{subject} .= ' '.WebGUI::International::get(233); + $session{form}{subject} .= ' '.WebGUI::International::get(233); } if ($session{form}{mid} eq "new") { - if ($session{user}{userId} == 1) { - if ($session{form}{visitorName} eq "") { - $username = $session{user}{username}; - } else { + if ($session{user}{userId} == 1) { + if ($session{form}{visitorName} eq "") { + $username = $session{user}{username}; + } else { $username = $session{form}{visitorName}; - } - } else { + } + } else { $username = $session{user}{username}; } if ($session{form}{sid} eq "") { @@ -201,16 +298,28 @@ sub postSave { $rid = $session{form}{mid}; $pid = 0; } - WebGUI::SQL->write("insert into discussion (messageId, wobjectId, subId, rid, pid, userId, username) values - ($session{form}{mid},$session{form}{wid},$session{form}{sid},$rid,$pid,$session{user}{userId},".quote($username).")"); + if ($_[0]->get("moderationType") eq "before") { + $status = "Pending"; + WebGUI::MessageLog::addInternationalizedEntry('',$_[0]->get("groupToModerate"), + WebGUI::URL::page('func=showMessage&wid='.$session{form}{wid}.'&sid=' + .$session{form}{sid}.'&mid='.$session{form}{mid}), + 578,'WebGUI','pending'); + } else { + $status = "Approved"; + } + WebGUI::SQL->write("insert into discussion (messageId, wobjectId, subId, rid, pid, userId, username, status) values + ($session{form}{mid},$session{form}{wid},$session{form}{sid},$rid,$pid,$session{user}{userId}," + .quote($username).", '$status')"); } elsif ($session{setting}{addEditStampToPosts}) { - $session{form}{message} = "\n --- (Edited at ".localtime(time)." by $session{user}{username}) --- \n\n".$session{form}{message}; + $session{form}{message} = "\n --- (Edited at ".localtime(time)." by $session{user}{username}) --- \n\n" + .$session{form}{message}; } WebGUI::SQL->write("update discussion set subject=".quote($session{form}{subject}).", message=".quote($session{form}{message}).", dateOfPost=".time()." where messageId=$session{form}{mid}"); if ($session{setting}{useKarma}) { $u = WebGUI::User->new($session{user}{userId}); - $u->karma($_[0],"Discussion (".$session{form}{wid}."/".$session{form}{sid}.")","Made a post."); + $u->karma($_[0]->get("karmaPerPost"),"Discussion (" + .$session{form}{wid}."/".$session{form}{sid}.")","Made a post."); } return ""; } @@ -263,22 +372,33 @@ sub search { sub showMessage { my (@data, $html, %message, $sqlAdd); tie %message, 'Tie::CPHash'; + if ($session{form}{mid} eq "") { + ($session{form}{mid}) = WebGUI::SQL->quickArray("select min(messageId) from discussion + where wobjectId=$session{form}{wid}"); + } if ($session{form}{sid}) { $sqlAdd = " and subId=$session{form}{sid}"; } if ($session{form}{mid} eq "") { - ($session{form}{mid}) = WebGUI::SQL->quickArray("select min(messageId) from discussion where wobjectId=$session{form}{wid}".$sqlAdd); + ($session{form}{mid}) = WebGUI::SQL->quickArray("select min(messageId) from discussion + where wobjectId=$session{form}{wid}".$sqlAdd); } WebGUI::SQL->write("update discussion set views=views+1 where messageId=$session{form}{mid}"); %message = getMessage($session{form}{mid}); if ($message{messageId}) { $html .= '
| '; - $html .= formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost},$message{views}); + $html .= formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost}, + $message{views},'',$message{status}); $html .= ' | '; $html .= '';
@data = WebGUI::SQL->quickArray("select max(messageId) from discussion
where wobjectId=$message{wobjectId} and pid=0 and messageId<$message{rid}".$sqlAdd);
+ if (canPostReply($_[1],\%message)) {
+ $html .= ''.WebGUI::International::get(577).' '; + } if ($data[0] ne "") { $html .= '« '.WebGUI::International::get(513).' '; @@ -289,6 +409,38 @@ sub showMessage { $html .= ''.WebGUI::International::get(512).' » '; } + if (canEditMessage($_[1],$session{form}{mid})) { + $html .= '' + .WebGUI::International::get(575).' '; + $html .= '' + .WebGUI::International::get(576).' '; + } + if (WebGUI::Privilege::isInGroup($_[1]->get("groupToModerate"))) { + unless ($message{locked}) { + $html .= '' + .WebGUI::International::get(570).' '; + } else { + $html .= '' + .WebGUI::International::get(571).' '; + } + if ($message{status} ne "Approved") { + $html .= ''. + WebGUI::International::get(572).' '; + $html .= ''. + WebGUI::International::get(573).' '; + $html .= ''. + WebGUI::International::get(574).' '; + } + + } + $html .= '' + .WebGUI::International::get(364).' '; $html .= $_[0]; $html .= ' | |||||
| ';
$html .= formatMessage($message{message}).' '; @@ -311,7 +463,7 @@ sub showReplyTree { $html .= ' | ||||||
| '.WebGUI::International::get(229). ' | '.WebGUI::International::get(244). ' | '.WebGUI::International::get(245).' | ||||
| '.substr($data[1],0,30).''; + if ($data[4] == $session{user}{userId}) { + $html .= ' ('.$status{$data[5]}.')'; + } + $html .= ' | '.$data[2]. ' | '. epochToHuman($data[3],"%z %Z").' | ||||
| '; $html .= formatHeader($data{subject},$data{userId},$data{username},$data{dateOfPost},$data{views}, - WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$session{form}{wid})); + WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$session{form}{wid}), + $data{status}); $html .= ' | ||||||
| '.substr($data{subject},0,30). - ' | '.$data{username}. ' | '.epochToHuman($data{dateOfPost},"%z %Z"). ' | ||||
| '; $html .= formatHeader($data{subject},$data{userId},$data{username},$data{dateOfPost},$data{views}, - WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$session{form}{wid})); + WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$session{form}{wid}), + $data{status}); $html .= ' | ||||||
| read("select messageId,subject,username,dateOfPost,userId from discussion where pid=$_[0] order by messageId"); + $sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,status from discussion where pid=$_[0] + and (status='Approved' or userId=$session{user}{userId}) order by messageId"); while (@data = $sth->array) { $data[1] = WebGUI::HTML::filter($data[1],'all'); $html .= ' | ||||||
| '.$data[2].' | '.epochToHuman($data[3],"%z %Z").' | '.$depth.''.substr($data[1],0,30).''; + if ($data[4] == $session{user}{userId}) { + $html .= ' ('.$status{$data[5]}.')'; + } + $html .= ' | ' + .$data[2].' | '.epochToHuman($data[3],"%z %Z").' | '; $html .= traverseReplyTree($data[0],$_[1]+1); } $sth->finish; return $html; } +#------------------------------------------------------------------- +sub unlockThread { + _unlockReplyTree($session{form}{mid}); + WebGUI::SQL->write("update discussion set locked=0 where messageId=$session{form}{mid}"); + return ""; +} + + + 1; diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm index 07a8d48ac..3a6e6d9db 100644 --- a/lib/WebGUI/Wobject.pm +++ b/lib/WebGUI/Wobject.pm @@ -87,6 +87,39 @@ sub description { #------------------------------------------------------------------- +=head2 discussionProperties ( ) + + Returns a formRow list of discussion properties, which may be + attached to any Wobject. + +=cut + +sub discussionProperties { + my ($f,$editTimeout,$groupToModerate,%moderationType,$moderationType); + %moderationType = (before=>WebGUI::International::get(567),after=>WebGUI::International::get(568)); + $f = WebGUI::HTMLForm->new; + if ($_[0]->get("wobjectId") eq "new") { + $editTimeout = 1; + $moderationType = 'after'; + } else { + $editTimeout = $_[0]->get("editTimeout"); + $moderationType = $_[0]->get("moderationType"); + } + $groupToModerate = $_[0]->get("groupToModerate") || 4; + $f->group("groupToPost",WebGUI::International::get(564),[$_[0]->get("groupToPost")]); + $f->integer("editTimeout",WebGUI::International::get(566),$editTimeout); + if ($session{setting}{useKarma}) { + $f->integer("karmaPerPost",WebGUI::International::get(541),$_[0]->get("karmaPerPost")); + } else { + $f->hidden("karmaPerPost",$_[0]->get("karmaPerPost")); + } + $f->group("groupToModerate",WebGUI::International::get(565),[$groupToModerate]); + $f->select("moderationType",\%moderationType,WebGUI::International::get(569),[$moderationType]); + return $f->printRowsOnly; +} + +#------------------------------------------------------------------- + =head2 displayTitle ( ) Returns this instance's title if displayTitle is set to yes. @@ -293,7 +326,7 @@ sub set { $sql = "update wobject set"; foreach $key (keys %{$_[1]}) { $_[0]->{_property}{$key} = ${$_[1]}{$key}; - if (isIn($key, qw(title displayTitle description processMacros pageId templatePosition startDate endDate sequenceNumber))) { + if (isIn($key, qw(moderationType groupToModerate groupToPost karmaPerPost editTimeout title displayTitle description processMacros pageId templatePosition startDate endDate sequenceNumber))) { $sql .= " ".$key."=".quote(${$_[1]}{$key}).","; } if (isIn($key, @{$_[2]})) { @@ -440,7 +473,12 @@ sub www_editSave { templatePosition=>$templatePosition, startDate=>$startDate, endDate=>$endDate, - description=>$session{form}{description} + description=>$session{form}{description}, + karmaPerPost=>$session{form}{karmaPerPost}, + groupToPost=>$session{form}{groupToPost}, + groupToModerate=>$session{form}{groupToModerate}, + editTimeout=>$session{form}{editTimeout}, + moderationType=>$session{form}{moderationType} }); return ""; } diff --git a/lib/WebGUI/Wobject/Article.pm b/lib/WebGUI/Wobject/Article.pm index fa7f011ab..7afe6d325 100644 --- a/lib/WebGUI/Wobject/Article.pm +++ b/lib/WebGUI/Wobject/Article.pm @@ -30,22 +30,6 @@ our $namespace = "Article"; our $name = WebGUI::International::get(1,$namespace); -#------------------------------------------------------------------- -sub _canEditMessage { - my (%message); - tie %message, 'Tie::CPHash'; - %message = WebGUI::Discussion::getMessage($_[1]); - if ( - (time()-$message{dateOfPost}) < 3600*$_[0]->get("editTimeout") - && $message{userId} eq $session{user}{userId} - || WebGUI::Privilege::isInGroup($_[0]->get("groupToModerate")) - ) { - return 1; - } else { - return 0; - } -} - #------------------------------------------------------------------- sub duplicate { my ($file, $w); @@ -62,11 +46,7 @@ sub duplicate { attachment=>$_[0]->get("attachment"), convertCarriageReturns=>$_[0]->get("convertCarriageReturns"), alignImage=>$_[0]->get("alignImage"), - allowDiscussion=>$_[0]->get("allowDiscussion"), - groupToPost=>$_[0]->get("groupToPost"), - groupToModerate=>$_[0]->get("groupToModerate"), - karmaPerPost=>$_[0]->get("karmaPerPost"), - editTimeout=>$_[0]->get("editTimeout") + allowDiscussion=>$_[0]->get("allowDiscussion") }); WebGUI::Discussion::duplicate($_[0]->get("wobjectId"),$w->get("wobjectId")); } @@ -88,8 +68,16 @@ sub purge { #------------------------------------------------------------------- sub set { - $_[0]->SUPER::set($_[1], - [qw(karmaPerPost image linkTitle linkURL attachment convertCarriageReturns alignImage allowDiscussion groupToPost groupToModerate editTimeout)]); + $_[0]->SUPER::set($_[1],[qw(image linkTitle linkURL attachment convertCarriageReturns alignImage allowDiscussion)]); +} + +#------------------------------------------------------------------- +sub www_approvePost { + if (WebGUI::Privilege::isInGroup($_[0]->get("groupToModerate"))) { + return WebGUI::Discussion::approvePost(); + } else { + return WebGUI::Privilege::insufficient(); + } } #------------------------------------------------------------------- @@ -124,7 +112,7 @@ sub www_deleteImage { #------------------------------------------------------------------- sub www_deleteMessage { - if (_canEditMessage($_[0],$session{form}{mid})) { + if (WebGUI::Discussion::canEditMessage($_[0],$session{form}{mid})) { return WebGUI::Discussion::deleteMessage(); } else { return WebGUI::Privilege::insufficient(); @@ -133,13 +121,22 @@ sub www_deleteMessage { #------------------------------------------------------------------- sub www_deleteMessageConfirm { - if (_canEditMessage($_[0],$session{form}{mid})) { + if (WebGUI::Discussion::canEditMessage($_[0],$session{form}{mid})) { return WebGUI::Discussion::deleteMessageConfirm(); } else { return WebGUI::Privilege::insufficient(); } } +#------------------------------------------------------------------- +sub www_denyPost { + if (WebGUI::Privilege::isInGroup($_[0]->get("groupToModerate"))) { + return WebGUI::Discussion::denyPost(); + } else { + return WebGUI::Privilege::insufficient(); + } +} + #------------------------------------------------------------------- sub www_edit { my ($output, $editTimeout, $groupToModerate, %hash, $f); @@ -177,14 +174,7 @@ sub www_edit { $f->yesNo("convertCarriageReturns",WebGUI::International::get(10,$namespace),$_[0]->get("convertCarriageReturns") ,'',' '.WebGUI::International::get(11,$namespace).''); $f->yesNo("allowDiscussion",WebGUI::International::get(18,$namespace),$_[0]->get("allowDiscussion")); - $f->group("groupToPost",WebGUI::International::get(19,$namespace),[$_[0]->get("groupToPost")]); - $f->group("groupToModerate",WebGUI::International::get(20,$namespace),[$groupToModerate]); - $f->integer("editTimeout",WebGUI::International::get(21,$namespace),$editTimeout); - if ($session{setting}{useKarma}) { - $f->integer("karmaPerPost",WebGUI::International::get(541),$_[0]->get("karmaPerPost")); - } else { - $f->hidden("karmaPerPost",$_[0]->get("karmaPerPost")); - } + $f->raw($_[0]->SUPER::discussionProperties); $output .= $_[0]->SUPER::www_edit($f->printRowsOnly); return $output; } else { @@ -208,10 +198,6 @@ sub www_editSave { $property{linkTitle} = $session{form}{linkTitle}; $property{linkURL} = $session{form}{linkURL}; $property{allowDiscussion} = $session{form}{allowDiscussion}; - $property{groupToModerate} = $session{form}{groupToModerate}; - $property{karmaPerPost} = $session{form}{karmaPerPost}; - $property{groupToPost} = $session{form}{groupToPost}; - $property{editTimeout} = $session{form}{editTimeout}; $_[0]->set(\%property); return ""; } else { @@ -219,9 +205,19 @@ sub www_editSave { } } +#------------------------------------------------------------------- +sub www_lockThread { + if (WebGUI::Privilege::isInGroup($_[0]->get("groupToModerate"))) { + WebGUI::Discussion::lockThread(); + return $_[0]->www_showMessage; + } else { + return WebGUI::Privilege::insufficient(); + } +} + #------------------------------------------------------------------- sub www_post { - if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"),$session{user}{userId})) { + if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"))) { return WebGUI::Discussion::post(); } else { return WebGUI::Privilege::insufficient(); @@ -230,8 +226,8 @@ sub www_post { #------------------------------------------------------------------- sub www_postSave { - if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"),$session{user}{userId})) { - WebGUI::Discussion::postSave($_[0]->get("karmaPerPost")); + if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"))) { + WebGUI::Discussion::postSave($_[0]); return $_[0]->www_showMessage(); } else { return WebGUI::Privilege::insufficient(); @@ -243,20 +239,22 @@ sub www_showMessage { my ($submenu, $output, $defaultMid); ($defaultMid) = WebGUI::SQL->quickArray("select min(messageId) from discussion where wobjectId=$session{form}{wid}"); $session{form}{mid} = $defaultMid if ($session{form}{mid} eq ""); - $submenu = ''.WebGUI::International::get(24,$namespace).''.WebGUI::International::get(514).' | '.WebGUI::International::get(19,$namespace).' | '.WebGUI::International::get(20,$namespace).' | '; - $sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,views - from discussion where wobjectId=".$_[0]->get("wobjectId")." and pid=0 order by messageId desc"); + $sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,views,status + from discussion where wobjectId=".$_[0]->get("wobjectId")." and pid=0 + and (status='Approved' or userId=$session{user}{userId}) order by messageId desc"); while (%data = $sth->hash) { $data{subject} = WebGUI::Discussion::formatSubject($data{subject}); if ($i >= ($_[0]->get("messagesPerPage")*$pn) && $i < ($_[0]->get("messagesPerPage")*($pn+1))) { @last = WebGUI::SQL->quickArray("select messageId,dateOfPost,username,subject,userId - from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data{messageId} order by dateOfPost desc"); + from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data{messageId} + and status='Approved' order by dateOfPost desc"); $last[3] = WebGUI::HTML::filter($last[3],'all'); - ($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where rid=$data{messageId}"); + ($replies) = WebGUI::SQL->quickArray("select count(*) from discussion + where rid=$data{messageId} and status='Approved'"); $replies--; $html .= '
| '.substr($data{subject},0,30).' | -'.$data{username}.' | + .'">'.substr($data{subject},0,30).''; + if ($data{userId} == $session{user}{userId}) { + $html .= ' ('.$status{$data{status}}.')'; + } + $html .= ' +' + .$data{username}.' | '.epochToHuman($data{dateOfPost},"%z %Z").' | '.$data{views}.' | '.$replies.' | ' .substr($last[3],0,30).' - @ '.epochToHuman($last[1],"%z %Z").' by '.$last[2].' + @ '.epochToHuman($last[1],"%z %Z").' by '.$last[2].' |