From c575ba511d63afabdb60f7cb4829c50765b0c714 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 18 Oct 2003 16:55:39 +0000 Subject: [PATCH] some cleanup --- docs/upgrades/upgrade_5.4.4-5.5.0.sql | 25 + lib/WebGUI/Discussion.pm | 678 -------------------------- lib/WebGUI/Forum/UI.pm | 42 +- lib/WebGUI/Wobject.pm | 7 +- lib/WebGUI/Wobject/MessageBoard.pm | 69 +-- lib/WebGUI/Wobject/USS.pm | 15 +- 6 files changed, 90 insertions(+), 746 deletions(-) delete mode 100644 lib/WebGUI/Discussion.pm diff --git a/docs/upgrades/upgrade_5.4.4-5.5.0.sql b/docs/upgrades/upgrade_5.4.4-5.5.0.sql index 021fc7fd6..a2fea9627 100644 --- a/docs/upgrades/upgrade_5.4.4-5.5.0.sql +++ b/docs/upgrades/upgrade_5.4.4-5.5.0.sql @@ -236,6 +236,31 @@ INSERT INTO replacements VALUES (12,'[/i]',''); INSERT INTO replacements VALUES (0,NULL,NULL); alter table forum add column masterForumId int; alter table USS_submission add column forumId int; +INSERT INTO template VALUES (1,'Default Message Board','\n

\n
\n\n\n

\n\n\n\n \">

\n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \">
\n \n
\n \">\n by \n \n \n \n \">\n \n on @ \n
\n\n

\n \n
\n
\n

\n \n','MessageBoard'); +delete from template where templateId=1 and namespace='USS/Submission'; +INSERT INTO template VALUES (1,'Default Submission','

\n\n\n
\n: \">
\n:
\n:
\n:
\n
\n\n\n \">«
\n
\n\n \">»
\n
\n\n \">
\n \">
\n
\n\n \">
\n \">
\n
\n\n \">
\n
\n\">
\n\">
\n\n
\n\n \" border=\"0\">

\n\n

\n
\n\n

\n\n','USS/Submission'); +INSERT INTO template VALUES (1,'Default Forum','\n \">\n \n • \n \n \">\n \n \">\n \n \n •\n \">\n

\n\n\n\n\n \n \n \n \n \n \n \n\n\n\n \n \n \n \n \n \n \n \n \n \n \n\n\n
\">\">\">\">\">
\">\"> @ \n \">\n by \n \n \n \n \">\n \n on @ \n
\n\n\n

\n · · \n
\n
\n\n\n\n','Forum'); +INSERT INTO template VALUES (1,'Default Post Form','

\n\n\n\n\n\n \n\n\n\n\n\n\n \n \n \n \n \n \n \n\n\n\n\n\n
\n\n\n

\n\n

','Forum/PostForm'); +INSERT INTO template VALUES (1,'Default Post','

\n\n\n\n\n\n
\n\n\n \n

\n \">\n \n • : [ \">1, \">2, \n \">3, \">4, \">5 ]\n \n \n \n • \">\n • \">\n \n \n • \">\n • \">\n \n\n

\n: @
\n:
\n:
\n:
\n\n :
\n\n : \">
\n
\n
','Forum/Post'); +INSERT INTO template VALUES (1,'Default Thread','
\n\n\n
\n
\n\n \n \">\n \n
style=\"border: 4px dotted #aaaaaa; padding: 5px;\">\n \n
style=\"border: 4px dotted #aaaaaa; padding: 5px;\">\n \n \n
\n \n\n\n\n \n \n \n \n \n \n \n \n
         \n \">\n \n
style=\"border: 4px dotted #aaaaaa; padding: 5px;\">\n \n
style=\"border: 4px dotted #aaaaaa; padding: 5px;\">\n \n \n
\n
\n
\n
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
   \">\"> @
\n
\n\n

\n\"> •\n\"> •\n\"> \n\n • \">\n \n •\n \n \">\n \n \">\n \n \n \n •\n \n \">\n \n \">\n \n •\n \n \">\n \n \">\n \n \n\n\n

\n','Forum/Thread'); +INSERT INTO template VALUES (1,'Default Forum Notification','\n\n','Forum/Notification'); +INSERT INTO template VALUES (1000,'phpBB Forum','\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\">^I(phpBB post);   \" class=\"nav\">Forum IndexMark all topics read
\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n
Topics Replies Author Views Last Post
\r\n \r\n ^I(phpBB folder_sticky);\r\n \r\n \r\n ^I(phpBB folder_locked);\r\n \r\n ^I(phpBB folder);\r\n \r\n \r\n \" class=\"topictitle\">
\r\n
\">
\"> \">^I(phpBB icon_latest_reply);
Display topics from previous: \r\n \r\n
\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\">^I(phpBB post); \" class=\"nav\">Forum Index Goto page \r\n
Page of
\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
^I(phpBB folder_new);New posts ^I(phpBB folder);No new posts ^I(phpBB folder_sticky);Sticky
^I(phpBB folder_lock_new);New posts [ Locked ] ^I(phpBB folder_lock);No new posts [ Locked ]
\r\n You cannot post new topics in this forum
\r\n You cannot reply to topics in this forum
\r\n You cannot edit your posts in this forum
\r\n You cannot delete your posts in this forum
\r\n
\r\n\r\n \r\n \r\n \r\n','Forum'); +INSERT INTO template VALUES (1,'Default Forum Search','\n\n\n \n
\n

\n
\n \n \'\n \n \n \n \n
\n
\n \n
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\">\"> @
\n
\n\n\n
\n · · \n
\n
','Forum/Search'); +delete from international where namespace='MessageBoard' and internationalId=8; +delete from international where namespace='MessageBoard' and internationalId=9; +delete from international where namespace='MessageBoard' and internationalId=7; +delete from international where namespace='MessageBoard' and internationalId=4; +delete from international where namespace='MessageBoard' and internationalId=22; +delete from international where namespace='MessageBoard' and internationalId=18; +delete from international where namespace='MessageBoard' and internationalId=16; +delete from international where namespace='MessageBoard' and internationalId=2; +delete from international where namespace='MessageBoard' and internationalId=15; +delete from international where namespace='MessageBoard' and internationalId=12; +delete from international where namespace='WebGUI' and internationalId=234; +delete from international where namespace='WebGUI' and internationalId=228; +delete from international where namespace='WebGUI' and internationalId=570; +delete from international where namespace='WebGUI' and internationalId=571; +delete from international where namespace='WebGUI' and internationalId=402; diff --git a/lib/WebGUI/Discussion.pm b/lib/WebGUI/Discussion.pm deleted file mode 100644 index 0da08132e..000000000 --- a/lib/WebGUI/Discussion.pm +++ /dev/null @@ -1,678 +0,0 @@ -package WebGUI::Discussion; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2003 Plain Black LLC. -#------------------------------------------------------------------- -# Please read the legal notices (docs/legal.txt) and the license -# (docs/license.txt) that came with this distribution before using -# this software. -#------------------------------------------------------------------- -# http://www.plainblack.com info@plainblack.com -#------------------------------------------------------------------- - -use strict; -use Tie::CPHash; -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; - - - -### NOTE: This package implements WebGUI's discussion system. However it is -### outdated and cludgy. We recommend not coding any new systems against this -### package, but instead wait for the new package that will be created in 6.0.0. - - -#------------------------------------------------------------------- -sub _deleteReplyTree { - 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) { - _deleteReplyTree($data{messageId}); - WebGUI::SQL->write("delete from discussion where messageId=$data{messageId}"); - } - $sth->finish; -} - -#------------------------------------------------------------------- -sub _duplicateReplyTree { - my ($sth, %data, $newMessageId); - tie %data, 'Tie::CPHash'; - $sth = WebGUI::SQL->read("select * from discussion where pid=$_[0] order by messageId"); - while (%data = $sth->hash) { - $newMessageId = getNextId("messageId"); - WebGUI::SQL->write("insert into discussion values ($newMessageId, $_[2], $_[3], $_[1], $data{userId}, " - .quote($data{username}).", ".quote($data{subject}).", ".quote($data{message}). - ", $data{dateOfPost}, $_[4], $data{views}, $data{locked}, ".quote($data{status})." - , ".quote($data{userDefined1}).", ".quote($data{userDefined2}).", ".quote($data{userDefined3})." - , ".quote($data{userDefined4}).", ".quote($data{userDefined5}).")"); - _duplicateReplyTree($data{messageId},$newMessageId,$_[2],$_[3],$_[4]); - } - $sth->finish; -} - -#------------------------------------------------------------------- -sub _isSubscribed { - my ($subscribed) = WebGUI::SQL->quickArray("select count(*) from discussionSubscription - where threadId=$_[1] and userId=$_[0]"); - return $subscribed; -} - - -#------------------------------------------------------------------- -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}) < $_[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); - tie %data, 'Tie::CPHash'; - $oldSubId = $_[2] || 0; - $newSubId = $_[3] || 0; - $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, $data{views}, $data{locked}, - ".quote($data{status}).", ".quote($data{userDefined1}).", ".quote($data{userDefined2})." - , ".quote($data{userDefined3}).", ".quote($data{userDefined4}).", ".quote($data{userDefined5}).")"); - _duplicateReplyTree($data{messageId},$newMessageId,$newMessageId,$_[1],$newSubId); - } - $sth->finish; -} - -#------------------------------------------------------------------- -sub deleteMessage { - my ($output); - $output = '

'.WebGUI::International::get(42).'

'; - $output .= WebGUI::International::get(401); - $output .= '

'; - $output .= '

'; - return $output; -} - -#------------------------------------------------------------------- -sub deleteMessageConfirm { - _deleteReplyTree($session{form}{mid}); - WebGUI::SQL->write("delete from discussion where messageId=$session{form}{mid}"); - return ""; -} - -#------------------------------------------------------------------- -sub formatHeader { - my ($output, $subject); - $subject = $_[0]; - if ($_[5] ne "") { - $subject = ''.$subject.''; - } - $output = ''.WebGUI::International::get(237).' '.$subject.'
' if ($_[0] ne ""); - $output .= ''.WebGUI::International::get(238).' - '.$_[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).": ".status($_[6])."
" if ($_[6]); - return $output; -} - -#------------------------------------------------------------------- -sub formatMessage { - my $output; - $output = WebGUI::HTML::filter($_[0],$_[1]); - $output = WebGUI::HTML::searchAndReplace($output); - unless ($output =~ /\/ig || $output =~ /\/ig || $output =~ /\/ig) { - $output =~ s/\n/\/g; - } - return $output; -} - -#------------------------------------------------------------------- -sub getMessage { - my (%message); - tie %message, 'Tie::CPHash'; - %message = WebGUI::SQL->quickHash("select * from discussion where messageId='$_[0]'"); - 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); - my $signature = "\n\n\n".$session{user}{signature} if ($session{user}{signature} ne ""); - tie %message, 'Tie::CPHash'; - $f = WebGUI::HTMLForm->new; - 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}, - '',$message{status}) - .'

'.formatMessage($message{message},$_[0]->get("filterPost")); - $message{message} = $signature; - $message{subject} = "Re: ".$message{subject} unless ($message{subject} =~ /^Re:/); - $session{form}{mid} = "new"; - $f->hidden("replyTo",$session{form}{replyTo}); - unless (WebGUI::Privilege::isInGroup(1)) { - unless(_isSubscribed($session{user}{userId},$message{rid})) { - $f->yesNo( - -name=>"subscribe", - -value=>0, - -label=>WebGUI::International::get(873) - ); - } - } - 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 (WebGUI::Privilege::isInGroup(1)) { - $f->text("visitorName",WebGUI::International::get(438)); - } else { - $f->yesNo( - -name=>"subscribe", - -value=>1, - -label=>WebGUI::International::get(873) - ); - } - $message{message} = $signature; - } 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}, - '',$message{status}) - .'

'.formatMessage($message{message},$_[0]->get("filterPost")); - } - $f->hidden("func","postSave"); - $f->hidden("wid",$session{form}{wid}); - $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}); - $f->submit; - $html = '

'.$header.'

'; - $html .= $f->print; - $html .= '

'.$footer; - return $html; -} - -#------------------------------------------------------------------- -sub postSave { - my ($u, $rid, $status, $username, $pid); - if ($session{form}{subject} eq "") { - $session{form}{subject} = WebGUI::International::get(232); - } else { - $session{form}{subject} = WebGUI::HTML::filter($session{form}{subject},'all'); - } - if ($session{form}{message} eq "") { - $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 { - $username = $session{form}{visitorName}; - } - } else { - $username = $session{user}{alias}; - } - if ($session{form}{sid} eq "") { - $session{form}{sid} = 0; - } - $session{form}{mid} = getNextId("messageId"); - if ($session{form}{replyTo} ne "") { - ($rid) = WebGUI::SQL->quickArray("select rid from discussion where messageId=$session{form}{replyTo}"); - $pid = $session{form}{replyTo}; - } else { - $rid = $session{form}{mid}; - $pid = 0; - } - 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')"); - my $sth = WebGUI::SQL->read("select userId from discussionSubscription where threadId=$rid"); - while (my ($userId) = $sth->array) { - WebGUI::MessageLog::addInternationalizedEntry($userId,"", - WebGUI::URL::page('func=showMessage&wid='.$session{form}{wid} - .'&sid='.$session{form}{sid}.'&mid='.$session{form}{mid}),875); - } - $sth->finish; - if ($session{form}{subscribe}) { - subscribeToThread($session{user}{userId},$rid); - } - } elsif ($_[0]->get("addEditStampToPosts")) { - $session{form}{message} = "\n --- (".WebGUI::International::get(525,"Discussion")." " - .epochToHuman(time())." ".WebGUI::International::get(526,"Discussion") - ." $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]->get("karmaPerPost"),"Discussion (" - .$session{form}{wid}."/".$session{form}{sid}.")","Made a post."); - } - return ""; -} - -#------------------------------------------------------------------- -sub purge { - WebGUI::SQL->write("delete from discussion where wobjectId=$_[0]"); -} - -#------------------------------------------------------------------- -sub search { - my ($p, $i, $output, $constraints, $sql, $sth, %data, @row, $url); - $output = WebGUI::Search::form({wid=>"$session{form}{wid}",sid=>"$session{form}{sid}",func=>'search'}); - $constraints = WebGUI::Search::buildConstraints([qw(username subject message)]); - if ($constraints ne "") { - tie %data, 'Tie::CPHash'; - $url = WebGUI::URL::page('func=search&wid='.$session{form}{wid}.'&sid='.$session{form}{sid} - .'&all='.WebGUI::URL::escape($session{form}{all}) - .'&exactPhrase='.WebGUI::URL::escape($session{form}{exactPhrase}).'&atLeastOne=' - .WebGUI::URL::escape($session{form}{atLeastOne}).'&numResults='.$session{form}{numResults} - .'&without='.WebGUI::URL::escape($session{form}{without})); - $output .= ''; - $output .= ''; - $sql = "select * from discussion where wobjectId=$session{form}{wid} "; - $sql .= " and subId=$session{form}{sid} " if ($session{form}{sid}); - $sql .= " and ".$constraints." order by dateOfPost desc"; - $sth = WebGUI::SQL->read($sql); - while (%data = $sth->hash) { - $data{subject} = substr(WebGUI::HTML::filter($data{subject},'all'),0,30); - $row[$i] .= ''; - $i++; - } - $sth->finish; - $p = WebGUI::Paginator->new($url,\@row,$session{form}{numResults}); - $output .= $p->getPage($session{form}{pn}); - $output .= '
'.WebGUI::International::get(229). - ''.WebGUI::International::get(244). - ''.WebGUI::International::get(245).'
'.$data{subject}. - ''.$data{username}. - ''.epochToHuman($data{dateOfPost}). - '
'; - $output .= $p->getBarTraditional($session{form}{pn}); - } - return $output; -} - -#------------------------------------------------------------------- -sub showMessage { - my (@data, $html, %message, $sqlAdd); - tie %message, 'Tie::CPHash'; - 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); - } - WebGUI::SQL->write("update discussion set views=views+1 where messageId=$session{form}{mid}"); - %message = getMessage($session{form}{mid}); - if ($message{messageId}) { - $html .= '

'.$message{subject}.'

'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= formatHeader($message{subject},$message{userId},$message{username},$message{dateOfPost}, - $message{views},'',$message{status}); - $html .= ''; - if (canPostReply($_[1],\%message)) { - $html .= ''.WebGUI::International::get(577).'
'; - } - @data = WebGUI::SQL->quickArray("select max(messageId) from discussion - where wobjectId=$message{wobjectId} and pid=0 and messageId<$message{rid} - and (userId=$session{user}{userId} or status='Approved') ".$sqlAdd); - if ($data[0] ne "") { - $html .= '« '.WebGUI::International::get(513).'
'; - } - @data = WebGUI::SQL->quickArray("select min(messageId) from discussion - where wobjectId=$message{wobjectId} and pid=0 and messageId>$message{rid} - and (userId=$session{user}{userId} or status='Approved')".$sqlAdd); - if ($data[0] ne "") { - $html .= ''.WebGUI::International::get(512).' »
'; - } - unless (WebGUI::Privilege::isInGroup(1)) { - if (_isSubscribed($session{user}{userId},$message{rid})) { - $html .= '' - .WebGUI::International::get(874).'
'; - } else { - $html .= '' - .WebGUI::International::get(873).'
'; - } - } - 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},$_[1]->get("filterPost")).'

'; - $html .= '

'; - } else { - $html = WebGUI::International::get(402); - } - return $html; -} - -#------------------------------------------------------------------- -sub showReplyTree { - my (@data, $html, $sql, %message, $sth, %data); - tie %message, 'Tie::CPHash'; - tie %data, 'Tie::CPHash'; - %message = getMessage($session{form}{mid}); - if ($message{messageId}) { - $html .= ''; - if ($session{user}{discussionLayout} eq "threaded") { - $html .= ''; - @data = WebGUI::SQL->quickArray("select messageId,subject,username,dateOfPost,userId,status - from discussion where messageId=$message{rid}"); - $html .= ''.substr($data[1],0,30).''; - if ($data[4] == $session{user}{userId}) { - $html .= ' ('.status($data[5]).')'; - } - $html .= ''; - $html .= traverseReplyTree($message{rid},0); - } else { - $sql = "select * from discussion where rid=$message{rid} and wobjectId=$session{form}{wid}"; - if ($session{form}{sid}) { - $sql .= " and subId=$session{form}{sid}"; - } - $sql .= " and (status='Approved' or userId=$session{user}{userId})"; - $sql .= " order by messageId"; - $sth = WebGUI::SQL->read($sql); - while (%data = $sth->hash) { - unless ($data{messageId} == $session{form}{mid} && $data{messageId} == $data{rid}) { # don't show first message. - $html .= ''; - } - } - $sth->finish; - } - $html .= "
'.WebGUI::International::get(229). - ''.WebGUI::International::get(244). - ''.WebGUI::International::get(245).'
'.$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}), - $data{status}); - $html .= '
get("filterPost")).'

"; - } - return $html; -} - -#------------------------------------------------------------------- -sub showThreads { - my ($sth, %data, $html, $sql); - tie %data, 'Tie::CPHash'; - $sql = "select * from discussion where wobjectId=$session{form}{wid}"; - $sql .= " and subId=$session{form}{sid}" if ($session{form}{sid}); - $sql .= " and (status='Approved' or userId=$session{user}{userId})"; - $html .= ''; - if ($session{user}{discussionLayout} eq "threaded") { - $sql .= " and pid=0 order by dateOfPost desc"; - $sth = WebGUI::SQL->read($sql); - $html .= ' - - ' if ($sth->rows); - while (%data = $sth->hash) { - $data{subject} = WebGUI::HTML::filter($data{subject},'all'); - $html .= ''.substr($data{subject},0,30). - ''; - if ($data{userId} == $session{user}{userId}) { - $html .= ' ('.status($data{status}).')'; - } - $html .= ''; - $html .= WebGUI::Discussion::traverseReplyTree($data{messageId},1); - } - } else { - $sql .= " order by dateOfPost"; - $sth = WebGUI::SQL->read($sql); - while (%data = $sth->hash) { - $html .= ''; - } - } - $html .= '
'.WebGUI::International::get(229).''.WebGUI::International::get(244).''.WebGUI::International::get(245).'
'.$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}), - $data{status}); - $html .= '
get("filterPost")).'

'; - $sth->finish; - return $html; -} - -#------------------------------------------------------------------- -sub status { - if ($_[0] eq "Approved") { - return WebGUI::International::get(560); - } elsif ($_[0] eq "Denied") { - return WebGUI::International::get(561); - } elsif ($_[0] eq "Pending") { - return WebGUI::International::get(562); - } -} - -#------------------------------------------------------------------- -sub subscribeToThread { - my $userId = $_[0] || $session{user}{userId}; - my $threadId = $_[1] || $session{form}{threadId}; - unless (_isSubscribed($userId,$threadId)) { - WebGUI::SQL->write("insert into discussionSubscription (threadId,userId) values ($threadId, $userId)"); - } - return ""; -} - - -#------------------------------------------------------------------- -sub traverseReplyTree { - my ($sth, @data, $html, $depth, $i); - for ($i=0;$i<=$_[1];$i++) { - $depth .= "  "; - } - $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 .= ''.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 ""; -} - - -#------------------------------------------------------------------- -sub unsubscribeFromThread { - if (_isSubscribed($session{user}{userId},$session{form}{threadId})) { - WebGUI::SQL->write("delete from discussionSubscription where - threadId=$session{form}{threadId} and userId=$session{user}{userId}"); - } - return ""; -} - - - -1; diff --git a/lib/WebGUI/Forum/UI.pm b/lib/WebGUI/Forum/UI.pm index 30c2cfbb0..bfb295ad0 100644 --- a/lib/WebGUI/Forum/UI.pm +++ b/lib/WebGUI/Forum/UI.pm @@ -567,11 +567,42 @@ sub recurseThread { return \@post_loop; } +sub setPostApproved { + my ($callback, $post) = @_; + $post->setStatusApproved; + unless ($session{user}{userId} == $post->get("userId")) { + WebGUI::MessageLog::addInternationalizedEntry($post->get("userId"),'',formatThreadURL($callback,$post->get("forumPostId")),579); + } + notifySubscribers($post,$post->getThread,$post->getThread->getForum,$callback); +} + +sub setPostDenied { + my ($callback, $post) = @_; + $post->setStatusDenied; + WebGUI::MessageLog::addInternationalizedEntry($post->get("userId"),'',formatThreadURL($callback,$post->get("forumPostId")),580); +} + +sub setPostPending { + my ($callback, $post) = @_; + $post->setStatusPending; + WebGUI::MessageLog::addInternationalizedEntry('',$post->getThread->getForum->get("groupToModerate"), + formatThreadURL($callback,$post->get("forumPostId")),578,'WebGUI','pending'); +} + +sub setPostStatus { + my ($callback, $post) = @_; + if ($post->getThread->getForum->get("moderatePosts")) { + setPostPending($callback,$post); + } else { + setPostApproved($callback,$post); + } +} + sub www_approvePost { my ($callback) = @_; my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->isModerator); - $post->setStatusApproved; + setPostApproved($callback,$post); return www_viewThread($callback); } @@ -599,7 +630,7 @@ sub www_denyPost { my ($callback) = @_; my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); return WebGUI::Privilege::insufficient() unless ($post->canEdit($session{user}{userId})); - $post->setStatusDenied; + setPostDenied($callback,$post); return www_viewThread($callback); } @@ -745,9 +776,11 @@ sub www_postSave { my $forumId = $session{form}{forumId}; my $threadId = $session{form}{forumThreadId}; my $postId = $session{form}{forumPostId}; + $session{form}{subject} = WebGUI::International::get(232) if ($session{form}{subject} eq ""); + $session{form}{subject} .= ' '.WebGUI::International::get(233) if ($session{form}{message} eq ""); my %postData = ( message=>$session{form}{message}, - subject=>$session{form}{subject}, + subject=>formatSubject($session{form}{subject}), contentType=>$session{form}{contentType} ); my %postDataNew = ( @@ -763,7 +796,7 @@ sub www_postSave { $postData{forumThreadId} = $parentPost->getThread->get("forumThreadId"); $postData{parentId} = $session{form}{parentId}; my $post = WebGUI::Forum::Post->create(\%postData); - notifySubscribers($post,$post->getThread,$post->getThread->getForum,$callback); + setPostStatus($callback,$post); return www_viewThread($callback,$post->get("forumPostId")); } if ($session{form}{forumPostId} > 0) { # edit @@ -787,6 +820,7 @@ sub www_postSave { isLocked=>$session{form}{isLocked} }, \%postData); $thread->subscribe($session{user}{userId}) if ($session{form}{subscribe}); + setPostStatus($callback,$thread->getPost($thread->get("rootPostId"))); return www_viewForum($callback, $forumId); } } diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm index ab4505f66..cb6a5a683 100644 --- a/lib/WebGUI/Wobject.pm +++ b/lib/WebGUI/Wobject.pm @@ -746,8 +746,11 @@ NOTE: This method is meant to be extended by all sub-classes. sub purge { if ($_[0]->get("forumId")) { - my $forum = WebGUI::Forum->new($_[0]->get("forumId")); - $forum->purge; + my ($inUseElsewhere) = WebGUI::SQL->quickArray("select count(*) from wobject where forumId=".$_[0]->get("forumId")); + unless ($inUseElsewhere > 1) { + my $forum = WebGUI::Forum->new($_[0]->get("forumId")); + $forum->purge; + } } WebGUI::SQL->write("delete from ".$_[0]->get("namespace")." where wobjectId=".$_[0]->get("wobjectId")); WebGUI::SQL->write("delete from wobject where wobjectId=".$_[0]->get("wobjectId")); diff --git a/lib/WebGUI/Wobject/MessageBoard.pm b/lib/WebGUI/Wobject/MessageBoard.pm index f8725ab74..fd9c7ab85 100644 --- a/lib/WebGUI/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Wobject/MessageBoard.pm @@ -59,9 +59,12 @@ sub new { sub purge { my $sth = WebGUI::SQL->read("select forumId from MessageBoard_forums where wobjectId=".$_[0]->get("wobjectId")); while (my ($forumId) = $sth->array) { - my $forum = WebGUI::Forum->new($forumId); - $forum->purge; - } + my ($inUseElsewhere) = WebGUI::SQL->quickArray("select count(*) from MessageBoard_forums where forumId=".$forumId); + unless ($inUseElsewhere > 1) { + my $forum = WebGUI::Forum->new($forumId); + $forum->purge; + } + } $sth->finish; WebGUI::SQL->write("delete from MessageBoard_forums where wobjectId=".$_[0]->get("wobjectId")); $_[0]->SUPER::purge(); @@ -77,9 +80,12 @@ sub www_deleteForum { #------------------------------------------------------------------- sub www_deleteForumConfirm { return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); - my $forum = WebGUI::Forum->new($session{form}{forumId}); - $forum->purge; - WebGUI::SQL->write("delete from MessageBoard_forums where forumId=".$session{form}{forumId}); + my ($inUseElsewhere) = WebGUI::SQL->quickArray("select count(*) from MessageBoard_forums where forumId=".$session{form}{forumId}); + unless ($inUseElsewhere > 1) { + my $forum = WebGUI::Forum->new($session{form}{forumId}); + $forum->purge; + } + WebGUI::SQL->write("delete from MessageBoard_forums where forumId=".$session{form}{forumId}." and wobjectId=".$_[0]->get("wobjectId")); return ""; } @@ -209,57 +215,6 @@ sub www_view { $var{areMultipleForums} = ($count > 1); $var{forum_loop} = \@forum_loop; return $_[0]->processTemplate($_[0]->get("templateId"),\%var); - - - my ($p, $data, %var, @message_loop, $rows, @last, $replies); - - $var{canPost} = WebGUI::Privilege::isInGroup($_[0]->get("groupToPost")); - $var{"post.url"} = WebGUI::URL::page('func=post&mid=new&wid='.$_[0]->get("wobjectId")); - $var{"post.label"} = WebGUI::International::get(17,$_[0]->get("namespace")); - $var{"search.url"} = WebGUI::URL::page('func=search&wid='.$_[0]->get("wobjectId")); - $var{"search.label"} = WebGUI::International::get(364); - $var{"subject.label"} = WebGUI::International::get(229); - $var{"user.label"} = WebGUI::International::get(15,$_[0]->get("namespace")); - $var{"date.label"} = WebGUI::International::get(18,$_[0]->get("namespace")); - $var{"views.label"} = WebGUI::International::get(514); - $var{"replies.label"} = WebGUI::International::get(19,$_[0]->get("namespace")); - $var{"last.label"} = WebGUI::International::get(20,$_[0]->get("namespace")); - $p = WebGUI::Paginator->new(WebGUI::URL::page('wid='.$_[0]->get("wobjectId").'&func=view'),[],$_[0]->get("messagesPerPage")); - $p->setDataByQuery("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 dateOfPost desc"); - $rows = $p->getPageData; - foreach $data (@$rows) { - @last = WebGUI::SQL->quickArray("select messageId,dateOfPost,username,subject,userId - from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data->{messageId} - and status='Approved' order by dateOfPost desc"); - ($replies) = WebGUI::SQL->quickArray("select count(*) from discussion - where rid=$data->{messageId} and status='Approved'"); - $replies--; - push (@message_loop,{ - "last.url" => WebGUI::URL::page('func=showMessage&mid='.$last[0].'&wid='.$_[0]->get("wobjectId")), - "last.subject" => substr(WebGUI::HTML::filter($last[3],'all'),0,30), - "last.date" => epochToHuman($last[1]), - "last.userProfile" => WebGUI::URL::page('op=viewProfile&uid='.$last[4]), - "last.username" => $last[2], - "message.replies" => $replies, - "message.url" => WebGUI::URL::page('func=showMessage&mid='.$data->{messageId}.'&wid='.$_[0]->get("wobjectId")), - "message.subject" => substr($data->{subject},0,30), - "message.currentUser" => ($data->{userId} == $session{user}{userId}), - "message.status" => status($data->{status}), - "message.userProfile" => WebGUI::URL::page('op=viewProfile&uid='.$data->{userId}), - "message.username" => $data->{username}, - "message.date" => epochToHuman($data->{dateOfPost}), - "message.views" => $data->{views} - }); - } - $var{message_loop} = \@message_loop; - $var{firstPage} = $p->getFirstPageLink; - $var{lastPage} = $p->getLastPageLink; - $var{nextPage} = $p->getNextPageLink; - $var{pageList} = $p->getPageLinks; - $var{previousPage} = $p->getPreviousPageLink; - $var{multiplePages} = ($p->getNumberOfPages > 1); } 1; diff --git a/lib/WebGUI/Wobject/USS.pm b/lib/WebGUI/Wobject/USS.pm index dea034b97..047604e30 100644 --- a/lib/WebGUI/Wobject/USS.pm +++ b/lib/WebGUI/Wobject/USS.pm @@ -73,7 +73,6 @@ sub duplicate { quote($row{title}).", $row{dateSubmitted}, ".quote($row{username}).", '$row{userId}', ".quote($row{content}).", ". quote($row{image}).", ".quote($row{attachment}).", '$row{status}', '$row{convertCarriageReturns}', '$row{views}')"); - WebGUI::Discussion::duplicate($_[0]->get("wobjectId"),$w,$row{USS_submissionId},$newSubmissionId); } $sth->finish; } @@ -122,8 +121,11 @@ sub new { sub purge { my $sth = WebGUI::SQL->read("select forumId from USS_submission where wobjectId=".$_[0]->get("wobjectId")); while (my ($forumId) = $sth->array) { - my $forum = WebGUI::Forum->new($forumId); - $forum->purge; + my ($inUseElsewhere) = WebGUI::SQL->quickArray("select count(*) from USS_submission where forumId=".$forumId); + unless ($inUseElsewhere > 1) { + my $forum = WebGUI::Forum->new($forumId); + $forum->purge; + } } $sth->finish; WebGUI::SQL->write("delete from USS_submission where wobjectId=".$_[0]->get("wobjectId")); @@ -186,8 +188,11 @@ sub www_deleteSubmission { sub www_deleteSubmissionConfirm { my ($owner, $forumId) = WebGUI::SQL->quickArray("select userId,forumId from USS_submission where USS_submissionId=$session{form}{sid}"); if ($owner == $session{user}{userId} || WebGUI::Privilege::isInGroup($_[0]->get("groupToApprove"))) { - my $forum = WebGUI::Forum->new($forumId); - $forum->purge; + my ($inUseElsewhere) = WebGUI::SQL->quickArray("select count(*) from USS_submission where forumId=".$forumId); + unless ($inUseElsewhere > 1) { + my $forum = WebGUI::Forum->new($forumId); + $forum->purge; + } $_[0]->deleteCollateral("USS_submission","USS_submissionId",$session{form}{sid}); my $file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{sid}); $file->deleteNode;