diff --git a/docs/upgrades/upgrade_6.2.11-6.3.0.pl b/docs/upgrades/upgrade_6.2.11-6.3.0.pl index 6e2259503..c66437d1f 100644 --- a/docs/upgrades/upgrade_6.2.11-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.11-6.3.0.pl @@ -6,6 +6,7 @@ use File::Path; use File::Copy; use Getopt::Long; use strict; +use WebGUI::Group; use WebGUI::HTML; use WebGUI::Id; use WebGUI::Session; @@ -46,6 +47,15 @@ foreach my $key (%threadTemplates) { WebGUI::SQL::write("insert into template (templateId, namespace, template, name) values (".quote(WebGUI::Id::generate()).", 'Forum/Thread', ".quote($threadTemplates{$key}).", ".quote($key).")"); } +WebGUI::SQL->write("update template set templateId='25' where templateId='1' and namespace in ('Forum','Forum/Thread','Forum/PostForm')"); +WebGUI::SQL->write("update forum set forumTemplateId='25' where forumTemplateId='1'"); +WebGUI::SQL->write("update forum set postFormTemplateId='25' where postFormTemplateId='1'"); +WebGUI::SQL->write("update forum set threadTemplateId='25' where threadTemplateId='1'"); +WebGUI::SQL->write("update template set templateId=concat('NNN',templateId) where templateId like '10%' and namespace in ('Forum','Forum/Thread','Forum/PostForm')"); +WebGUI::SQL->write("update forum set forumTemplateId=concat('NNN',forumTemplateId) where forumTemplateId like '10%'"); +WebGUI::SQL->write("update forum set postFormTemplateId=concat('NNN',postFormTemplateId) where postFormTemplateId like '10%'"); +WebGUI::SQL->write("update forum set threadTemplateId=concat('NNN',threadTemplateId) where threadTemplateId like '10%'"); + print "\tFixing navigation template variables.\n" unless ($quiet); @@ -79,7 +89,7 @@ WebGUI::SQL->write("delete from settings where name in ('siteicon','favicon')"); print "\tMigrating wobject templates to asset templates.\n" unless ($quiet); my $sth = WebGUI::SQL->read("select templateId, template, namespace from template where namespace in ('Article', - 'USS', 'SyndicatedContent', 'MessageBoard', 'DataForm', 'EventsCalendar', 'HttpProxy', 'Poll', 'Product', 'WobjectProxy', + 'SyndicatedContent', 'MessageBoard', 'DataForm', 'EventsCalendar', 'HttpProxy', 'Poll', 'Product', 'WobjectProxy', 'IndexedSearch', 'SQLReport', 'Survey', 'WSClient')"); while (my $t = $sth->hashRef) { $t->{template} = ' @@ -211,17 +221,6 @@ WebGUI::SQL->write("alter table DataForm_entry drop column wobjectId"); WebGUI::SQL->write("alter table DataForm_entryData drop column wobjectId"); WebGUI::SQL->write("alter table DataForm_field drop column wobjectId"); WebGUI::SQL->write("alter table DataForm_tab drop column wobjectId"); -WebGUI::SQL->write("alter table USS_submission drop column forumId"); -WebGUI::SQL->write("alter table USS_submission drop column sequenceNumber"); -WebGUI::SQL->write("alter table USS_submission drop column startDate"); -WebGUI::SQL->write("alter table USS_submission drop column title"); -WebGUI::SQL->write("alter table USS_submission drop column USS_id"); -WebGUI::SQL->write("alter table USS_submission drop column endDate"); -WebGUI::SQL->write("alter table USS_submission drop column USS_submissionId"); -WebGUI::SQL->write("alter table USS_submission drop column pageId"); -WebGUI::SQL->write("alter table USS_submission drop column image"); -WebGUI::SQL->write("alter table USS_submission drop column attachment"); -WebGUI::SQL->write("alter table USS_submission add primary key (assetId)"); WebGUI::SQL->write("alter table Product_accessory drop column wobjectId"); WebGUI::SQL->write("alter table Product_benefit drop column wobjectId"); WebGUI::SQL->write("alter table Product_feature drop column wobjectId"); @@ -238,6 +237,8 @@ WebGUI::SQL->write("drop table forumSubscription"); WebGUI::SQL->write("drop table forumThread"); WebGUI::SQL->write("drop table forumThreadSubscription"); WebGUI::SQL->write("drop table MessageBoard_forums"); +WebGUI::SQL->write("drop table USS"); +WebGUI::SQL->write("drop table USS_submission"); # start migrating non-wobject stuff into assets my %migration; @@ -574,7 +575,7 @@ WebGUI::SQL->write("alter table template drop primary key"); WebGUI::SQL->write("alter table template drop column templateId"); WebGUI::SQL->write("alter table template drop column name"); WebGUI::SQL->write("alter table template add primary key (assetId)"); -my @wobjectTypes = qw(Article Poll Survey USS WSClient DataForm Layout EventsCalendar Navigation HttpProxy IndexedSearch MessageBoard Product SQLReport SyndicatedContent Shortcut); +my @wobjectTypes = qw(Article Poll Survey WSClient DataForm Layout EventsCalendar Navigation HttpProxy IndexedSearch MessageBoard Product SQLReport SyndicatedContent Shortcut); my @allWobjectTypes = (@wobjectTypes,@otherWobjects); print "\t\tMigrating wobject templates to new IDs\n" unless ($quiet); foreach my $type (@allWobjectTypes) { @@ -609,13 +610,16 @@ while (my ($assetId, $emailId, $ackId, $listId) = $sth->array) { }); } $sth->finish; -print "\t\tMigrating USS templates to new IDs\n" unless ($quiet); -my $sth = WebGUI::SQL->read("select assetId, submissionTemplateId, submissionFormTemplateId from USS"); -while (my ($assetId, $subId, $formId) = $sth->array) { - WebGUI::SQL->setRow("USS","assetId",{ +print "\t\tMigrating Collaboration templates to new IDs\n" unless ($quiet); +my $sth = WebGUI::SQL->read("select assetId, collaborationTemplateId, postFormTemplateId, threadTemplateId, searchTemplateId, notificationTemplateId from Collaboration"); +while (my ($assetId, $collabId, $formId, $threadId, $searchId, $notId) = $sth->array) { + WebGUI::SQL->setRow("Collaboration","assetId",{ assetId=>$assetId, - submissionTemplateId=>$templateCache{"USS/Submission"}{$subId}, - submissionFormTemplateId=>$templateCache{"USS/SubmissionForm"}{$formId} + collaborationTemplateId=>$templateCache{"Collaboration"}{$collabId}, + searchTemplateId=>$templateCache{"Collaboration/Search"}{$searchId}, + threadTemplateId=>$templateCache{"Collaboration/Thread"}{$threadId}, + notificationTemplateId=>$templateCache{"Collaboration/Notification"}{$notId}, + postFormTemplateId=>$templateCache{"Collaboration/PostForm"}{$formId} }); } print "\t\tMigrating Shortcut templates to new IDs\n" unless ($quiet); @@ -1130,7 +1134,7 @@ sub walkTree { print "\t\t\tConverting File Manager ".$wobject->{wobjectId}." into File Folder Layout\n" unless ($quiet); WebGUI::SQL->write("update asset set className='WebGUI::Asset::Layout' where assetId=".quote($wobjectId)); WebGUI::SQL->write("insert into Layout (assetId,templateId) values (".quote($wobjectId).", '15')"); - WebGUI::SQL->write("update wobject set namespace='Layout' where wobjectId=".quote($wobjectId)); + WebGUI::SQL->write("update wobject set namespace='Layout' where wobjectId=".quote($wobject->{wobjectId})); print "\t\t\tMigrating attachments for File Manager ".$wobject->{wobjectId}."\n" unless ($quiet); my $sth = WebGUI::SQL->read("select * from FileManager_file where wobjectId=".quote($wobjectId)." order by sequenceNumber"); my $rank = 1; @@ -1205,17 +1209,50 @@ sub walkTree { WebGUI::SQL->write("update $table set assetId=".quote($wobjectId)." where wobjectId=".quote($wobject->{wobjectId})); } } elsif ($wobject->{namespace} eq "USS") { + print "\t\t\tConverting USS to collaboration system ".$wobject->{wobjectId}."\n" unless ($quiet); + WebGUI::SQL->write("update asset set className='WebGUI::Asset::Wobject::Collaboration' where assetId=".quote($wobjectId)); + my $moderate = ($namespace->{defaultStatus} eq 'Approved') ? 0 : 1; + my $master = WebGUI::SQL->quickHashRef("select * from forum where forumId=".quote($wobject->{forumId})); + my $sg = WebGUI::Group->new("new"); + $sg->description("The group to store subscriptions for the collaboration system $wobjectId"); + $sg->name($wobjectId); + $sg->showInForms(0); + $sg->isEditable(0); + $sg->deleteGroups(['3']); + WebGUI::SQL->write("insert into Collaboration (assetId,postGroupId,moderateGroupId,moderatePosts,karmaPerPost, + collaborationTemplateId, threadTemplateId, postFormTemplateId, searchTemplateId, notificationTemplateId, + sortBy, sortOrder, usePreview, addEditStampToPosts, editTimeout, attachmentsPerPost, allowRichEdit, filterCode, + useContentFilter, rating, archiveAfter, postsPerPage, threadsPerPage, subscriptionGroupId, + allowReplies) values (".quote($wobjectId).", ".quote($namespace->{groupToContribute}).", + ".quote($namespace->{groupToApprove}).", $moderate, ".quote($namespace->{karmaPerSubmission}).", + ".quote($wobject->{templateId}).", ".quote($namespace->{submissionTemplateId}).", + ".quote($namespace->{submissionFormTemplateId}).", ".quote($master->{searchTemplateId}||1).", + ".quote($master->{notificationTemplateId}||1)." , ".quote($namespace->{sortBy}).", + ".quote($namespace->{sortOrder}).", 0, 0, 931536000, 2, 1, ".quote($namespace->{filterContent}).", + 0, 0, ".quote($master->{archiveAfter}||31536000).", ".quote($master->{postsPerPage}||10).", + ".quote($namespace->{submissionsPerPage}).", ".quote($sg->groupId).", + ".quote($wobject->{allowDiscussion}).")"); + #count threads, views, replies + #find last post + WebGUI::SQL->write("update wobject set namespace='Collaboration' where wobjectId=".quote($wobject->{wobjectId})); print "\t\t\tMigrating submissions for USS ".$wobject->{wobjectId}."\n" unless ($quiet); - my ($ussId) = WebGUI::SQL->quickArray("select USS_id from USS where wobjectId=".quote($wobject->{wobjectId})); + my $ussId = $namespace->{USS_id}; my $sth = WebGUI::SQL->read("select * from USS_submission where USS_id=".quote($ussId)); my $usssubrank = 1; + my $collabReplyCounter; + my $collabViewCounter; + my $collabThreadCounter; + my %oldestForumPost; while (my $submission = $sth->hashRef) { + $collabThreadCounter++; + $collabViewCounter += $submission->{views}; print "\t\t\t\tMigrating submission ".$submission->{USS_submissionId}."\n" unless ($quiet); my $body = $submission->{content}; $body =~ s/\n/\^\-\;/ unless ($body =~ m/\^\-\;/); my @content = split(/\^\-\;/,$body); $content[0] = WebGUI::HTML::filter($content[0],"none"); $body =~ s/\^\-\;/\n/; + my $threadLineage = $wobjectLineage.sprintf("%06d",$usssubrank); my $id = WebGUI::SQL->setRow("asset","assetId",{ assetId => "new", title => $submission->{title}, @@ -1231,15 +1268,98 @@ sub walkTree { synopsis=>$content[0], assetSize=>length($submission->{content}), parentId=>$wobjectId, - lineage=>$wobjectLineage.sprintf("%06d",$usssubrank), + lineage=>$threadLineage, isHidden => 1 }); - WebGUI::SQL->write("update USS_submission set content=".quote($body).", - assetId=".quote($id)." where USS_submissionId=".quote($submission->{USS_submissionId})); + WebGUI::SQL->setRow("Post","assetId",{ + assetId=>$id, + threadId=>$id, + dateSubmitted=>$submission->{dateSubmitted}, + dateUpdated=>$submission->{dateUpdated}, + username=>$submission->{username}, + content=>$body, + status=>lc($submission->{status}), + views=>$submission->{views}, + contentType=>$submission->{contentType}, + rating=>0 + },undef,$id); + my $threadSubscriptionGroup = WebGUI::Group->new("new"); + $threadSubscriptionGroup->description("The group to store subscriptions for the thread $id"); + $threadSubscriptionGroup->name($id); + $threadSubscriptionGroup->showInForms(0); + $threadSubscriptionGroup->isEditable(0); + $threadSubscriptionGroup->deleteGroups(['3']); + WebGUI::SQL->setRow("Thread","assetId",{ + assetId=>$id, + isLocked=>0, + isSticky=>0, + subscriptionGroupId=>$threadSubscriptionGroup->groupId + }, undef, $id); + my %oldestThreadPost; + my $posts = WebGUI::SQL->read("select forumPost.* from forumPost left join forumThread on forumPost.forumThreadId=forumThread.forumThreadId where forumId=".quote($submission->{forumId})); + my $postRank = 1; + my $threadReplyCounter; + while (my $post = $posts->hashRef) { + $collabViewCounter += $post->{views}; + $threadReplyCounter++; + my $postId = WebGUI::SQL->setRow("asset","assetId",{ + assetId=>"new", + parentId=>$id, + lineage=>$threadLineage.sprintf("%06d",$postRank), + state=>'published', + className=>'WebGUI::Asset::Post', + title=>$post->{subject}, + menuTitle=>$post->{subject}, + url=>fixUrl("noneyet",$wobject->{title}.'/'.$submission->{title}.'/'.$post->{subject}), + startDate=>$submission->{startDate}, + endDate=>$submission->{endDate}, + ownerUserId=>$post->{userId}, + groupIdView=>$page->{groupIdView}, + groupIdEdit=>$page->{groupIdEdit}, + isHidden=>1, + lastUpdated=>$post->{dateOfPost}, + lastUpdatedBy=>$post->{userId} + }); + if ($oldestThreadPost{date} < $post->{dateOfPost}) { + $oldestThreadPost{date} = $post->{dateOfPost}; + $oldestThreadPost{id} = $postId; + } + WebGUI::SQL->setRow("Post","assetId",{ + assetId=>$postId, + threadId=>$id, + dateSubmitted=>$post->{dateOfPost}, + dateUpdated=>$post->{dateOfPost}, + username=>$post->{username}, + content=>$post->{message}, + status=>$post->{status}, + views=>$post->{views}, + contentType=>$post->{contentType}, + rating=>$post->{rating} + },undef,$postId); + $postRank++; + } + $posts->finish; + WebGUI::SQL->setRow("Thread","assetId",{ + assetId=>$id, + lastPostId=>$oldestThreadPost{id}, + lastPostDate=>$oldestThreadPost{date}, + replies=>$threadReplyCounter + }); $usssubrank++; + $collabReplyCounter += $threadReplyCounter; + if ($oldestForumPost{date} < $oldestThreadPost{date}) { + $oldestForumPost{date} = $oldestThreadPost{date}; + $oldestForumPost{id} = $oldestThreadPost{id}; + } } - # migrate master forum - # migrate submission forums + WebGUI::SQL->setRow("Collaboration","assetId",{ + assetId=>$wobjectId, + lastPostId=>$oldestForumPost{id}, + lastPostDate=>$oldestForumPost{date}, + replies=>$collabReplyCounter, + views=>$collabViewCounter, + threads=>$collabThreadCounter + }); # migrate submission attachments # migrate submission images } elsif ($wobject->{namespace} eq "WobjectProxy") { @@ -1601,7 +1721,7 @@ sub getNewId { 'Operation/MessageLog/View' => { '1' => 'PBtmpl0000000000000050' }, - 'Forum/Search' => { + 'Collaboration/Search' => { '1' => 'PBtmpl0000000000000031' }, 'Auth/WebGUI/Account' => { @@ -1613,9 +1733,6 @@ sub getNewId { 'Operation/Profile/View' => { '1' => 'PBtmpl0000000000000052' }, - 'Forum/PostForm' => { - '1' => 'PBtmpl0000000000000029' - }, 'Operation/RedeemSubscription' => { '1' => 'PBtmpl0000000000000053' }, @@ -1650,9 +1767,6 @@ sub getNewId { 'AttachmentBox' => { '1' => 'PBtmpl0000000000000003' }, - 'Forum' => { - '1' => 'PBtmpl0000000000000026' - }, 'Poll' => { '1' => 'PBtmpl0000000000000055' }, @@ -1728,7 +1842,8 @@ sub getNewId { 'Macro/H_homeLink' => { '1' => 'PBtmpl0000000000000042' }, - 'USS' => { + 'Collaboration' => { + '25' => 'PBtmpl0000000000000026', '6' => 'PBtmpl0000000000000133', '21' => 'PBtmpl0000000000000102', '3' => 'PBtmpl0000000000000112', @@ -1740,7 +1855,6 @@ sub getNewId { '4' => 'PBtmpl0000000000000121', '1' => 'PBtmpl0000000000000066', '18' => 'PBtmpl0000000000000082', - '1000' => 'PBtmpl0000000000000074', '16' => 'PBtmpl0000000000000080', '19' => 'PBtmpl0000000000000083', '5' => 'PBtmpl0000000000000128' @@ -1807,7 +1921,8 @@ sub getNewId { 'Commerce/CheckoutCanceled' => { '1' => 'PBtmpl0000000000000015' }, - 'USS/Submission' => { + 'Collaboration/Thread' => { + '25' => 'PBtmpl0000000000000032', '1' => 'PBtmpl0000000000000067', '3' => 'PBtmpl0000000000000113', '2' => 'PBtmpl0000000000000098' @@ -1824,7 +1939,8 @@ sub getNewId { 'SyndicatedContent' => { '1' => 'PBtmpl0000000000000065' }, - 'USS/SubmissionForm' => { + 'Collaboration/PostForm' => { + '25' => 'PBtmpl0000000000000029', '4' => 'PBtmpl0000000000000122', '1' => 'PBtmpl0000000000000068', '3' => 'PBtmpl0000000000000114', @@ -1836,7 +1952,7 @@ sub getNewId { 'Macro/GroupAdd' => { '1' => 'PBtmpl0000000000000040' }, - 'Forum/Notification' => { + 'Collaboration/Notification' => { '1' => 'PBtmpl0000000000000027' }, 'Auth/LDAP/Login' => { @@ -1855,12 +1971,6 @@ sub getNewId { 'tinymce' => 'PBtmpl0000000000000138', '5' => 'PBtmpl0000000000000126' }, - 'Forum/Thread' => { - '1' => 'PBtmpl0000000000000032' - }, - 'Forum/Post' => { - '1' => 'PBtmpl0000000000000028' - }, 'Macro/EditableToggle' => { '1' => 'PBtmpl0000000000000038' }, diff --git a/lib/WebGUI/Asset/Wobject/USS.pm b/lib/WebGUI/Asset/Wobject/USS.pm deleted file mode 100644 index b361ba4e5..000000000 --- a/lib/WebGUI/Asset/Wobject/USS.pm +++ /dev/null @@ -1,446 +0,0 @@ -package WebGUI::Asset::Wobject::USS; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2005 Plain Black Corporation. -#------------------------------------------------------------------- -# 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::Grouping; -use WebGUI::HTML; -use WebGUI::HTTP; -use WebGUI::Icon; -use WebGUI::International; -use WebGUI::Paginator; -use WebGUI::Privilege; -use WebGUI::Search; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::Style; -use WebGUI::URL; -use WebGUI::Utility; -use WebGUI::Asset::Wobject; -use WebGUI::Asset::USS_submission; - -our @ISA = qw(WebGUI::Asset::Wobject); - -#------------------------------------------------------------------- -sub definition { - my $class = shift; - my $definition = shift; - push(@{$definition}, { - tableName=>'USS', - className=>'WebGUI::Asset::Wobject::USS', - properties=>{ - templateId =>{ - fieldType=>"template", - defaultValue=>'PBtmpl0000000000000066' - }, - submissionsPerPage=>{ - fieldType=>"integer", - defaultValue=>50 - }, - groupToContribute=>{ - fieldType=>"group", - defaultValue=>2 - }, - groupToApprove=>{ - fieldType=>"group", - defaultValue=>4 - }, - defaultStatus=>{ - fieldType=>"selectList", - defaultValue=>"Approved" - }, - submissionTemplateId=>{ - fieldType=>"template", - defaultValue=>undef - }, - submissionFormTemplateId=>{ - fieldType=>"template", - defaultValue=>undef - }, - karmaPerSubmission=>{ - fieldType=>"integer", - defaultValue=>0 - }, - filterContent=>{ - fieldType=>"filterContent", - defaultValue=>"javascript" - }, - sortBy=>{ - fieldType=>"selectList", - defaultValue=>"dateUpdated" - }, - sortOrder=>{ - fieldType=>"selectList", - defaultValue=>"desc" - }, - USS_id=>{ - fieldType=>"hidden", - autoId=>1 - }, - submissionFormTemplateId=>{ - fieldType=>"template", - defaultValue=>undef - } - } - }); - return $class->SUPER::definition($definition); -} - -#------------------------------------------------------------------- -sub getEditForm { - my $self = shift; - my $tabform = $self->SUPER::getEditForm; - $tabform->getTab("display")->template( - -value=>$self->getValue('templateId'), - -namespace=>"USS" - ); - $tabform->getTab("display")->template( - -name=>"submissionTemplateId", - -value=>$self->getValue("submissionTemplateId"), - -namespace=>"USS"."/Submission", - -label=>WebGUI::International::get(73,"USS"), - -afterEdit=>'func=edit&wid='.$self->get("wobjectId") - ); - $tabform->getTab("display")->template( - -name=>"submissionFormTemplateId", - -value=>$self->getValue("submissionFormTemplateId"), - -namespace=>"USS"."/SubmissionForm", - -label=>WebGUI::International::get(87,"USS"), - -afterEdit=>'func=edit&wid='.$self->get("wobjectId") - ); - $tabform->getTab("security")->group( - -name=>"groupToApprove", - -label=>WebGUI::International::get(1,"USS"), - -value=>[$self->getValue("groupToApprove")] - ); - $tabform->getTab("security")->group( - -name=>"groupToContribute", - -label=>WebGUI::International::get(2,"USS"), - -value=>[$self->getValue("groupToContribute")] - ); - $tabform->getTab("display")->integer( - -name=>"submissionsPerPage", - -label=>WebGUI::International::get(6,"USS"), - -value=>$self->getValue("submissionsPerPage") - ); - $tabform->getTab("security")->selectList( - -name=>"defaultStatus", - -options=>{ - Approved=>$self->status('Approved'), - Denied=>$self->status('Denied'), - Pending=>$self->status('Pending') - }, - -label=>WebGUI::International::get(563), - -value=>[$self->getValue("defaultStatus")] - ); - if ($session{setting}{useKarma}) { - $tabform->getTab("properties")->integer( - -name=>"karmaPerSubmission", - -label=>WebGUI::International::get(30,"USS"), - -value=>$self->getValue("karmaPerSubmission") - ); - } else { - $tabform->getTab("properties")->hidden("karmaPerSubmission",$self->getValue("karmaPerSubmission")); - } - $tabform->getTab("display")->filterContent( - -value=>$self->getValue("filterContent") - ); - $tabform->getTab("display")->selectList( - -name=>"sortBy", - -value=>[$self->getValue("sortBy")], - -options=>{ - lineage=>WebGUI::International::get(88,"USS"), - dateUpdated=>WebGUI::International::get(78,"USS"), - dateSubmitted=>WebGUI::International::get(13,"USS"), - title=>WebGUI::International::get(35,"USS") - }, - -label=>WebGUI::International::get(79,"USS") - ); - $tabform->getTab("display")->selectList( - -name=>"sortOrder", - -value=>[$self->getValue("sortOrder")], - -options=>{ - asc=>WebGUI::International::get(81,"USS"), - desc=>WebGUI::International::get(82,"USS") - }, - -label=>WebGUI::International::get(80,"USS") - ); - return $tabform; -} - -#------------------------------------------------------------------- -sub getIcon { - my $self = shift; - my $small = shift; - return $session{config}{extrasURL}.'/assets/small/userSubmissionSystem.gif' if ($small); - return $session{config}{extrasURL}.'/assets/userSubmissionSystem.gif'; -} - -#------------------------------------------------------------------- -sub getIndexerParams { - my $self = shift; - my $now = shift; - return { - USS_discussion => { - sql => "select forumPost.forumPostId, - forumPost.username, - forumPost.subject, - forumPost.message, - forumPost.userId as ownerId, - forumThread.forumId as forumId, - USS_submission.USS_submissionId as sid, - wobject.namespace as namespace, - wobject.wobjectId as wid, - page.urlizedTitle as urlizedTitle, - page.languageId as languageId, - page.pageId as pageId, - page.groupIdView as page_groupIdView, - wobject.groupIdView as wobject_groupIdView, - 7 as wobject_special_groupIdView - from forumPost, forumThread, USS_submission, wobject, page, USS - where forumPost.forumThreadId = forumThread.forumThreadId - and forumThread.forumId = USS_submission.forumId - and USS_submission.USS_id = USS.USS_id - and USS.wobjectId = wobject.wobjectId - and wobject.pageId = page.pageId - and wobject.startDate < $now - and wobject.endDate > $now - and page.startDate < $now - and page.endDate > $now", - fieldsToIndex => ["username", "subject", "message"], - contentType => 'discussion', - url => 'WebGUI::URL::append($data{urlizedTitle},"func=viewSubmission&wid=$data{wid}&sid=$data{sid}&forumOp=viewThread&forumPostId=$data{forumPostId}&forumId=$data{forumId}")', - headerShortcut => 'select subject from forumPost where forumPostId = \'$data{forumPostId}\'', - bodyShortcut => 'select message from forumPost where forumPostId = \'$data{forumPostId}\'', - }, - USS_submission => { - sql => "select USS_submission.title as title, - USS_submission.username as username, - USS_submission.content as content, - USS_submission.image as image, - USS_submission.attachment as attachment, - USS.wobjectId as wid, - USS_submission.USS_submissionId as sid, - USS_submission.userId as ownerId, - wobject.namespace as namespace, - page.urlizedTitle as urlizedTitle, - page.languageId as languageId, - page.pageId as pageId, - page.groupIdView as page_groupIdView, - wobject.groupIdView as wobject_groupIdView, - 7 as wobject_special_groupIdView - from wobject, page, USS_submission, USS - where USS_submission.USS_id = USS.USS_id - and USS.wobjectId = wobject.wobjectId - and wobject.pageId = page.pageId - and USS_submission.status = 'Approved' - and wobject.startDate < $now - and wobject.endDate > $now - and page.startDate < $now - and page.endDate > $now", - fieldsToIndex => ["username", "title", "content", "image", "attachment"], - contentType => 'wobjectDetail', - url => 'WebGUI::URL::append($data{urlizedTitle}, "func=viewSubmission&wid=$data{wid}&sid=$data{sid}")', - headerShortcut => 'select title from USS_submission where USS_submissionId = \'$data{sid}\'', - bodyShortcut => 'select content from USS_submission where USS_submissionId = \'$data{sid}\'', - } - }; -} - -#------------------------------------------------------------------- -sub getName { - return WebGUI::International::get(29,"USS"); -} - - -#------------------------------------------------------------------- -sub status { - my $self = shift; - my $status = shift; - if ($status eq "Approved") { - return WebGUI::International::get(560); - } elsif ($status eq "Denied") { - return WebGUI::International::get(561); - } elsif ($status eq "Pending") { - return WebGUI::International::get(562); - } -} - -#------------------------------------------------------------------- -sub view { - my $self = shift; - my $numResults = $self->get("submissionsPerPage"); - my %var; - $var{"readmore.label"} = WebGUI::International::get(46,"USS"); - $var{"responses.label"} = WebGUI::International::get(57,"USS"); - $var{canPost} = WebGUI::Grouping::isInGroup($self->get("groupToContribute")); - $var{"post.url"} = $self->getUrl('func=add&class=WebGUI::Asset::USS_submission'); - $var{"post.label"} = WebGUI::International::get(20,"USS"); - $var{"addquestion.label"} = WebGUI::International::get(83,"USS"); - $var{"addlink.label"} = WebGUI::International::get(89,"USS"); - $var{"search.label"} = WebGUI::International::get(364); - $var{"search.Form"} = WebGUI::Search::form({func=>'view',search=>1}); - $var{"search.url"} = WebGUI::Search::toggleURL("func=view"); - $var{"rss.url"} = WebGUI::URL::page('func=viewRSS',1); - $var{canModerate} = WebGUI::Grouping::isInGroup($self->get("groupToApprove"),$session{user}{userId}); - $var{"title.label"} = WebGUI::International::get(99); - $var{"thumbnail.label"} = WebGUI::International::get(52,"USS"); - $var{"date.label"} = WebGUI::International::get(13,"USS"); - $var{"date.updated.label"} = WebGUI::International::get(78,"USS"); - $var{"by.label"} = WebGUI::International::get(21,"USS"); - $var{"submission.edit.label"} = WebGUI::International::get(27,"USS"); - WebGUI::Style::setLink($var{"rss.url"},{ rel=>'alternate', type=>'application/rss+xml', title=>'RSS' }); - my $constraints; - if ($session{scratch}{search}) { - $numResults = $session{scratch}{numResults}; - $constraints = WebGUI::Search::buildConstraints([qw(USS_submission.username asset.synopsis asset.title USS_submission.content USS_submission.userDefined1 USS_submission.userDefined2 USS_submission.userDefined3 USS_submission.userDefined4 USS_submission.userDefined5)]); - } - if ($constraints ne "") { - $constraints = "USS_submission.status='Approved' and ".$constraints; - } else { - $constraints = "(USS_submission.status='Approved' or (USS_submission.userId=".quote($session{user}{userId})." and USS_submission.userId<>'1')"; - if ($var{canModerate}) { - $constraints .= " or USS_submission.status='Pending'"; - } - $constraints .= ")"; - } - my $p = WebGUI::Paginator->new($self->getUrl,$numResults); - my $sql = "select * from USS_submission left join asset on USS_submission.assetId=asset.assetId - where asset.parentId=".quote($self->getId)." and asset.state='published' and asset.className='WebGUI::Asset::USS_submission' and $constraints - order by ".$self->getValue("sortBy")." ".$self->getValue("sortOrder"); - $p->setDataByQuery($sql); - my $page = $p->getPageData; - my $i = 0; - my $imageURL = ""; - foreach my $row (@$page) { - my $submission = WebGUI::Asset::USS_submission->newByPropertyHashRef($row); - my $body = WebGUI::HTML::filter($submission->get("content"),$self->get("filterContent")); - $body = WebGUI::HTML::format($body,$submission->get("contentType")); - my $controls = deleteIcon('func=delete',$submission->getUrl,WebGUI::International::get(17,"USS")).editIcon('func=edit',$submission->getUrl); - if ($self->get("sortBy") eq "lineage") { - if ($self->get("sortOrder") eq "desc") { - $controls .= moveUpIcon('func=demote',$submission->getUrl).moveDownIcon('func=promote',$submission->getUrl); - } else { - $controls .= moveUpIcon('func=promote',$submission->getUrl).moveDownIcon('func=demote',$submission->getUrl); - } - } - my $inDateRange; - if ($submission->get("startDate") < WebGUI::DateTime::time() && $submission->get("endDate") > WebGUI::DateTime::time()) { - $inDateRange = 1; - } else { - $inDateRange = 0; - } - push(@{$var{submissions_loop}}, { - "submission.id"=>$submission->getId, - "submission.url"=>$submission->getUrl, - "submission.content"=>$submission->get("synopsis"), - "submission.content.full"=>$submission->get("content"), - "submission.responses"=>$submission->getResponseCount, - "submission.title"=>$submission->get("title"), - "submission.userDefined1"=>$submission->get("userDefined1"), - "submission.userDefined2"=>$submission->get("userDefined2"), - "submission.userDefined3"=>$submission->get("userDefined3"), - "submission.userDefined4"=>$submission->get("userDefined4"), - "submission.userDefined5"=>$submission->get("userDefined5"), - "submission.userId"=>$submission->get("userId"), - "submission.username"=>$submission->get('username'), - "submission.status"=>$self->status($submission->get("status")), - "submission.thumbnail"=>$submission->getThumbnailUrl, - "submission.image"=>$submission->getImageUrl, - "submission.date"=>epochToHuman($submission->get("dateSubmitted")), - "submission.date.updated"=>epochToHuman($submission->get("dateUpdated")), - "submission.userProfile"=>WebGUI::URL::page('op=viewProfile&uid='.$submission->get("userId")), - "submission.edit.url"=>$submission->getUrl("func=edit"), - "submission.secondColumn"=>(($i+1)%2==0), - "submission.thirdColumn"=>(($i+1)%3==0), - "submission.fourthColumn"=>(($i+1)%4==0), - "submission.fifthColumn"=>(($i+1)%5==0), - 'submission.controls'=>$submission->getToolbar, - 'submission.inDateRange'=>$inDateRange, - "submission.currentUser"=>($session{user}{userId} eq $submission->get("userId") && $session{user}{userId} ne "1") - }); - $i++; - } - $p->appendTemplateVars(\%var); - return $self->processTemplate(\%var,$self->get("templateId")); -} - -#------------------------------------------------------------------- -sub www_edit { - my $self = shift; - return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless $self->canEdit; - $self->getAdminConsole->setHelp("user submission system add/edit"); - return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get("18","USS")); -} - - -#------------------------------------------------------------------- -# print out RSS 2.0 feed describing the items visible on the first page -sub www_viewRSS { - $_[0]->logView() if ($session{setting}{passiveProfilingEnabled}); - my $wid = $_[0]->get("wobjectId"); - my $numResults = $_[0]->get("submissionsPerPage"); - - my $encTitle = _xml_encode($_[0]->get("title")); - my $encDescription = _xml_encode($_[0]->get("description")); - my $encUrl = _xml_encode(WebGUI::URL::page("wid=$wid")); - - my $xml = qq~ - - -$encTitle -$encUrl -$encDescription -~; - - my $res = WebGUI::SQL->read - ("select USS_submissionId, content, title, " . - "dateSubmitted, username from USS_submission " . - "where USS_id = " .quote($_[0]->get("USS_id")) . " and status='Approved' " . - "order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder")." limit " . $numResults,WebGUI::SQL->getSlave); - - while (my $row = $res->{_sth}->fetchrow_arrayref()) { - my ($sid, $content, $title, $dateSubmitted, $username) = - @{$row}; - - my $encUrl = _xml_encode - (WebGUI::URL::page - ("wid=$wid&func=viewSubmission&sid=$sid")); - my $encTitle = _xml_encode($title); - my $encPubDate = _xml_encode - (_get_rfc822_date($dateSubmitted)); - my $encDescription = _xml_encode($content); - - $xml .= qq~ - -$encTitle -$encUrl -$encDescription -$encUrl -$encPubDate - -~; - } - - $xml .=qq~ - - -~; - WebGUI::HTTP::setMimeType("text/xml"); - return $xml; -} - - - -1; - diff --git a/lib/WebGUI/Forum.pm b/lib/WebGUI/Forum.pm deleted file mode 100644 index a88bb5802..000000000 --- a/lib/WebGUI/Forum.pm +++ /dev/null @@ -1,475 +0,0 @@ -package WebGUI::Forum; - -=head1 LEGAL - - ------------------------------------------------------------------- - WebGUI is Copyright 2001-2005 Plain Black Corporation. - ------------------------------------------------------------------- - 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 - ------------------------------------------------------------------- - -=cut - -use strict; -use WebGUI::Forum::Thread; -use WebGUI::Grouping; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::Utility; - - -=head1 NAME - -Package WebGUI::Forum - -=head1 DESCRIPTION - -Data management class for forums. - -=head1 SYNOPSIS - - use WebGUI::Forum; - $forum = WebGUI::Forum->create(\%forumParams); - $forum = WebGUI::Forum->new($forumId); - - $boolean = $forum->canPost; - $boolean = $forum->canView; - $scalar = $forum->get($param); - $obj = $forum->getThread($threadId); - $boolean = $forum->isModerator; - $boolean = $forum->isSubscribed; - - $forum->decrementReplies; - $forum->decrementThreads; - $forum->incrementReplies($postDate, $postId); - $forum->incrementThreads($postDate, $postId); - $forum->incrementViews; - $forum->purge; - $forum->recalculateRating; - $forum->set(\%data); - $forum->setLastPost($epoch, $postId); - $forum->subscribe; - $forum->unsubscribe; - -=head1 METHODS - -These methods are available from this class: - -=cut - - -#------------------------------------------------------------------- - -=head2 canPost ( [ userId ] ) - -Returns a boolean whether the user has the privileges required to post. - -=head3 userId - -Defaults to $session{user}{userId}. Specify a user ID to check privileges for. - -=cut - -sub canPost { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - return (WebGUI::Grouping::isInGroup($self->get("groupToPost"),$userId) || $self->isModerator); -} - -#------------------------------------------------------------------- - -=head2 canView ( [ userId ] ) - -Returns a boolean whether the user has the privileges required to view the forum. - -=head3 userId - -Defaults to $session{user}{userId}. Specify a user ID to check privileges for. - -=cut - -sub canView { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - return (WebGUI::Grouping::isInGroup($self->get("groupToView"),$userId) || $self->canPost); -} - -#------------------------------------------------------------------- - -=head2 create ( forumParams ) - -Creates a new forum. Returns a forum object. - -=head3 forumParams - -A hash reference containing a list of the parameters to default the forum to. The valid parameters are: - -addEditStampToPosts - boolean -filterPosts - A valid HTML::filter string. -karmaPerPost - integer -groupToPost - Group ID -groupToModerate - Group ID -editTimeout - interval -moderatePosts - boolean -attachmentsPerPost - integer -allowRichEdit - boolean -allowReplacements - boolean -forumTemplateId - Template ID -threadTemplateId - Template ID -postTemplateId - Template ID -postFormTemplateId - Template ID -searchTemplateId - Template ID -notificationTemplateId - Template ID -archiveAfter - interval -postsPerPage - integer -masterForumId - Forum ID - -=cut - -sub create { - my ($self, $data) = @_; - $data->{forumId} = "new"; - my $forumId = WebGUI::SQL->setRow("forum","forumId",$data); - return WebGUI::Forum->new($forumId); -} - -#------------------------------------------------------------------- - -=head2 decrementReplies ( ) - -Deccrements this forum's reply counter. - -=cut - -sub decrementReplies { - my ($self) = @_; - WebGUI::SQL->write("update forum set replies=replies-1 where forumId=".quote($self->get("forumId"))); -} - -#------------------------------------------------------------------- - -=head2 decrementThreads ( ) - -Decrements this forum's thread counter. - -=cut - -sub decrementThreads { - my ($self) = @_; - WebGUI::SQL->write("update forum set threads=threads-1 where forumId=".quote($self->get("forumId"))); -} - -#------------------------------------------------------------------- - -=head2 get ( [ param ] ) - -Returns a hash reference containing all of the properties of the forum. - -=head3 param - -If specified then this method will return the value of this one parameter as a scalar. Param is the name of the parameter to return. See the forum table for details. - -=cut - -sub get { - my ($self, $key) = @_; - if ($key eq "") { - return $self->{_properties}; - } - return $self->{_properties}->{$key}; -} - -#------------------------------------------------------------------- - -=head2 getThread ( threadId ) - -Returns a thread object. - -=head3 threadId - -The unique identifier of a thread in this forum. - -=cut - -sub getThread { - my ($self, $threadId) = @_; - unless (exists $self->{_thread}{$threadId}) { - $self->{_thread}{$threadId} = WebGUI::Forum::Thread->new($threadId); - } - return $self->{_thread}{$threadId}; -} - -#------------------------------------------------------------------- - -=head2 isModerator ( [ userId ] ) - -Returns a boolean indicating whether the user is a moderator. - -=head3 userId - -Defaults to $session{user}{userId}. A user id to test for moderator privileges. - -=cut - -sub isModerator { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - return WebGUI::Grouping::isInGroup($self->get("groupToModerate"), $userId); -} - -#------------------------------------------------------------------- - -=head2 incrementReplies ( lastPostDate, lastPostId ) - -Increments this forum's reply counter. - -=head3 lastPostDate - -The date of the post being added. - -=head3 lastPostId - -The unique identifier of the post being added. - -=cut - -sub incrementReplies { - my ($self, $lastPostDate, $lastPostId) = @_; - WebGUI::SQL->write("update forum set replies=replies+1, lastPostId=".quote($lastPostId).", lastPostDate=$lastPostDate where forumId=".quote($self->get("forumId"))); -} - -#------------------------------------------------------------------- - -=head2 incrementThreads ( lastPostDate, lastPostId ) - -Increments the thread counter for this forum. - -=head3 lastPostDate - -The date of the post that was just added. - -=head3 lastPostId - -The unique identifier of the post that was just added. - -=cut - -sub incrementThreads { - my ($self, $lastPostDate, $lastPostId) = @_; - WebGUI::SQL->write("update forum set threads=threads+1, lastPostId=".quote($lastPostId).", lastPostDate=$lastPostDate where forumId=".quote($self->get("forumId"))); -} - -#------------------------------------------------------------------- - -=head2 incrementViews ( ) - -Increments the views counter on this forum. - -=cut - -sub incrementViews { - my ($self) = @_; - WebGUI::SQL->write("update forum set views=views+1 where forumId=".quote($self->get("forumId"))); -} - -#------------------------------------------------------------------- - -=head2 isSubscribed ( [ userId ] ) - -Returns a boolean indicating whether the user is subscribed to the forum. - -=head3 userId - -The user to check for the subscription. Defaults to $session{user}{userId}. - -=cut - -sub isSubscribed { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - my ($isSubscribed) = WebGUI::SQL->quickArray("select count(*) from forumSubscription where forumId=".quote($self->get("forumId"))." and userId=".quote($userId)); - return $isSubscribed; -} - -#------------------------------------------------------------------- - -=head2 new ( forumId ) - -Constructor. - -=head3 forumId - -The unique identifier of the forum to retrieve the object for. - -=cut - -sub new { - my ($class, $forumId) = @_; - my $properties = WebGUI::SQL->getRow("forum","forumId",$forumId); - if ($properties->{masterForumId}) { - my $master = WebGUI::SQL->getRow("forum","forumId",$properties->{masterForumId}); - $properties->{forumTemplateId} = $master->{forumTemplateId}; - $properties->{threadTemplateId} = $master->{threadTemplateId}; - $properties->{postTemplateId} = $master->{postTemplateId}; - $properties->{searchTemplateId} = $master->{searchTemplateId}; - $properties->{notificationTemplateId} = $master->{notificationTemplateId}; - $properties->{postFormTemplateId} = $master->{postFormTemplateId}; - $properties->{postPreviewTemplateId} = $master->{postPreviewTemplateId}; - $properties->{archiveAfter} = $master->{archiveAfter}; - $properties->{allowRichEdit} = $master->{allowRichEdit}; - $properties->{allowReplacements} = $master->{allowReplacements}; - $properties->{filterPosts} = $master->{filterPosts}; - $properties->{karmaPerPost} = $master->{karmaPerPost}; - $properties->{groupToView} = $master->{groupToView}; - $properties->{groupToPost} = $master->{groupToPost}; - $properties->{groupToView} = $master->{groupToView}; - $properties->{groupToModerate} = $master->{groupToModerate}; - $properties->{moderatePosts} = $master->{moderatePosts}; - $properties->{attachmentsPerPost} = $master->{attachmentsPerPost}; - $properties->{addEditStampToPosts} = $master->{addEditStampsToPost}; - $properties->{postsPerPage} = $master->{postsPerPage}; - $properties->{usePreview} = $master->{usePreview}; - - } - bless {_properties=>$properties}, $class; -} - -#------------------------------------------------------------------- - -=head2 purge ( ) - -Destroys this forum and everything it contains. - -=cut - -sub purge { - my ($self) = @_; - return unless ($self->get("forumId")); - my $a = WebGUI::SQL->read("select * from forumThread where forumId=".quote($self->get("forumId"))); - while (my ($threadId) = $a->array) { - my $b = WebGUI::SQL->read("select * from forumPost where forumThreadId=".quote($threadId)); - while (my ($postId) = $b->array) { - WebGUI::SQL->write("delete from forumPostAttachment where forumPostId=".quote($postId)); - WebGUI::SQL->write("delete from forumPostRating where forumPostId=".quote($postId)); - } - $b->finish; - WebGUI::SQL->write("delete from forumThreadSubscription where forumThreadId=".quote($threadId)); - WebGUI::SQL->write("delete from forumRead where forumThreadId=".quote($threadId)); - WebGUI::SQL->write("delete from forumPost where forumThreadId=".quote($threadId)); - } - $a->finish; - WebGUI::SQL->write("delete from forumSubscription where forumId=".quote($self->get("forumId"))); - WebGUI::SQL->write("delete from forumThread where forumId=".quote($self->get("forumId"))); - WebGUI::SQL->write("delete from forum where forumId=".quote($self->get("forumId"))); -} - -#------------------------------------------------------------------- - -=head2 recalculateRating ( ) - -Calculates the rating of this forum from its threads and stores the new value in the forum properties. - -=cut - -sub recalculateRating { - my ($self) = @_; - my ($count) = WebGUI::SQL->quickArray("select count(*) from forumThread where forumId=".quote($self->get("forumId"))." and rating>0"); - $count = $count || 1; - my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from forumThread where forumId=".quote($self->get("forumId"))." and rating>0"); - my $average = round($sum/$count); - $self->set({rating=>$average}); -} - -#------------------------------------------------------------------- - -=head2 set ( data ) - -Sets the forum properties both in the object and to the database. - -=head3 data - -A hash reference containing the properties to set. See the forum table for details. - -=cut - -sub set { - my ($self, $data) = @_; - $data->{forumId} = $self->get("forumId") unless ($data->{forumId}); - WebGUI::SQL->setRow("forum","forumId",$data); - foreach my $key (keys %{$data}) { - $self->{_properties}{$key} = $data->{$key}; - } -} - -#------------------------------------------------------------------- - -=head2 setLastPost ( lastPostDate, lastPostId ) - -Sets the pertinent details for the last post. Can also be done directly using the set method. - -=head3 lastPostDate - -The epoch date of the post. - -=head3 lastPostId - -The unique id of the post. - -=cut - -sub setLastPost { - my ($self, $postDate, $postId) = @_; - $self->set({ - lastPostId=>$postId, - lastPostDate=>$postDate - }); -} - -#------------------------------------------------------------------- - -=head2 subscribe ( [ userId ] ) - -Subscribes a user to this forum. - -=head3 userId - -The unique identifier of the user to subscribe. Defaults to the current user. - -=cut - -sub subscribe { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - unless ($self->isSubscribed($userId)) { - WebGUI::SQL->write("insert into forumSubscription (forumId, userId) values (".quote($self->get("forumId")).",".quote($userId).")"); - } -} - -#------------------------------------------------------------------- - -=head2 unsubscribe ( [ userId ] ) - -Unsubscribes a user from this forum. - -=head3 userId - -The unique identifier of the user to unsubscribe. Defaults to the current user. - -=cut - -sub unsubscribe { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - if ($self->isSubscribed($userId)) { - WebGUI::SQL->write("delete from forumSubscription where forumId=".quote($self->get("forumId"))." and userId=".quote($userId)); - } -} - - - -1; - diff --git a/lib/WebGUI/Forum/Post.pm b/lib/WebGUI/Forum/Post.pm deleted file mode 100644 index 40cf49b91..000000000 --- a/lib/WebGUI/Forum/Post.pm +++ /dev/null @@ -1,487 +0,0 @@ -package WebGUI::Forum::Post; - -=head1 LEGAL - - ------------------------------------------------------------------- - WebGUI is Copyright 2001-2005 Plain Black Corporation. - ------------------------------------------------------------------- - 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 - ------------------------------------------------------------------- - -=cut - -use strict; -use WebGUI::DateTime; -use WebGUI::Forum::Thread; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::Utility; - -=head1 NAME - -Package WebGUI::Forum::Post - -=head1 DESCRIPTION - -Data management class for forum posts. - -=head1 SYNOPSIS - - use WebGUI::Forum::Post; - $post = WebGUI::Forum::Post->create(\%params); - $post = WebGUI::Forum::Post->new($postId); - - $boolean = $post->canEdit; - $boolean = $post->canView; - $scalar = $post->get("forumPostId"); - $arrayRef = $post->getReplies; - $obj = $post->getThread; - $boolean = $post->hasRated; - $boolean = $post->isMarkedRead; - $boolean = $post->isReply; - - $post->incrementViews; - $post->markRead; - $post->rate($rating); - $post->recalculateRating; - $post->set(\%data); - $post->setStatusApproved; - $post->setStatusArchived; - $post->setStatusDeleted; - $post->setStatusDenied; - $post->setStatusPending; - $post->unmarkRead; - -=head1 METHODS - -These methods are available from this class: - -=cut - -#------------------------------------------------------------------- - -=head2 canEdit ( [ userId ] ) - -Returns a boolean indicating whether the user can edit the current post. - -=head3 userId - -The unique identifier to check privileges against. Defaults to the current user. - -=cut - -sub canEdit { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - return ($self->getThread->getForum->isModerator || ($self->get("userId") eq $userId && $userId != 1 - && $self->getThread->getForum->get("editTimeout") > (WebGUI::DateTime::time() - $self->get("dateOfPost")))); -} - -#------------------------------------------------------------------- - -=head2 canView ( [ userId ] ) - -Returns a boolean indicating whether the user can view the current post. - -=head3 userId - -The unique identifier to check privileges against. Defaults to the current user. - -=cut - -sub canView { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - if ($self->get("status") eq "approved" || $self->get("status") eq "archived") { - return 1; - } elsif ($self->get("status") eq "deleted") { - return 0; - } elsif ($self->get("status") eq "denied" && $userId eq $self->get("userId")) { - return 1; - } elsif ($self->getThread->getForum->isModerator) { - return 1; - } else { - return 0; - } -} - -#------------------------------------------------------------------- - -=head2 create ( [ data ] ) - -Creates a new post. - -=head3 data - -A hash reference containing the data to use to create the post. See the forumPost table for details. - -=cut - -sub create { - my ($self, $data) = @_; - $data->{dateOfPost} = WebGUI::DateTime::time(); - $data->{forumPostId} = "new"; - my $forumPostId = WebGUI::SQL->setRow("forumPost","forumPostId", $data); - $self = WebGUI::Forum::Post->new($forumPostId); - return $self; -} - -#------------------------------------------------------------------- - -=head2 get ( [ param ] ) - -Returns a hash reference containing all of the parameters of this post. - -=head3 param - -The name of a parameter to get. If specified then the method will return only the value for this parameter as a scalar. - -=cut - -sub get { - my ($self, $key) = @_; - if ($key eq "") { - return $self->{_properties}; - } - return $self->{_properties}->{$key}; -} - -#------------------------------------------------------------------- - -=head2 getReplies ( ) - -Returns an array reference containing a list of post objects that are direct decendants to this post. - -=cut - -sub getReplies { - my ($self) = @_; - my @replies = (); - my $query = "select forumPostId from forumPost where parentId=".quote($self->get("forumPostId"))." and "; - if ($self->getThread->getForum->isModerator) { - $query .= "(status='approved' or status='pending' or status='denied'"; - } else { - $query .= "(status='approved'"; - } - $query .= " or userId=".quote($session{user}{userId}).") order by dateOfPost"; - my $sth = WebGUI::SQL->read($query,WebGUI::SQL->getSlave); - while (my @data = $sth->array) { - push(@replies,WebGUI::Forum::Post->new($data[0])); - } - $sth->finish; - return \@replies; -} - -#------------------------------------------------------------------- - -=head2 getThread ( ) - -Returns the thread object that is related to this post. - -=cut - -sub getThread { - my ($self) = @_; - unless (exists $self->{_thread}) { - $self->{_thread} = WebGUI::Forum::Thread->new($self->get("forumThreadId")); - } - return $self->{_thread}; -} - -#------------------------------------------------------------------- - -=head2 hasRated ( [ userId, ipAddress ] ) - -Returns a boolean indicating whether this user has already rated this post. - -=head3 userId - -A unique identifier for a user to check. Defaults to the current user. - -=head3 ipAddress - -If the user ID equals 1 (visitor) then an IP address is used to distinguish the user. Defaults to the current user's ip address. - -=cut - -sub hasRated { - my ($self, $userId, $ipAddress) = @_; - $userId = $session{user}{userId} unless ($userId); - return 1 if ($userId != 1 && $userId eq $self->get("userId")); # is poster - $ipAddress = $session{env}{REMOTE_ADDR} unless ($ipAddress); - my ($flag) = WebGUI::SQL->quickArray("select count(*) from forumPostRating where forumPostId=" - .quote($self->get("forumPostId"))." and ((userId=".quote($userId)." and userId<>1) or (userId='1' and - ipAddress=".quote($ipAddress)."))"); - return $flag; -} - -#------------------------------------------------------------------- - -=head2 incrementViews ( ) - -Increments the views counter for this post. - -=cut - -sub incrementViews { - my ($self) = @_; - WebGUI::SQL->write("update forumPost set views=views+1 where forumPostId=".quote($self->get("forumPostId"))); - $self->getThread->incrementViews; -} - -#------------------------------------------------------------------- - -=head2 isMarkedRead ( [ userId ] ) - -Returns a boolean indicating whether this post is marked read for the user. - -=head3 userId - -A unique id for a user that you want to check. Defaults to the current user. - -=cut - -sub isMarkedRead { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - my ($isRead) = WebGUI::SQL->quickArray("select count(*) from forumRead where userId=".quote($userId)." and forumPostId=".quote($self->get("forumPostId"))); - return $isRead; -} - -#------------------------------------------------------------------- - -=head2 isReply ( ) - -Returns a boolean indicating whether this post is a reply or the root post in a thread. - -=cut - -sub isReply { - my ($self) = @_; - if ($self->get("parentId") ne "0") { - return 1; - } else { - return 0; - } -} - -#------------------------------------------------------------------- - -=head2 markRead ( [ userId ] ) - -Marks this post read for this user. - -=head3 userId - -A unique identifier for a user. Defaults to the current user. - -=cut - -sub markRead { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - unless ($self->isMarkedRead($userId)) { - WebGUI::SQL->write("insert into forumRead (userId, forumPostId, forumThreadId, lastRead) values (".quote($userId).", - ".quote($self->get("forumPostId")).", ".quote($self->get("forumThreadId")).", ".WebGUI::DateTime::time().")"); - } - $self->incrementViews; -} - -#------------------------------------------------------------------- - -=head2 new ( postId ) - -Constructor. - -=head3 postId - -The unique identifier for the post object you wish to retrieve. - -=cut - -sub new { - my ($class, $forumPostId) = @_; - my $properties = WebGUI::SQL->getRow("forumPost","forumPostId",$forumPostId); - if (defined $properties) { - bless {_properties=>$properties}, $class; - } else { - return undef; - } -} - -#------------------------------------------------------------------- - -=head2 rate ( rating [ , userId, ipAddress ] ) - -Stores a rating against this post. - -=head3 rating - -An integer between 1 and 5 (5 being best) to rate this post with. - -=head3 userId - -The unique id for the user rating this post. Defaults to the current user. - -=head3 ipAddress - -The ip address of the user doing the rating. Defaults to the current user's IP. - -=cut - -sub rate { - my ($self, $rating, $userId, $ipAddress) = @_; - $userId = $session{user}{userId} unless ($userId); - $ipAddress = $session{env}{REMOTE_ADDR} unless ($ipAddress); - WebGUI::SQL->write("insert into forumPostRating (forumPostId,userId,ipAddress,dateOfRating,rating) values (" - .quote($self->get("forumPostId")).", ".quote($userId).", ".quote($ipAddress).", ".WebGUI::DateTime::time().", $rating)"); - $self->recalculateRating; -} - -#------------------------------------------------------------------- - -=head2 recalculateRating ( ) - -Recalculates the average rating of the post from all the ratings and stores the result to the database. - -=cut - -sub recalculateRating { - my ($self) = @_; - my ($count) = WebGUI::SQL->quickArray("select count(*) from forumPostRating where forumPostId=".quote($self->get("forumPostId"))); - $count = $count || 1; - my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from forumPostRating where forumPostId=".quote($self->get("forumPostId"))); - my $average = round($sum/$count); - $self->set({rating=>$average}); - $self->getThread->recalculateRating; -} - -#------------------------------------------------------------------- - -=head2 set ( data ) - -Sets properties to the database and the object. - -=head3 data - -A hash reference containing the properties to set. See the forumPost table for details. - -=cut - - -sub set { - my ($self, $data) = @_; - $data->{forumPostId} = $self->get("forumPostId") unless ($data->{forumPostId}); - WebGUI::SQL->setRow("forumPost","forumPostId",$data); - foreach my $key (keys %{$data}) { - $self->{_properties}{$key} = $data->{$key}; - } -} - -#------------------------------------------------------------------- - -=head2 setStatusApproved ( ) - -Sets the status of this post to approved. - -=cut - - -sub setStatusApproved { - my ($self) = @_; - $self->set({status=>'approved'}); - $self->getThread->setStatusApproved if ($self->getThread->get("rootPostId") eq $self->get("forumPostId")); - if ($self->isReply) { - $self->getThread->incrementReplies($self->get("dateOfPost"),$self->get("forumPostId")); - } -} - -#------------------------------------------------------------------- - -=head2 setStatusArchived ( ) - -Sets the status of this post to archived. - -=cut - - -sub setStatusArchived { - my ($self) = @_; - $self->set({status=>'archived'}); - $self->getThread->setStatusArchived if ($self->getThread->get("rootPostId") eq $self->get("forumPostId")); - if ($self->isReply) { - $self->getThread->incrementReplies($self->get("dateOfPost"),$self->get("forumPostId")); - } -} - -#------------------------------------------------------------------- - -=head2 setStatusDeleted ( ) - -Sets the status of this post to deleted. - -=cut - -sub setStatusDeleted { - my ($self) = @_; - $self->set({status=>'deleted'}); - $self->getThread->decrementReplies; - $self->getThread->setStatusDeleted if ($self->getThread->get("rootPostId") eq $self->get("forumPostId")); - my ($id, $date) = WebGUI::SQL->quickArray("select forumPostId,dateOfPost from forumPost where forumThreadId=" - .quote($self->get("forumThreadId"))." and status='approved'"); - $self->getThread->setLastPost($date,$id); -} - -#------------------------------------------------------------------- - -=head2 setStatusDenied ( ) - -Sets the status of this post to denied. - -=cut - -sub setStatusDenied { - my ($self) = @_; - $self->set({status=>'denied'}); - $self->getThread->setStatusDenied if ($self->getThread->get("rootPostId") eq $self->get("forumPostId")); -} - -#------------------------------------------------------------------- - -=head2 setStatusPending ( ) - -Sets the status of this post to pending. - -=cut - -sub setStatusPending { - my ($self) = @_; - $self->set({status=>'pending'}); - $self->getThread->setStatusPending if ($self->getThread->get("rootPostId") eq $self->get("forumPostId")); -} - - -#------------------------------------------------------------------- - -=head2 unmarkRead ( [ userId ] ) - -Negates the markRead method. - -=head3 userId - -The unique id of the user marking unread. Defaults to the current user. - -=cut - -sub unmarkRead { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - WebGUI::SQL->write("delete from forumRead where userId=".quote($userId)." and forumPostId=".quote($self->get("forumPostId"))); -} - -1; - diff --git a/lib/WebGUI/Forum/Thread.pm b/lib/WebGUI/Forum/Thread.pm deleted file mode 100644 index 33719b97c..000000000 --- a/lib/WebGUI/Forum/Thread.pm +++ /dev/null @@ -1,540 +0,0 @@ -package WebGUI::Forum::Thread; - -=head1 LEGAL - - ------------------------------------------------------------------- - WebGUI is Copyright 2001-2005 Plain Black Corporation. - ------------------------------------------------------------------- - 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 - ------------------------------------------------------------------- - -=cut - -use strict; -use WebGUI::DateTime; -use WebGUI::Forum; -use WebGUI::Forum::Post; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::Utility; - -=head1 NAME - -Package WebGUI::Forum::Thread - -=head1 DESCRIPTION - -Data management class for forum threads. - -=head1 SYNOPSIS - - use WebGUI::Forum; - $thread = WebGUI::Forum::Thread->create(\%params); - $thread = WebGUI::Forum::Thread->new($threadId); - - $scalar = $thread->get($param); - $obj = $thread->getForum; - $obj = $thread->getNextThread; - $obj = $thread->getPost($postId); - $obj = $thread->getPreviousThread; - $boolean = $thread->isLocked; - $boolean = $thread->isSticky; - $boolean = $thread->isSubscribed; - - $thread->decrementReplies; - $thread->incrementReplies($postDate, $postId); - $thread->incrementViews; - $thread->lock; - $thread->recalculateRating; - $thread->set(\%data); - $thread->setLastPost($postDate,$postId); - $thread->setStatusApproved; - $thread->setStatusArchived; - $thread->setStatusDeleted; - $thread->setStatusDenied; - $thread->setStatusPending; - $thread->stick; - $thread->subscribe; - $thread->unlock; - $thread->unstick; - $thread->unsubscribe; - -=head1 METHODS - -These methods are available from this class: - -=cut - -#------------------------------------------------------------------- - -=head2 create ( data, postData ) - -Creates a new thread, including the root post in that thread. - -=head3 data - -The properties of this thread. See the forumThread table for details. - -=head3 postData - -The properties of the root post in this thread. See the forumPost table and the WebGUI::Forum::Post->create method for details. - -=cut - -sub create { - my ($self, $data, $postData) = @_; - $data->{forumThreadId} = "new"; - $postData->{forumThreadId} = WebGUI::SQL->setRow("forumThread","forumThreadId", $data); - $self = WebGUI::Forum::Thread->new($postData->{forumThreadId}); - $postData->{parentId} = 0; - my $post = WebGUI::Forum::Post->create($postData); - $self->set({ - rootPostId=>$post->get("forumPostId"), - lastPostId=>$post->get("forumPostId"), - lastPostDate=>$post->get("dateOfPost") - }); - $self->{_post}{$post->get("forumPostId")} = $post; - $self->getForum->incrementThreads($post->get("dateOfPost"),$post->get("forumPostId")); - return $self; -} - -#------------------------------------------------------------------- - -=head2 decrementReplies ( ) - -Decrements the replies counter for this thread. - -=cut - -sub decrementReplies { - my ($self) = @_; - WebGUI::SQL->write("update forumThread set replies=replies-1 where forumThreadId=".quote($self->get("forumThreadId"))); - $self->getForum->decrementReplies; -} - -#------------------------------------------------------------------- - -=head2 get ( [ param ] ) - -Returns a hash reference containing all the properties of this thread. - -=head3 param - -The name of a specific property. If specified only the value of that property will be return as a scalar. - -=cut - -sub get { - my ($self, $key) = @_; - if ($key eq "") { - return $self->{_properties}; - } - return $self->{_properties}->{$key}; -} - -#------------------------------------------------------------------- - -=head2 getForum ( ) - -Returns a forum object for the forum that is related to this thread. - -=cut - -sub getForum { - my ($self) = @_; - unless (exists $self->{_forum}) { - $self->{_forum} = WebGUI::Forum->new($self->get("forumId")); - } - return $self->{_forum}; -} - -#------------------------------------------------------------------- - -=head2 getNextThread ( ) - -Returns a thread object for the next (newer) thread in the same forum. - -=cut - -sub getNextThread { - my ($self) = @_; - unless (exists $self->{_next}) { - my ($nextId) = WebGUI::SQL->quickArray("select lastPostId from forumThread where forumId=".quote($self->get("forumId"))." - and lastPostDate>".quote($self->get("lastPostDate")." order by lastPostDate asc"),WebGUI::SQL->getSlave); - $self->{_next} = WebGUI::Forum::Thread->new($nextId); - } - return $self->{_next}; -} - -#------------------------------------------------------------------- - -=head2 getPost ( postId ) - -Returns a post object. - -=head3 postId - -The unique id of the post object you wish to retrieve. - -=cut - -sub getPost { - my ($self, $postId) = @_; - unless (exists $self->{_post}{$postId}) { - $self->{_post}{$postId} = WebGUI::Forum::Post->new($postId); - } - return $self->{_post}{$postId}; -} - -#------------------------------------------------------------------- - -=head2 getPreviousThread ( ) - -Returns a thread object for the previous (older) thread in the same forum. - -=cut - -sub getPreviousThread { - my ($self) = @_; - unless (exists $self->{_previous}) { - my ($nextId) = WebGUI::SQL->quickArray("select lastPostId from forumThread where forumId=".quote($self->get("forumId"))." - and lastPostDate<".quote($self->get("lastPostDate")." order by lastPostDate desc"),WebGUI::SQL->getSlave); - $self->{_previous} = WebGUI::Forum::Thread->new($nextId); - } - return $self->{_previous}; -} - -#------------------------------------------------------------------- - -=head2 isLocked ( ) - -Returns a boolean indicating whether this thread is locked from new posts and other edits. - -=cut - -sub isLocked { - my ($self) = @_; - return $self->get("isLocked"); -} - -#------------------------------------------------------------------- - -=head2 incrementReplies ( lastPostDate, lastPostId ) - -Increments the replies counter for this thread. - -=head3 lastPostDate - -The date of the reply that caused the replies counter to be incremented. - -=head3 lastPostId - -The id of the reply that caused the replies counter to be incremented. - -=cut - -sub incrementReplies { - my ($self, $dateOfReply, $replyId) = @_; - WebGUI::SQL->write("update forumThread set replies=replies+1, lastPostId=".quote($replyId).", lastPostDate=$dateOfReply - where forumThreadId=".quote($self->get("forumThreadId"))); - $self->getForum->incrementReplies($dateOfReply,$replyId); -} - -#------------------------------------------------------------------- - -=head2 incrementViews ( ) - -Increments the views counter for this thread. - -=cut - -sub incrementViews { - my ($self) = @_; - WebGUI::SQL->write("update forumThread set views=views+1 where forumThreadId=".quote($self->get("forumThreadId"))); - $self->getForum->incrementViews; -} - -#------------------------------------------------------------------- - -=head2 isSticky ( ) - -Returns a boolean indicating whether this thread should be "stuck" a the top of the forum and not be sorted with the rest of the threads. - -=cut - -sub isSticky { - my ($self) = @_; - return $self->get("isSticky"); -} - -#------------------------------------------------------------------- - -=head2 isSubscribed ( [ userId ] ) - -Returns a boolean indicating whether the user is subscribed to this thread. - -=head3 userId - -The unique id of the user to check. Defaults to the current user. - -=cut - -sub isSubscribed { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - my ($isSubscribed) = WebGUI::SQL->quickArray("select count(*) from forumThreadSubscription where forumThreadId=".quote($self->get("forumThreadId")) - ." and userId=".quote($userId)); - return $isSubscribed; -} - -#------------------------------------------------------------------- - -=head2 lock ( ) - -Sets this thread to be locked from edits. - -=cut - -sub lock { - my ($self) = @_; - $self->set({isLocked=>1}); -} - -#------------------------------------------------------------------- - -=head2 new ( threadId ) - -Constructor. - -=head3 threadId - -The unique id of the thread object you wish to retrieve. - -=cut - -sub new { - my ($class, $forumThreadId) = @_; - my $properties = WebGUI::SQL->getRow("forumThread","forumThreadId",$forumThreadId); - if (defined $properties) { - bless {_properties=>$properties}, $class; - } else { - return undef; - } -} - -#------------------------------------------------------------------- - -=head2 recalculateRating ( ) - -Recalculates the average rating of this thread based upon all of the posts in the thread. - -=cut - -sub recalculateRating { - my ($self) = @_; - my ($count) = WebGUI::SQL->quickArray("select count(*) from forumPost where forumThreadId=".quote($self->get("forumThreadId"))." and rating>0"); - $count = $count || 1; - my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from forumPost where forumThreadId=".quote($self->get("forumThreadId"))." and rating>0"); - my $average = round($sum/$count); - $self->set({rating=>$average}); - $self->getForum->recalculateRating; -} - -#------------------------------------------------------------------- - -=head2 set ( data ) - -Sets properties for this thread both to the object and to the database. - -=head3 data - -A hash reference containing the properties to set. See the forumThread table for details. - -=cut - -sub set { - my ($self, $data) = @_; - $data->{forumThreadId} = $self->get("forumThreadId") unless ($data->{forumThreadId}); - WebGUI::SQL->setRow("forumThread","forumThreadId",$data); - foreach my $key (keys %{$data}) { - $self->{_properties}{$key} = $data->{$key}; - } -} - -#------------------------------------------------------------------- - -=head2 setLastPost ( lastPostDate, lastPostId ) - -Sets the pertinent details for the last post. Can also be done directly using the set method. - -=head3 lastPostDate - -The epoch date of the post. - -=head3 lastPostId - -The unique id of the post. - -=cut - -sub setLastPost { - my ($self, $postDate, $postId) = @_; - $self->set({ - lastPostId=>$postId, - lastPostDate=>$postDate - }); - $self->getForum->setLastPost($postDate, $postId); -} - -#------------------------------------------------------------------- - -=head2 setStatusApproved ( ) - -Sets the status of this thread to approved. - -=cut - -sub setStatusApproved { - my ($self) = @_; - $self->set({status=>'approved'}); -} - -#------------------------------------------------------------------- - -=head2 setStatusArchived ( ) - -Sets the status of this thread to archived. - -=cut - -sub setStatusArchived { - my ($self) = @_; - $self->set({status=>'archived'}); -} - -#------------------------------------------------------------------- - -=head2 setStatusDeleted ( ) - -Sets the status of this thread to deleted. - -=cut - -sub setStatusDeleted { - my ($self) = @_; - $self->set({status=>'deleted'}); - $self->getForum->decrementThreads; -} - -#------------------------------------------------------------------- - -=head2 setStatusDenied ( ) - -Sets the status of this thread to denied. - -=cut - -sub setStatusDenied { - my ($self) = @_; - $self->set({status=>'denied'}); -} - -#------------------------------------------------------------------- - -=head2 setStatusPending ( ) - -Sets the status of this thread to pending. - -=cut - -sub setStatusPending { - my ($self) = @_; - $self->set({status=>'pending'}); -} - -#------------------------------------------------------------------- - -=head2 stick ( ) - -Makes this thread sticky. - -=cut - -sub stick { - my ($self) = @_; - $self->set({isSticky=>1}); -} - -#------------------------------------------------------------------- - -=head2 subscribe ( [ userId ] ) - -Subscribes the user to this thread. - -=head3 userId - -The unique id of the user. Defaults to the current user. - -=cut - -sub subscribe { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - unless ($self->isSubscribed($userId)) { - WebGUI::SQL->write("insert into forumThreadSubscription (forumThreadId, userId) values (".quote($self->get("forumThreadId")).",".quote($userId).")"); - } -} - -#------------------------------------------------------------------- - -=head2 unlock ( ) - -Negates the lock method. - -=cut - -sub unlock { - my ($self) = @_; - $self->set({isLocked=>0}); -} - -#------------------------------------------------------------------- - -=head2 unstick ( ) - -Negates the stick method. - -=cut - -sub unstick { - my ($self) = @_; - $self->set({isSticky=>0}); -} - -#------------------------------------------------------------------- - -=head2 unsubscribe ( [ userId ] ) - -Negates the subscribe method. - -=head3 userId - -The unique id of the user to unsubscribe. Defaults to the current user. - -=cut - -sub unsubscribe { - my ($self, $userId) = @_; - $userId = $session{user}{userId} unless ($userId); - if ($self->isSubscribed($userId)) { - WebGUI::SQL->write("delete from forumThreadSubscription where forumThreadId=".quote($self->get("forumThreadId"))." and userId=".quote($userId)); - } -} - - -1; - diff --git a/lib/WebGUI/Forum/UI.pm b/lib/WebGUI/Forum/UI.pm deleted file mode 100644 index 4eacb3578..000000000 --- a/lib/WebGUI/Forum/UI.pm +++ /dev/null @@ -1,2275 +0,0 @@ -package WebGUI::Forum::UI; - -=head1 LEGAL - - ------------------------------------------------------------------- - WebGUI is Copyright 2001-2005 Plain Black Corporation. - ------------------------------------------------------------------- - 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 - ------------------------------------------------------------------- - -=cut - -use strict qw(vars subs); -use WebGUI::DateTime; -use WebGUI::Form; -use WebGUI::FormProcessor; -use WebGUI::Forum; -use WebGUI::Forum::Post; -use WebGUI::Forum::Thread; -use WebGUI::HTML; -use WebGUI::HTTP; -use WebGUI::MessageLog; -use WebGUI::Search; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::Template; -use WebGUI::User; - - -=head1 NAME - -Package WebGUI::Forum::UI - -=head1 DESCRIPTION - -User interface package for forums. - -=head1 SYNOPSIS - - use WebGUI::Forum::UI; - - $scalar = WebGUI::Forum::UI::chopSubject($subject); - $url = WebGUI::Forum::UI::formatApprovePostURL($callback, $postId); - $url = WebGUI::Forum::UI::formatDeletePostURL($callback, $postId); - $url = WebGUI::Forum::UI::formatDenyPostURL($callback, $postId); - $url = WebGUI::Forum::UI::formatEditPostURL($callback, $postId); - $url = WebGUI::Forum::UI::formatForumSearchURL($callback, $forumId); - $url = WebGUI::Forum::UI::formatForumSortByURL($callback, $forumIId); - $url = WebGUI::Forum::UI::formatForumSubscribeURL($callback, $forumId); - $url = WebGUI::Forum::UI::formatForumUnsubscribeURL($callback, $forumId); - $url = WebGUI::Forum::UI::formatForumURL($callback, $forumId); - $scalar = WebGUI::Forum::UI::formatMessage($post,$forum); - $url = WebGUI::Forum::UI::formatNextThreadURL($callback, $postId); - $url = WebGUI::Forum::UI::formatNewThreadURL($callback, $forumId); - $scalar = WebGUI::Forum::UI::formatPostDate($epoch); - $scalar = WebGUI::Forum::UI::formatPostTime($epoch); - $url = WebGUI::Forum::UI::formatPreviousThreadURL($callback, $postId); - $url = WebGUI::Forum::UI::formatRatePostURL($callback, $postId, $rating); - $url = WebGUI::Forum::UI::formatReplyPostURL($callback, $postId, $forumId); - $scalar = WebGUI::Forum::UI::formatStatus($status); - $url = WebGUI::Forum::UI::formatThreadLayoutURL($callback, $postId, $layout); - $url = WebGUI::Forum::UI::formatThreadLockURL($callback, $postId); - $url = WebGUI::Forum::UI::formatThreadStickURL($callback, $postId); - $url = WebGUI::Forum::UI::formatThreadSubscribeURL($callback, $postId); - $url = WebGUI::Forum::UI::formatThreadUnlockURL($callback, $postId); - $url = WebGUI::Forum::UI::formatThreadUnstickURL($callback, $postId); - $url = WebGUI::Forum::UI::formatThreadUnsubscribeURL($callback, $postId); - $url = WebGUI::Forum::UI::formatThreadURL($callback, $postId); - $url = WebGUI::Forum::UI::formatUserProfileURL($userId); - - $html = WebGUI::Forum::UI::forumProperties($forumId); - WebGUI::Forum::UI::forumPropertiesSave(); - - $hashRef = WebGUI::Forum::UI::getForumTemplateVars($caller, $forum); - $hashRef = WebGUI::Forum::UI::getPostTemplateVars($post, $thread, $forum, $caller); - $hashRef = WebGUI::Forum::UI::getThreadTemplateVars($caller, $post); - $arrayRef = WebGUI::Forum::UI::recurseThread($post, $thread, $forum, $depth, $caller, $postId); - $arrayRef = WebGUI::Forum::UI::getFlatThread($post, $thread, $forum, $caller, $postId); - - WebGUI::Forum::UI::notifySubscribers($post, $thread, $forum, $caller); - WebGUI::Forum::UI::setPostApproved($caller, $post); - WebGUI::Forum::UI::setPostDeleted($caller, $post); - WebGUI::Forum::UI::setPostDenied($caller, $post); - WebGUI::Forum::UI::setPostPending($caller, $post); - WebGUI::Forum::UI::setPostStatus($caller, $post); - - $html = WebGUI::Forum::UI::forumOp($callback); - $html = WebGUI::Forum::UI::www_approvePost($callback); - $html = WebGUI::Forum::UI::www_deletePost($callback); - $html = WebGUI::Forum::UI::www_deletePostConfirm($callback); - $html = WebGUI::Forum::UI::www_denyPost($callback); - $html = WebGUI::Forum::UI::www_forumSubscribe($callback); - $html = WebGUI::Forum::UI::www_forumUnsubscribe($callback); - $html = WebGUI::Forum::UI::www_nextThread($callback); - $html = WebGUI::Forum::UI::www_post($callback); - $html = WebGUI::Forum::UI::www_postPreview($callback); - $html = WebGUI::Forum::UI::www_postSave($callback); - $html = WebGUI::Forum::UI::www_previousThread($callback); - $html = WebGUI::Forum::UI::www_ratePost($callback); - $html = WebGUI::Forum::UI::www_search($callback); - $html = WebGUI::Forum::UI::www_threadLock($callback); - $html = WebGUI::Forum::UI::www_threadStick($callback); - $html = WebGUI::Forum::UI::www_threadSubscribe($callback); - $html = WebGUI::Forum::UI::www_threadUnlock($callback); - $html = WebGUI::Forum::UI::www_threadUnstick($callback); - $html = WebGUI::Forum::UI::www_threadUnsubscribe($callback); - $html = WebGUI::Forum::UI::www_viewForum($callback); - $html = WebGUI::Forum::UI::www_viewThread($callback); - -=head1 FUNCTIONS - -These functions are available from this package: - -=cut - -#------------------------------------------------------------------- - -=head2 chopSubject ( subject ) - -Cuts a subject string off at 30 characters. - -=head3 subject - -The string to format. - -=cut - -sub chopSubject { - return substr($_[0],0,30); -} - -#------------------------------------------------------------------- - -=head2 formatApprovePostURL ( callback, postId ) - -Formats the URL to approve a post. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatApprovePostURL { - return WebGUI::URL::append($_[0],"forumOp=approvePost&forumPostId=".$_[1]."&mlog=".$session{form}{mlog}); -} - -#------------------------------------------------------------------- - -=head2 formatDeletePostURL ( callback, postId ) - -Formats the url to delete a post. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatDeletePostURL { - return WebGUI::URL::append($_[0],"forumOp=deletePost&forumPostId=".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatDenyPostURL ( callback, postId ) - -Formats the url to deny a post. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatDenyPostURL { - return WebGUI::URL::append($_[0],"forumOp=denyPost&forumPostId=".$_[1]."&mlog=".$session{form}{mlog}); -} - -#------------------------------------------------------------------- - -=head2 formatEditPostURL ( callback, postId ) - -Formats the url to edit a post. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatEditPostURL { - return WebGUI::URL::append($_[0],"forumOp=post&forumPostId=".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatForumSearchURL ( callback, forumId ) - -Formats the url to the forum search engine. - -=head3 callback - -The url to get back to the calling object. - -=head3 forumId - -The unique id for the forum. - -=cut - -sub formatForumSearchURL { - return WebGUI::URL::append($_[0],"forumOp=search&forumId=".quote($_[1])); -} - -#------------------------------------------------------------------- - -=head2 formatForumSortByURL ( callback, forumId, sortBy ) - -Formats the url to change the default sort. - -=head3 callback - -The url to get back to the calling object. - -=head3 forumId - -The unique id for the forum. - -=head3 sortBy - -The sort by string. Can be views, rating, date replies, or lastreply. - -=cut - -sub formatForumSortByURL { - return WebGUI::URL::append($_[0],"forumOp=viewForum&forumId=".quote($_[1])."&sortBy=".$_[2]); -} - -#------------------------------------------------------------------- - -=head2 formatForumSubscribeURL ( callback, forumId ) - -Formats the url to subscribe to the forum. - -=head3 callback - -The url to get back to the calling object. - -=head3 forumId - -The unique id for the forum. - -=cut - -sub formatForumSubscribeURL { - return WebGUI::URL::append($_[0],"forumOp=forumSubscribe&forumId=".quote($_[1])); -} - -#------------------------------------------------------------------- - -=head2 formatForumUnsubscribeURL ( callback, forumId ) - -Formats the url to unsubscribe from the forum. - -=head3 callback - -The url to get back to the calling object. - -=head3 forumId - -The unique id for the forum. - -=cut - -sub formatForumUnsubscribeURL { - return WebGUI::URL::append($_[0],"forumOp=forumUnsubscribe&forumId=".quote($_[1])); -} - -#------------------------------------------------------------------- - -=head2 formatForumURL ( callback, forumId ) - -Formats the url to view the forum. - -=head3 callback - -The url to get back to the calling object. - -=head3 forumId - -The unique id for the forum. - -=cut - -sub formatForumURL { - return WebGUI::URL::append($_[0],"forumOp=viewForum&forumId=".quote($_[1])); -} - - -#------------------------------------------------------------------- - -=head2 formatMessage ( post [, forum]) - -Formats a post message for display. - -=head3 post - -The post object for this message. - -=head3 forum - -The forum object for this message. Defaults to post->getThread->getForum. - -=cut - -sub formatMessage { - my $post = shift; - my $forum = shift || $post->getThread->getForum; - my $msg = WebGUI::HTML::filter($post->get("message"),$forum->get("filterPosts")); - $msg = WebGUI::HTML::format($msg, $post->get("contentType")); - if ($forum->get("allowReplacements")) { - $msg = WebGUI::HTML::processReplacements($msg); - } - return $msg; -} - -#------------------------------------------------------------------- - -=head2 formatNextThreadURL ( callback, postId ) - -Formats the url to view the next thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatNextThreadURL { - return WebGUI::URL::append($_[0],"forumOp=nextThread&forumThreadId=".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatNewThreadURL ( callback, forumId ) - -Formats the url to start a new thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 forumId - -The unique id for the forum. - -=cut - -sub formatNewThreadURL { - return WebGUI::URL::append($_[0],"forumOp=post&forumId=".quote($_[1])); -} - -#------------------------------------------------------------------- - -=head2 formatPostDate ( epoch ) - -Formats the date as human readable according to the user's profile. - -=head3 epoch - -The date represented as the number of seconds since January 1, 1970. - -=cut - -sub formatPostDate { - return WebGUI::DateTime::epochToHuman($_[0],"%z"); -} - -#------------------------------------------------------------------- - -=head2 formatPostTime ( epoch ) - -Formats the time as human readable according to the user's profile. - -=head3 epoch - -The date represented as the number of seconds since January 1, 1970. - -=cut - -sub formatPostTime { - return WebGUI::DateTime::epochToHuman($_[0],"%Z"); -} - -#------------------------------------------------------------------- - -=head2 formatPreviousThreadURL ( callback, postId ) - -Formats the url to view the previous thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatPreviousThreadURL { - return WebGUI::URL::append($_[0],"forumOp=previousThread&forumThreadId=".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatRatePostURL ( callback, postId, rating ) - -Formats the url to rate a post. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=head3 rating - -An integer between 1 and 5 (5 = best). - -=cut - -sub formatRatePostURL { - return WebGUI::URL::append($_[0],"forumOp=ratePost&forumPostId=".$_[1]."&rating=".$_[2]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatReplyPostURL ( callback, postId, forumId [ , withQuote ] ) - -Formats the url to reply to a post. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=head3 forumId - -The unique id for the forum. - -=head3 withQuote - -If specified the reply with automatically quote the parent post. - -=cut - -sub formatReplyPostURL { - my $url = WebGUI::URL::append($_[0],"forumOp=post&parentId=".$_[1]."&forumId=".$_[2]); - $url = WebGUI::URL::append($url,"withQuote=1") if ($_[3]); - return $url; -} - -#------------------------------------------------------------------- - -=head2 formatStatus ( status ) - -Returns an internationalized string for the status based upon the key. - -=head3 status - -A string key. Can be approved, archived, deleted, denied, or pending. - -=cut - -sub formatStatus { - 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); - } elsif ($_[0] eq "archived") { - return WebGUI::International::get(1046); - } -} - - -#------------------------------------------------------------------- - -=head2 formatThreadLayoutURL ( callback, postId, layout ) - -Formats the url to change the layout of a thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=head3 layout - -A string indicating the type of layout to use. Can be flat, nested, or threaded. - -=cut - -sub formatThreadLayoutURL { - return WebGUI::URL::append($_[0],"forumOp=viewThread&forumPostId=".$_[1]."&layout=".$_[2]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadLockURL ( callback, postId ) - -Formats the url to lock a thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadLockURL { - return WebGUI::URL::append($_[0],"forumOp=threadLock&forumPostId=".$_[1]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadStickURL ( callback, postId ) - -Formats the url to make a thread sticky. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadStickURL { - return WebGUI::URL::append($_[0],"forumOp=threadStick&forumPostId=".$_[1]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadSubscribeURL ( callback, postId ) - -Formats the url to subscribe to a thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadSubscribeURL { - return WebGUI::URL::append($_[0],"forumOp=threadSubscribe&forumPostId=".$_[1]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadUnlockURL ( callback, postId ) - -Formats the url to unlock a thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadUnlockURL { - return WebGUI::URL::append($_[0],"forumOp=threadUnlock&forumPostId=".$_[1]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadUnstickURL ( callback, postId ) - -Formats the url to make a sticky thread no longer sticky. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadUnstickURL { - return WebGUI::URL::append($_[0],"forumOp=threadUnstick&forumPostId=".$_[1]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadUnsubscribeURL ( callback, postId ) - -Formats the url to unsubscribe from a thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadUnsubscribeURL { - return WebGUI::URL::append($_[0],"forumOp=threadUnsubscribe&forumPostId=".$_[1]."#".$_[1]); -} - -#------------------------------------------------------------------- - -=head2 formatThreadURL ( callback, postId ) - -Formats the url to view a thread. - -=head3 callback - -The url to get back to the calling object. - -=head3 postId - -The unique id for the post. - -=cut - -sub formatThreadURL { - my $callback = shift; - my $postId = shift; - return WebGUI::URL::append($callback,"forumOp=viewThread&forumPostId=".$postId."#".$postId); -} - -#------------------------------------------------------------------- - -=head2 formatUserProfileURL ( userId ) - -Formats the url to view a users profile. - -=head3 userId - -The unique id for the user. - -=cut - -sub formatUserProfileURL { - return WebGUI::URL::page("op=viewProfile&uid=".$_[0]); -} - -#------------------------------------------------------------------- - -=head2 forumProperties ( forumId ) - -Returns a forum containing the editable properties of a forum. - -=head3 forumId - -The unique id of the forum. - -=cut - -sub forumProperties { - my ($forumId) = @_; - my $forum = WebGUI::Forum->new($forumId); - my $f = WebGUI::HTMLForm->new; - $f->hidden( - -name=>"forumId", - -value=>$forumId || "new" - ); - $f->template( - -name=>"forumTemplateId", - -label=>WebGUI::International::get(1031), - -namespace=>"Forum", - -uiLevel=>5, - -value=>$forum->get("forumTemplateId") - ); - $f->template( - -name=>"threadTemplateId", - -label=>WebGUI::International::get(1032), - -namespace=>"Forum/Thread", - -uiLevel=>5, - -value=>$forum->get("threadTemplateId") - ); - $f->template( - -name=>"postTemplateId", - -label=>WebGUI::International::get(1033), - -namespace=>"Forum/Post", - -uiLevel=>5, - -value=>$forum->get("postTemplateId") - ); - $f->template( - -name=>"searchTemplateId", - -label=>WebGUI::International::get(1044), - -namespace=>"Forum/Search", - -uiLevel=>5, - -value=>$forum->get("searchTemplateId") - ); - $f->template( - -name=>"postFormTemplateId", - -label=>WebGUI::International::get(1034), - -namespace=>"Forum/PostForm", - -uiLevel=>5, - -value=>$forum->get("postFormTemplateId") - ); - $f->template( - -name=>"postPreviewTemplateId", - -label=>WebGUI::International::get('Forum, Post Preview Template'), - -namespace=>"Forum/PostPreview", - -uiLevel=>5, - -value=>$forum->get("postPreviewTemplateId") - ); - $f->yesNo( - -name=>"usePreview", - -label=>WebGUI::International::get('Forum, use preview'), - -value=>$forum->get("usePreview"), - -uiLevel=>9 - ); - - $f->template( - -name=>"notificationTemplateId", - -label=>WebGUI::International::get(1035), - -namespace=>"Forum/Notification", - -uiLevel=>5, - -value=>$forum->get("notificationTemplateId") - ); - my ($interval, $units) = WebGUI::DateTime::secondsToInterval(($forum->get("archiveAfter") || 31536000)); - $f->interval( - -name=>"archiveAfter", - -label=>WebGUI::International::get(1043), - -intervalValue=>$interval, - -unitsValue=>$units, - -uiLevel=>9 - ); - ($interval, $units) = WebGUI::DateTime::secondsToInterval(($forum->get("editTimeout") || 3600)); - $f->interval( - -name=>"editTimeout", - -label=>WebGUI::International::get(566), - -intervalValue=>$interval, - -unitsValue=>$units, - -uiLevel=>9 - ); - $f->yesNo( - -name=>"addEditStampToPosts", - -label=>WebGUI::International::get(1025), - -value=>$forum->get("addEditStampToPosts"), - -uiLevel=>9 - ); - $f->yesNo( - -name=>"allowRichEdit", - -value=>$forum->get("allowRichEdit"), - -uiLevel=>7, - -label=>WebGUI::International::get(1026) - ); - $f->yesNo( - -name=>"allowReplacements", - -value=>$forum->get("allowReplacements"), - -uiLevel=>7, - -label=>WebGUI::International::get(1027) - ); - $f->filterContent( - -name=>"filterPosts", - -value=>$forum->get("filterPosts") || "most", - -label=>WebGUI::International::get(1024), - -uiLevel=>7 - ); - $f->integer( - -name=>"threadsPerPage", - -label=>WebGUI::International::get('Forum, Threads Per Page'), - -value=>$forum->get("threadsPerPage")||30, - -uiLevel=>7 - ); - $f->integer( - -name=>"postsPerPage", - -label=>WebGUI::International::get(1042), - -value=>$forum->get("postsPerPage")||10, - -uiLevel=>7 - ); - if ($session{setting}{useKarma}) { - $f->integer( - -name=>"karmaPerPost", - -label=>WebGUI::International::get(541), - -value=>($forum->get("karmaPerPost") || 0), - -uiLevel=>7 - ); - } else { - $f->hidden( - -name=>"karmaPerPost", - -value=>($forum->get("karmaPerPost") || 0) - ); - } - $f->group( - -name=>"groupToView", - -label=>WebGUI::International::get(872), - -value=>[$forum->get("groupToView")], - -uiLevel=>5 - ); - $f->group( - -name=>"groupToPost", - -label=>WebGUI::International::get(564), - -value=>[$forum->get("groupToPost")], - -uiLevel=>5 - ); - $f->yesNo( - -name=>"moderatePosts", - -label=>WebGUI::International::get(1028), - -uiLevel=>5, - -value=>$forum->get("moderatePosts") - ); - my $groupToModerate = $forum->get("groupToModerate") || 4; - $f->group( - -name=>"groupToModerate", - -label=>WebGUI::International::get(565), - -value=>[$groupToModerate], - -uiLevel=>5 - ); - return $f->printRowsOnly; -} - -#------------------------------------------------------------------- - -=head2 forumPropertiesSave ( ) - -Saves all of the forum properties in $session{form}. - -=cut - -sub forumPropertiesSave { - my %data = ( - forumTemplateId=>$session{form}{forumTemplateId}, - threadTemplateId=>$session{form}{threadTemplateId}, - postTemplateId=>$session{form}{postTemplateId}, - searchTemplateId=>$session{form}{searchTemplateId}, - notificationTemplateId=>$session{form}{notificationTemplateId}, - postFormTemplateId=>$session{form}{postFormTemplateId}, - postPreviewTemplateId=>$session{form}{postPreviewTemplateId}, - editTimeout=>WebGUI::FormProcessor::interval("editTimeout"), - archiveAfter=>WebGUI::FormProcessor::interval("archiveAfter"), - addEditStampToPosts=>$session{form}{addEditStampToPosts}, - allowRichEdit=>$session{form}{allowRichEdit}, - allowReplacements=>$session{form}{allowReplacements}, - filterPosts=>$session{form}{filterPosts}, - threadsPerPage=>$session{form}{threadsPerPage}, - postsPerPage=>$session{form}{postsPerPage}, - karmaPerPost=>$session{form}{karmaPerPost}, - groupToView=>$session{form}{groupToView}, - groupToPost=>$session{form}{groupToPost}, - moderatePosts=>$session{form}{moderatePosts}, - groupToModerate=>$session{form}{groupToModerate}, - usePreview=>$session{form}{usePreview} - ); - my $forum; - if ($session{form}{forumId} eq "new") { - $forum = WebGUI::Forum->create(\%data); - } else { - $forum = WebGUI::Forum->new($session{form}{forumId}); - $forum->set(\%data); - } - return $forum->get("forumId"); -} - -#------------------------------------------------------------------- - -=head2 forumOp ( caller ) - -Returns the output of the various www_ subroutines. - -=head3 caller - -A hash reference containing information passed from the calling object. The following are hash keys that should be passed: - -callback: The URL to get back to the calling object. - -title: The title of the parent object for display in the forum templates. - -description: The description of the parent object for display in the fourm templates. - -forumId: The ID of the forum that is attached to the calling object. - -=cut - -sub forumOp { - my ($caller) = @_; - if ($session{form}{forumOp} =~ /^[A-Za-z]+$/) { - my $forumId = $session{form}{forumId}; - if ($session{form}{forumPostId}) { - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - if($session{form}{forumPostId} ne ''){ - $forumId = $post->getThread->get("forumId"); - } - - } elsif ($session{form}{forumThreadId}) { - my $thread = WebGUI::Forum::Thread->new($session{form}{forumThreadId}); - $forumId = $thread->get("forumId"); - } - if ($forumId ne $caller->{forumId}) { - WebGUI::ErrorHandler::security("view a forum (".$caller->{forumId}.") that does not belong to the calling object (".$caller->{callback}.")"); - return WebGUI::Privilege::insufficient(); - } - my $cmd = "www_".$session{form}{forumOp}; - return &$cmd($caller); - } else { - return WebGUI::ErrorHandler::security("execute an invalid forum operation: ".$session{form}{forumOp}); - } -} - -#------------------------------------------------------------------- - -=head2 getForumTemplateVars ( caller, forum ) - -Returns a hash reference compatible with WebGUI's templating system. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 forum - -The unique id for the forum. - -=cut - -sub getForumTemplateVars { - my ($caller, $forum) = @_; - my $callback = $caller->{callback}; - my (%var, @thread_loop); - $var{'callback.url'} = $callback; - $var{'callback.label'} = WebGUI::International::get(1039); - $var{'user.isVisitor'} = ($session{user}{userId} eq '1'); - $var{'thread.new.url'} = formatNewThreadURL($callback,$forum->get("forumId")); - $var{'thread.new.label'} = WebGUI::International::get(1018); - $var{'forum.description'} = $caller->{description}; - $var{'forum.title'} = $caller->{title}; - $var{'forum.search.label'} = WebGUI::International::get(364); - $var{'forum.search.url'} = formatForumSearchURL($callback,$forum->get("forumId")); - $var{'forum.subscribe.label'} = WebGUI::International::get(1022); - $var{'forum.subscribe.url'} = formatForumSubscribeURL($callback,$forum->get("forumId")); - $var{'forum.unsubscribe.label'} = WebGUI::International::get(1023); - $var{'forum.unsubscribe.url'} = formatForumUnsubscribeURL($callback,$forum->get("forumId")); - $var{'user.isSubscribed'} = $forum->isSubscribed; - $var{'user.isModerator'} = $forum->isModerator; - $var{'user.canPost'} = $forum->canPost; - $var{'thread.sortby.date.url'} = formatForumSortByURL($callback,$forum->get("forumId"),"date"); - $var{'thread.sortby.lastreply.url'} = formatForumSortByURL($callback,$forum->get("forumId"),"lastreply"); - $var{'thread.sortby.views.url'} = formatForumSortByURL($callback,$forum->get("forumId"),"views"); - $var{'thread.sortby.replies.url'} = formatForumSortByURL($callback,$forum->get("forumId"),"replies"); - $var{'thread.sortby.rating.url'} = formatForumSortByURL($callback,$forum->get("forumId"),"rating"); - $var{'thread.subject.label'} = WebGUI::International::get(229); - $var{'thread.date.label'} = WebGUI::International::get(245); - $var{'thread.user.label'} = WebGUI::International::get(244); - $var{"thread.views.label"} = WebGUI::International::get(514); - $var{"thread.replies.label"} = WebGUI::International::get(1016); - $var{'thread.rating.label'} = WebGUI::International::get(1020); - $var{"thread.last.label"} = WebGUI::International::get(1017); - my $query = "select * from forumThread where forumId=".quote($forum->get("forumId"))." and "; - if ($forum->isModerator) { - $query .= "(status='approved' or status='pending')"; - } else { - $query .= "status='approved'"; - } - $query .= " order by isSticky desc, "; - my $sortDir = $session{scratch}{forumSortDir}; - $var{'thread.sorted.'.$sortDir} = 1; - if ($session{scratch}{forumSortBy} eq "date") { - $var{'thread.sortedby.date'} = 1; - $query .= "lastPostDate $sortDir"; - } elsif ($session{scratch}{forumSortBy} eq "views") { - $var{'thread.sortedby.views'} = 1; - $query .= "views $sortDir"; - } elsif ($session{scratch}{forumSortBy} eq "replies") { - $var{'thread.sortedby.replies'} = 1; - $query .= "replies $sortDir"; - } elsif ($session{scratch}{forumSortBy} eq "rating") { - $var{'thread.sortedby.rating'} = 1; - $query .= "rating $sortDir"; - } else { - $query .= "lastPostDate desc"; - } - my $p = WebGUI::Paginator->new(WebGUI::URL::append($callback,"forumOp=viewForum&forumId=".quote($forum->get("forumId"))),$forum->get("threadsPerPage")); - $p->setDataByQuery($query); - $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); - $var{numberOfPages} = $p->getNumberOfPages; - $var{pageNumber} = $p->getPageNumber; - my $threads = $p->getPageData; - foreach my $thread (@$threads) { - my $root = WebGUI::Forum::Post->new($thread->{rootPostId}); - my $last; - if ($thread->{rootPostId} eq $thread->{lastPostId}) { #saves the lookup if it's the same id - $last = $root; - } else { - $last = WebGUI::Forum::Post->new($thread->{lastPostId}); - } - Yy @rating_loop; - for (my $i=0;$i<=$thread->{rating};$i++) { - push(@rating_loop,{'thread.rating_loop.count'=>$i}); - } - push(@thread_loop,{ - 'thread.views'=>$thread->{views}, - 'thread.replies'=>$thread->{replies}, - 'thread.rating'=>$thread->{rating}, - 'thread.rating_loop'=>\@rating_loop, - 'thread.isSticky'=>$thread->{isSticky}, - 'thread.isLocked'=>$thread->{isLocked}, - 'thread.root.subject'=>chopSubject($root->get("subject")), - 'thread.root.url'=>formatThreadURL($callback,$root->get("forumPostId")), - 'thread.root.epoch'=>$root->get("dateOfPost"), - 'thread.root.date'=>formatPostDate($root->get("dateOfPost")), - 'thread.root.time'=>formatPostTime($root->get("dateOfPost")), - 'thread.root.user.profile'=>formatUserProfileURL($root->get("userId")), - 'thread.root.user.name'=>$root->get("username"), - 'thread.root.user.alias'=>WebGUI::User->new($root->get("userId"))->profileField("alias"), - 'thread.root.user.id'=>$root->get("userId"), - 'thread.root.user.isVisitor'=>($root->get("userId") eq '1'), - 'thread.root.status'=>formatStatus($root->get("status")), - 'thread.last.subject'=>chopSubject($last->get("subject")), - 'thread.last.url'=>formatThreadURL($callback,$last->get("forumPostId")), - 'thread.last.epoch'=>$last->get("dateOfPost"), - 'thread.last.date'=>formatPostDate($last->get("dateOfPost")), - 'thread.last.time'=>formatPostTime($last->get("dateOfPost")), - 'thread.last.user.profile'=>formatUserProfileURL($last->get("userId")), - 'thread.last.user.name'=>$last->get("username"), - 'thread.last.user.id'=>$last->get("userId"), - 'thread.last.user.isVisitor'=>($root->get("userId") eq '1'), - 'thread.last.status'=>formatStatus($last->get("status")) - }); - } - $var{thread_loop} = \@thread_loop; - return \%var; -} - -#------------------------------------------------------------------- - -=head2 getPostTemplateVars ( post, thread, forum, caller [, var ] ) - -Returns a hash reference compatible with WebGUI's templating system containing the template variables for a post. - -=head3 post - -A post object. - -=head3 thread - -A thread object. - -=head3 forum - -A forum object. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 var - -A hash reference to be prepended to the hashref being returned. - -=cut - -sub getPostTemplateVars { - my ($post, $thread, $forum, $caller, $var) = @_; - my $callback = $caller->{callback}; - $var->{'callback.url'} = $callback; - $var->{'callback.label'} = WebGUI::International::get(1039); - $var->{'post.subject.label'} = WebGUI::International::get(229); - $var->{'post.subject'} = WebGUI::HTML::filter($post->get("subject"),"none"); - $var->{'post.message'} = formatMessage($post,$forum); - $var->{'user.canPost'} = $forum->canPost; - $var->{'post.date.value'} = formatPostDate($post->get("dateOfPost")); - $var->{'post.date.label'} = WebGUI::International::get(245); - $var->{'post.date.epoch'} = $post->get("dateOfPost"); - $var->{'post.time.value'} = formatPostTime($post->get("dateOfPost")); - $var->{'post.rating.value'} = $post->get("rating")+0; - $var->{'post.rating.label'} = WebGUI::International::get(1020); - $var->{'post.views.value'} = $post->get("views")+0; - $var->{'post.views.label'} = WebGUI::International::get(514); - $var->{'post.status.value'} = formatStatus($post->get("status")); - $var->{'post.status.label'} = WebGUI::International::get(553); - $var->{'post.isLocked'} = $thread->isLocked; - $var->{'post.isModerator'} = $forum->isModerator; - $var->{'post.canEdit'} = $post->canEdit($session{user}{userId}); - $var->{'post.user.isVisitor'} = ($post->get("userId") eq '1'); - $var->{'post.user.label'} = WebGUI::International::get(244); - $var->{'post.user.name'} = $post->get("username"); - $var->{'post.user.alias'} = WebGUI::User->new($post->get("userId"))->profileField("alias"); - $var->{'post.user.Id'} = $post->get("userId"); - $var->{'post.user.Profile'} = formatUserProfileURL($post->get("userId")); - $var->{'post.url'} = WebGUI::URL::getSiteURL().formatThreadURL($callback,$post->get("forumPostId")); - $var->{'post.id'} = $post->get("forumPostId"); - $var->{'post.rate.label'} = WebGUI::International::get(1021); - $var->{'post.rate.url.1'} = formatRatePostURL($callback,$post->get("forumPostId"),1); - $var->{'post.rate.url.2'} = formatRatePostURL($callback,$post->get("forumPostId"),2); - $var->{'post.rate.url.3'} = formatRatePostURL($callback,$post->get("forumPostId"),3); - $var->{'post.rate.url.4'} = formatRatePostURL($callback,$post->get("forumPostId"),4); - $var->{'post.rate.url.5'} = formatRatePostURL($callback,$post->get("forumPostId"),5); - $var->{'post.hasRated'} = $post->hasRated; - $var->{'post.reply.label'} = WebGUI::International::get(577); - $var->{'post.reply.url'} = formatReplyPostURL($callback,$post->get("forumPostId"),$forum->get("forumId")); - $var->{'post.reply.withquote.url'} = formatReplyPostURL($callback,$post->get("forumPostId"),$forum->get("forumId"),1); - $var->{'post.edit.label'} = WebGUI::International::get(575); - $var->{'post.edit.url'} = formatEditPostURL($callback,$post->get("forumPostId")); - $var->{'post.delete.label'} = WebGUI::International::get(576); - $var->{'post.delete.url'} = formatDeletePostURL($callback,$post->get("forumPostId")); - $var->{'post.approve.label'} = WebGUI::International::get(572); - $var->{'post.approve.url'} = formatApprovePostURL($callback,$post->get("forumPostId")); - $var->{'post.deny.label'} = WebGUI::International::get(574); - $var->{'post.deny.url'} = formatDenyPostURL($callback,$post->get("forumPostId")); - $var->{'forum.title'} = $callback->{title}; - $var->{'forum.description'} = $callback->{description}; - $var->{'post.full'} = WebGUI::Template::process($forum->get("postTemplateId"),"Forum/Post", $var); - return $var; -} - -#------------------------------------------------------------------- - -=head2 getThreadTemplateVars ( caller, post ) - -Returns a hash reference compatible with WebGUI's template system containing the template variables for the thread. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 post - -A post object. - -=cut - -sub getThreadTemplateVars { - my ($caller, $post) = @_; - my $callback = $caller->{callback}; - $post->markRead($session{user}{userId}); - my $thread = $post->getThread; - unless ($post->canView) { - $post = $thread->getPost($thread->get("rootPostId")); - } - my $forum = $thread->getForum; - my $var = getPostTemplateVars($post, $thread, $forum, $caller); - my $root = WebGUI::Forum::Post->new($thread->get("rootPostId")); - $var->{'callback.url'} = $callback; - $var->{'callback.label'} = WebGUI::International::get(1039); - $var->{'user.canPost'} = $forum->canPost; - $var->{'user.isVisitor'} = ($session{user}{userId} eq '1'); - $var->{'user.isModerator'} = $forum->isModerator; - $var->{'user.isSubscribed'} = $thread->isSubscribed; - $var->{'thread.layout.nested.label'} = WebGUI::International::get(1045); - $var->{'thread.layout.nested.url'} = formatThreadLayoutURL($callback,$post->get("forumPostId"),"nested"); - $var->{'thread.layout.flat.label'} = WebGUI::International::get(510); - $var->{'thread.layout.flat.url'} = formatThreadLayoutURL($callback,$post->get("forumPostId"),"flat"); - $var->{'thread.layout.threaded.label'} = WebGUI::International::get(511); - $var->{'thread.layout.threaded.url'} = formatThreadLayoutURL($callback,$post->get("forumPostId"),"threaded"); - my $layout = $session{scratch}{forumThreadLayout} || $session{user}{discussionLayout}; - $var->{'thread.layout.isFlat'} = ($layout eq "flat"); - $var->{'thread.layout.isNested'} = ($layout eq "nested"); - $var->{'thread.layout.isThreaded'} = ($layout eq "threaded" || !($var->{'thread.layout.isNested'} || $var->{'thread.layout.isFlat'})); - $var->{'thread.subscribe.url'} = formatThreadSubscribeURL($callback,$post->get("forumPostId")); - $var->{'thread.subscribe.label'} = WebGUI::International::get(873); - $var->{'thread.unsubscribe.url'} = formatThreadUnsubscribeURL($callback,$post->get("forumPostId")); - $var->{'thread.unsubscribe.label'} = WebGUI::International::get(874); - $var->{'thread.isSticky'} = $thread->isSticky; - $var->{'thread.stick.url'} = formatThreadStickURL($callback,$post->get("forumPostId")); - $var->{'thread.stick.label'} = WebGUI::International::get(1037); - $var->{'thread.unstick.url'} = formatThreadUnstickURL($callback,$post->get("forumPostId")); - $var->{'thread.unstick.label'} = WebGUI::International::get(1038); - $var->{'thread.isLocked'} = $thread->isLocked; - $var->{'thread.lock.url'} = formatThreadLockURL($callback,$post->get("forumPostId")); - $var->{'thread.lock.label'} = WebGUI::International::get(1040); - $var->{'thread.unlock.url'} = formatThreadUnlockURL($callback,$post->get("forumPostId")); - $var->{'thread.unlock.label'} = WebGUI::International::get(1041); - my $p = WebGUI::Paginator->new(WebGUI::URL::append($callback,"forumOp=viewThread&forumPostId=".$post->get("forumPostId")."&layout=$layout"),$forum->get("postsPerPage")); - if($layout eq "flat"){ - $p->setDataByArrayRef(getFlatThread($root, $thread, $forum, $caller, $post->get("forumPostId"))); - $var->{post_loop} = $p->getPageData(); - }else{ - $p->setDataByArrayRef(recurseThread($root, $thread, $forum, 0, $caller, $post->get("forumPostId"))); - $var->{post_loop} = $p->getPageData(); - } - $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); - $var->{numberOfPages} = $p->getNumberOfPages; - $var->{pageNumber} = $p->getPageNumber; - - $var->{'thread.subject.label'} = WebGUI::International::get(229); - $var->{'thread.date.label'} = WebGUI::International::get(245); - $var->{'thread.user.label'} = WebGUI::International::get(244); - $var->{'thread.new.url'} = formatNewThreadURL($callback,$thread->get("forumId")); - $var->{'thread.new.label'} = WebGUI::International::get(1018); - $var->{'thread.previous.url'} = formatPreviousThreadURL($callback,$thread->get("forumThreadId")); - $var->{'thread.previous.label'} = WebGUI::International::get(513); - $var->{'thread.next.url'} = formatNextThreadURL($callback,$thread->get("forumThreadId")); - $var->{'thread.next.label'} = WebGUI::International::get(512); - $var->{'thread.list.url'} = formatForumURL($callback,$forum->get("forumId")); - $var->{'thread.list.label'} = WebGUI::International::get(1019); - $var->{'forum.title'} = $caller->{title}; - $var->{'forum.description'} = $caller->{description}; - return $var; -} - -#------------------------------------------------------------------- - -=head2 notifySubscribers ( post, thread, forum, caller ) - -Send notifications to the thread and forum subscribers that a new post has been made. - -=head3 post - -A post object. - -=head3 thread - -A thread object. - -=head3 forum - -A forum object. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub notifySubscribers { - my ($post, $thread, $forum, $caller) = @_; - my %subscribers; - my $sth = WebGUI::SQL->read("select userId from forumThreadSubscription where forumThreadId=".quote($thread->get("forumThreadId"))); - while (my ($userId) = $sth->array) { - $subscribers{$userId} = $userId unless ($userId eq $post->get("userId")); # make sure we don't send unnecessary messages - } - $sth->finish; - $sth = WebGUI::SQL->read("select userId from forumSubscription where forumId=".quote($forum->get("forumId"))); - while (my ($userId) = $sth->array) { - $subscribers{$userId} = $userId unless ($userId eq $post->get("userId")); # make sure we don't send unnecessary messages - } - $sth->finish; - my %lang; - foreach my $userId (keys %subscribers) { - my $u = WebGUI::User->new($userId); - if ($lang{$u->profileField("language")}{message} eq "") { - $lang{$u->profileField("language")}{var} = { - 'notify.subscription.message' => WebGUI::International::get(875,"WebGUI",$u->profileField("language")) - }; - $lang{$u->profileField("language")}{var} = getPostTemplateVars($post, $thread, $forum, $caller, $lang{$u->profileField("language")}{var}); - $lang{$u->profileField("language")}{subject} = WebGUI::International::get(523,"WebGUI",$u->profileField("language")); - $lang{$u->profileField("language")}{message} = WebGUI::Template::process( - $forum->get("notificationTemplateId"),"Forum/Notification", - $lang{$u->profileField("language")}{var} - ); - } - WebGUI::MessageLog::addEntry($userId,"",$lang{$u->profileField("language")}{subject},$lang{$u->profileField("language")}{message}); - } -} - -#------------------------------------------------------------------- - -=head2 recurseThread ( post, thread, forum, depth, caller, currentPost ) - -Returns an array reference with the template variables from all the posts in a thread. - -=head3 post - -A post object. - -=head3 thread - -A thread object. - -=head3 forum - -A forum object. - -=head3 depth - -An integer representing the depth of the current recurrsion. Starts at 0. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 currentPost - -The unique id of the post that was selected by the user in this thread. - -=cut - -sub recurseThread { - my ($post, $thread, $forum, $depth, $caller, $currentPost) = @_; - my @depth_loop; - for (my $i=0; $i<$depth; $i++) { - push(@depth_loop,{depth=>$i}); - } - my @post_loop; - if ($post->canView) { - push (@post_loop, getPostTemplateVars($post, $thread, $forum, $caller, { - 'post.indent_loop'=>\@depth_loop, - 'post.indent.depth'=>$depth, - 'post.isCurrent'=>($currentPost eq $post->get("forumPostId")) - })); - my $replies = $post->getReplies; - foreach my $reply (@{$replies}) { - @post_loop = (@post_loop,@{recurseThread($reply, $thread, $forum, $depth+1, $caller, $currentPost)}); - } - } - return \@post_loop; -} -#------------------------------------------------------------------- - -=head2 getFlatThread ( post, thread, forum, caller, currentPost ) - -Returns an array reference with the template variables from all the posts in a thread in flat mode. In flat mode -messages are ordered by submission date, so threading is not maintained. - -=head3 post - -A post object. - -=head3 thread - -A thread object. - -=head3 forum - -A forum object. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 currentPost - -The unique id of the post that was selected by the user in this thread. - -=cut - -sub getFlatThread { - my ($post, $thread, $forum, $caller, $currentPost) = @_; - my (@post_loop, @posts, $OR); - unless ($post->getThread->getForum->isModerator) { - $OR = "OR status='denied' OR status='pending'"; - } - @posts = WebGUI::SQL->buildArray("SELECT forumPostId FROM forumPost WHERE forumThreadId=".quote($thread->get("forumThreadId"))." AND NOT (status='deleted' $OR) ORDER BY dateOfPost"); - foreach my $postId (@posts){ - my $post = WebGUI::Forum::Post->new($postId); - push (@post_loop, getPostTemplateVars($post,$thread, $forum, $caller, { - 'post.isCurrent'=>($currentPost eq $post->get("forumPostId")) - })); - } - return \@post_loop; -} - -#------------------------------------------------------------------- - -=head2 setPostApproved ( caller, post ) - -Sets the post to approved and sends any necessary notifications. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 post - -A post object. - -=cut - -sub setPostApproved { - my ($caller, $post) = @_; - $post->setStatusApproved; - unless ($session{user}{userId} eq $post->get("userId")) { - WebGUI::MessageLog::addInternationalizedEntry($post->get("userId"),'',formatThreadURL($caller->{callback},$post->get("forumPostId")),579); - } - notifySubscribers($post,$post->getThread,$post->getThread->getForum,$caller); -} - -#------------------------------------------------------------------- - -=head2 setPostDeleted ( caller, post ) - -Sets the post to deleted and sends any necessary notifications. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 post - -A post object. - -=cut - -sub setPostDeleted { - my ($caller, $post) = @_; - $post->setStatusDeleted; -} - -#------------------------------------------------------------------- - -=head2 setPostDenied ( caller, post ) - -Sets the post to denied and sends any necessary notifications. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 post - -A post object. - -=cut - -sub setPostDenied { - my ($caller, $post) = @_; - $post->setStatusDenied; - WebGUI::MessageLog::addInternationalizedEntry($post->get("userId"),'',formatThreadURL($caller->{callback},$post->get("forumPostId")),580); -} - -#------------------------------------------------------------------- - -=head2 setPostPending ( caller, post ) - -Sets the post to pending and sends any necessary notifications. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 post - -A post object. - -=cut - -sub setPostPending { - my ($caller, $post) = @_; - $post->setStatusPending; - WebGUI::MessageLog::addInternationalizedEntry('',$post->getThread->getForum->get("groupToModerate"), - formatThreadURL($caller->{callback},$post->get("forumPostId")),578,'WebGUI','pending'); -} - -#------------------------------------------------------------------- - -=head2 setPostStatus ( caller, post ) - -Sets a new post's status based upon forum settings. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 post - -A post object. - -=cut - -sub setPostStatus { - my ($caller, $post) = @_; - if ($post->getThread->getForum->get("moderatePosts")) { - setPostPending($caller,$post); - } else { - setPostApproved($caller,$post); - } -} - -#------------------------------------------------------------------- - -=head2 www_approvePost ( caller ) - -The web method to approve a post. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_approvePost { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->isModerator); - setPostApproved($caller,$post); - return www_viewThread($caller); -} - -#------------------------------------------------------------------- - -=head2 www_deletePost ( caller ) - -The web method to prompt a user as to whether they actually want to delete a post. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_deletePost { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->canEdit); - my $output = '

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

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

'; - $output .= '

'.WebGUI::International::get(44).''; - $output .= '   '.WebGUI::International::get(45).'
'; - return $output; -} - -#------------------------------------------------------------------- - -=head2 www_deletePostConfirm ( caller ) - -The web method to delete a post. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_deletePostConfirm { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->canEdit); - $post->setStatusDeleted; - return www_viewForum($caller,$post->getThread->get("forumId")); -} - -#------------------------------------------------------------------- - -=head2 www_denyPost ( caller ) - -The web method to deny a post. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_denyPost { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->canEdit($session{user}{userId})); - setPostDenied($caller,$post); - return www_viewThread($caller); -} - -#------------------------------------------------------------------- - -=head2 www_forumSubscribe ( caller ) - -The web method to subscribe to a forum. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_forumSubscribe { - my ($caller) = @_; - my $forum = WebGUI::Forum->new($session{form}{forumId}); - return WebGUI::Privilege::insufficient() unless ($session{user}{userId} != 1); - $forum->subscribe; - return www_viewForum($caller, $session{form}{forumId}); -} - -#------------------------------------------------------------------- - -=head2 www_forumUnsubscribe ( caller ) - -The web method to unsubscribe from a forum. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_forumUnsubscribe { - my ($caller) = @_; - my $forum = WebGUI::Forum->new($session{form}{forumId}); - return WebGUI::Privilege::insufficient() unless ($session{user}{userId} != 1); - $forum->unsubscribe; - return www_viewForum($caller, $session{form}{forumId}); -} - -#------------------------------------------------------------------- - -=head2 www_nextThread ( caller ) - -The web method to display the next thread in the forum. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_nextThread { - my ($caller) = @_; - my $thread = WebGUI::Forum::Thread->new($session{form}{forumThreadId}); - my $nextThreadRoot = $thread->getNextThread->get("rootPostId"); - if (defined $nextThreadRoot) { - return www_viewThread($caller,$nextThreadRoot); - } else { - return www_viewForum($caller,$thread->get("forumId")); - } -} - -#------------------------------------------------------------------- - -=head2 www_post ( caller ) - -The web method to display the post form. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_post { - my ($caller) = @_; - my ($subject, $message, $forum); - my $var; - $var->{'newpost.header'} = WebGUI::International::get(1064); - $var->{'newpost.isReply'} = ($session{form}{parentId} ne ""); - $var->{'newpost.isEdit'} = ($session{form}{forumPostId} ne ""); - $var->{'newpost.isNewThread'} = ($session{form}{parentId} eq "" && !$var->{'newpost.isEdit'}); - $var->{'user.isVisitor'} = ($session{user}{userId} eq '1'); - $var->{'newpost.isNewMessage'} = ($var->{'newpost.isNewThread'} || $var->{'newpost.isReply'}); - $var->{'form.begin'} = WebGUI::Form::formHeader({ - action=>$caller->{callback} - }); - my $defaultSubscribeValue = 0; - my $contentType = "mixed"; - if ($var->{'newpost.isReply'}) { - my $reply = WebGUI::Forum::Post->new($session{form}{parentId}); - return WebGUI::Privilege::insufficient() unless ($reply->getThread->getForum->canPost); - $var->{'form.begin'} .= WebGUI::Form::hidden({ - name=>'parentId', - value=>$reply->get("forumPostId") - }); - $forum = $reply->getThread->getForum; - $var->{'form.begin'} .= WebGUI::Form::hidden({ - name=>'forumId', - value=>$forum->get("forumId") - }); - $message = "[quote]".$reply->get("message")."[/quote]" if ($session{form}{withQuote}); - $var = getPostTemplateVars($reply, $reply->getThread, $forum, $caller, $var); - - $subject = $reply->get("subject"); - $subject = "Re: ".$subject unless ($subject =~ /^Re:/); - } - if ($var->{'newpost.isNewThread'}) { - $var->{'form.begin'} .= WebGUI::Form::hidden({ - name=>'forumId', - value=>$session{form}{forumId} - }); - $forum = WebGUI::Forum->new($session{form}{forumId}); - if ($forum->isModerator) { - $var->{'sticky.label'} = WebGUI::International::get(1013); - $var->{'sticky.form'} = WebGUI::Form::yesNo({ - name=>'isSticky', - value=>0 - }); - } - $defaultSubscribeValue = 1 unless ($forum->isSubscribed); - } - if ($var->{'newpost.isNewMessage'}) { - $var->{'subscribe.label'} = WebGUI::International::get(873); - return WebGUI::Privilege::insufficient() unless ($forum->canPost); - my $u = WebGUI::User->new($session{user}{userId}); - $u->karma($forum->get("karmaPerPost"),"Forum (".$forum->get("forumId").")","Forum Post") if ($session{setting}{useKarma}); - if ($forum->isModerator) { - $var->{'lock.label'} = WebGUI::International::get(1012); - $var->{'lock.form'} = WebGUI::Form::yesNo({ - name=>'isLocked', - value=>0 - }); - } - $var->{'subscribe.form'} = WebGUI::Form::yesNo({ - name=>'subscribe', - value=>$defaultSubscribeValue - }); - $message .= "\n\n".$session{user}{signature} if ($session{user}{signature}); - } - if ($var->{'newpost.isEdit'}) { - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->canPost); - $subject = $post->get("subject"); - $message = $post->get("message"); - $forum = $post->getThread->getForum; - $var->{'form.begin'} .= WebGUI::Form::hidden({ - name=>"forumPostId", - value=>$post->get("forumPostId") - }); - $contentType = $post->get("contentType"); - } - $var->{'contentType.label'} = WebGUI::International::get(1007); - $var->{'contentType.form'} = WebGUI::Form::contentType({ - name=>'contentType', - value=>[$contentType] - }); - $var->{'user.isModerator'} = $forum->isModerator; - $var->{allowReplacements} = $forum->get("allowReplacements"); - if ($forum->get("allowRichEdit")) { - $var->{'message.form'} = WebGUI::Form::HTMLArea({ - name=>'message', - value=>$message - }); - } else { - $var->{'message.form'} = WebGUI::Form::textarea({ - name=>'message', - value=>$message - }); - } - $var->{'message.label'} = WebGUI::International::get(230); - if ($var->{'user.isVisitor'}) { - $var->{'visitorName.label'} = WebGUI::International::get(438); - $var->{'visitorName.form'} = WebGUI::Form::text({ - name=>'visitorName' - }); - } - my $forumOp = ($forum->get("usePreview"))? "postPreview" : "postSave"; - $var->{'form.begin'} .= WebGUI::Form::hidden({ - name=>'forumOp', - value=>$forumOp - }); - $var->{'form.submit'} = WebGUI::Form::submit(); - $var->{'subject.label'} = WebGUI::International::get(229); - $var->{'subject.form'} = WebGUI::Form::text({ - name=>'subject', - value=>$subject - }); - $var->{'form.end'} = WebGUI::Form::formFooter(); - return WebGUI::Template::process($forum->get("postformTemplateId"),"Forum/PostForm", $var); -} -#------------------------------------------------------------------- - -=head2 www_postPreview ( caller ) - -The web method to generate a preview of a posting. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_postPreview { - my ($caller) = @_; - - - my $forumId = $session{form}{forumId}; - my $threadId = $session{form}{forumThreadId}; - my $postId = $session{form}{forumPostId}; - my $subject = $session{form}{subject}; - $subject = WebGUI::International::get(232) if ($subject eq ""); - $subject .= ' '.WebGUI::International::get(233) if ($session{form}{message} eq ""); - if ( $subject ne "") { # subjects could never contain anything other than text - $subject = WebGUI::HTML::filter(WebGUI::HTML::processReplacements($subject),"all"); - } - my $newPost = WebGUI::Forum::Post->new(); - - $newPost->{_properties}->{message} = $session{form}{message}; - $newPost->{_properties}->{subject} = $subject; - $newPost->{_properties}->{contentType} = $session{form}{contentType}; - $newPost->{_properties}->{userId} = $session{user}{userId}; - $newPost->{_properties}->{username} = ($session{form}{visitorName} || $session{user}{alias}); - $newPost->{_properties}->{dateOfPost} = WebGUI::DateTime::time(); - my $forum = WebGUI::Forum->new($forumId); - - my $var = getPostTemplateVars($newPost, WebGUI::Forum::Thread->new($threadId), WebGUI::Forum->new($forumId), $caller); - $var->{'newpost.header'} = WebGUI::International::get('Forum, Preview Heading'); - - $var->{'form.begin'} = WebGUI::Form::formHeader({ - action=>$caller->{callback} - }); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'forumId', value=>$forumId}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'forumThreadId', value=>$threadId}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'forumPostId', value=>$postId}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'parentId', value=>$session{form}{parentId}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'subject', value=>$subject}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'message', value=>$session{form}{message}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'contentType', value=>$session{form}{contentType}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'visitorName', value=>$session{form}{visitorName}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'subscribe', value=>$session{form}{subscribe}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'isLocked', value=>$session{form}{isLocked}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'isSticky', value=>$session{form}{isSticky}}); - $var->{'form.begin'} .= WebGUI::Form::hidden({name=>'forumOp', value=>"postSave"}); - $var->{'form.submit'} = WebGUI::Form::submit(); - $var->{'form.end'} = WebGUI::Form::formFooter(); - return WebGUI::Template::process($forum->get("postPreviewTemplateId"),"Forum/PostPreview", $var); -} - - -#------------------------------------------------------------------- - -=head2 www_postSave ( caller ) - -The web method to save the data from the post form. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_postSave { - my ($caller) = @_; - my $forumId = $session{form}{forumId}; - my $threadId = $session{form}{forumThreadId}; - my $postId = $session{form}{forumPostId}; - my $subject = $session{form}{subject}; - $subject = WebGUI::International::get(232) if ($subject eq ""); - $subject .= ' '.WebGUI::International::get(233) if ($session{form}{message} eq ""); - if ( $subject ne "") { # subjects could never contain anything other than text - $subject = WebGUI::HTML::filter(WebGUI::HTML::processReplacements($subject),"all"); - } - my %postData = ( - message=>$session{form}{message}, - subject=>$subject, - contentType=>$session{form}{contentType} - ); - my %postDataNew = ( - userId=>$session{user}{userId}, - username=>($session{form}{visitorName} || $session{user}{alias}) - ); - if ($session{form}{parentId} ne '') { # reply - %postData = (%postData, %postDataNew); - my $parentPost = WebGUI::Forum::Post->new($session{form}{parentId}); - return WebGUI::Privilege::insufficient() unless ($parentPost->getThread->getForum->canPost); - $parentPost->getThread->subscribe($session{user}{userId}) if ($session{form}{subscribe}); - $parentPost->getThread->lock if ($session{form}{isLocked}); - $postData{forumThreadId} = $parentPost->getThread->get("forumThreadId"); - $postData{parentId} = $session{form}{parentId}; - my $post = WebGUI::Forum::Post->create(\%postData); - setPostStatus($caller,$post); - WebGUI::HTTP::setRedirect(formatThreadURL($caller->{callback}, $post->get("forumPostId"))); - - return "Redirecting..."; - #return www_viewThread($caller,$post->get("forumPostId")); - } - if ($session{form}{forumPostId} ne '') { # edit - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->canEdit); - if ($post->getThread->getForum->get("addEditStampToPosts")) { - $postData{message} .= "\n\n --- (".WebGUI::International::get(1029)." " - .WebGUI::DateTime::epochToHuman(WebGUI::DateTime::time())." ".WebGUI::International::get(1030) - ." $session{user}{username}) --- \n"; - } - $post->set(\%postData); - WebGUI::HTTP::setRedirect(formatThreadURL($caller->{callback}, $post->get("forumPostId"))); - return "Redirecting..."; - #return www_viewThread($caller,$post->get("forumPostId")); - } - if ($forumId) { # new post - %postData = (%postData, %postDataNew); - my $forum = WebGUI::Forum->new($forumId); - return WebGUI::Privilege::insufficient() unless ($forum->canPost); - my $thread = WebGUI::Forum::Thread->create({ - forumId=>$forumId, - isSticky=>$session{form}{isSticky}, - isLocked=>$session{form}{isLocked} - }, \%postData); - $thread->subscribe($session{user}{userId}) if ($session{form}{subscribe}); - setPostStatus($caller,$thread->getPost($thread->get("rootPostId"))); - WebGUI::HTTP::setRedirect(formatForumURL($caller->{callback}, $forumId)); - return "Redirecting..."; - #return www_viewForum($caller,$forumId); - } -} - -#------------------------------------------------------------------- - -=head2 www_previousThread ( caller ) - -The web method to view the previous thread in this forum. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_previousThread { - my ($caller) = @_; - my $thread = WebGUI::Forum::Thread->new($session{form}{forumThreadId}); - my $previousThreadRoot = $thread->getPreviousThread->get("rootPostId"); - if (defined $previousThreadRoot) { - return www_viewThread($caller,$previousThreadRoot); - } else { - return www_viewForum($caller,$thread->get("forumId")); - } -} - -#------------------------------------------------------------------- - -=head2 www_ratePost ( caller ) - -The web method to rate a post. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_ratePost { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->canPost); - $post->rate($session{form}{rating}) unless ($post->hasRated); - return www_viewThread($caller,$session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_search ( caller ) - -The web method to display and use the forum search interface. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_search { - my ($caller) = @_; - my $forum = WebGUI::Forum->new($session{form}{forumId}); - WebGUI::Session::setScratch("all",$session{form}{all}); - WebGUI::Session::setScratch("atLeastOne",$session{form}{atLeastOne}); - WebGUI::Session::setScratch("exactPhrase",$session{form}{exactPhrase}); - WebGUI::Session::setScratch("without",$session{form}{without}); - WebGUI::Session::setScratch("numResults",$session{form}{numResults}); - my %var; - $var{'callback.url'} = $caller->{callback}; - $var{'callback.label'} = WebGUI::International::get(1039); - $var{'form.begin'} = WebGUI::Form::formHeader({action=>$caller->{callback}}); - $var{'form.begin'} .= WebGUI::Form::hidden({ name=>"forumOp", value=>"search" }); - $var{'form.begin'} .= WebGUI::Form::hidden({ name=>"doit", value=>1 }); - $var{'form.begin'} .= WebGUI::Form::hidden({ name=>"forumId", value=>$session{form}{forumId} }); - $var{'search.label'} = WebGUI::International::get(364); - $var{'all.label'} = WebGUI::International::get(530); - $var{'all.form'} = WebGUI::Form::text({ - name=>'all', - value=>$session{scratch}{all}, - size=>($session{setting}{textBoxSize}-5) - }); - $var{'exactphrase.label'} = WebGUI::International::get(531); - $var{'exactphrase.form'} = WebGUI::Form::text({ - name=>'exactPhrase', - value=>$session{scratch}{exactPhrase}, - size=>($session{setting}{textBoxSize}-5) - }); - $var{'atleastone.label'} = WebGUI::International::get(532); - $var{'atleastone.form'} = WebGUI::Form::text({ - name=>'atLeastOne', - value=>$session{scratch}{atLeastOne}, - size=>($session{setting}{textBoxSize}-5) - }); - $var{'without.label'} = WebGUI::International::get(533); - $var{'without.form'} = WebGUI::Form::text({ - name=>'without', - value=>$session{scratch}{without}, - size=>($session{setting}{textBoxSize}-5) - }); - $var{'results.label'} = WebGUI::International::get(529); - my %results; - tie %results, 'Tie::IxHash'; - %results = (10=>'10', 25=>'25', 50=>'50', 100=>'100'); - my $numResults = $session{scratch}{numResults} || 25; - $var{'results.form'} = WebGUI::Form::selectList({ - name=>"numResults", - options=>\%results, - value=>[$numResults] - }); - $var{'form.search'} = WebGUI::Form::submit({value=>WebGUI::International::get(170)}); - $var{'form.end'} = WebGUI::Form::formFooter(); - $var{'thread.list.url'} = formatForumURL($caller->{callback},$forum->get("forumId")); - $var{'thread.list.label'} = WebGUI::International::get(1019); - $var{doit} = $session{form}{doit}; - if ($session{form}{doit}) { - $var{'post.subject.label'} = WebGUI::International::get(229); - $var{'post.date.label'} = WebGUI::International::get(245); - $var{'post.user.label'} = WebGUI::International::get(244); - my $constraints = WebGUI::Search::buildConstraints([qw(a.subject a.username a.message)]); - my $query = "select a.forumPostId, a.subject, a.userId, a.username, a.dateOfPost from forumPost a left join forumThread b - on a.forumThreadId=b.forumThreadId where b.forumId=".quote($forum->get("forumId"))." and - (a.status='approved' or a.status='archived') and $constraints order by a.dateOfPost desc"; - my $p = WebGUI::Paginator->new(WebGUI::URL::append($caller->{callback},"forumOp=search&doit=1&forumId=".quote($forum->get("forumId"))), $numResults); - $p->setDataByQuery($query) if $constraints; - my @post_loop; - foreach my $row (@{$p->getPageData}) { - push(@post_loop,{ - 'post.subject'=>$row->{subject}, - 'post.url'=>formatThreadURL($caller->{callback},$row->{forumPostId}), - 'post.user.name'=>$row->{username}, - 'post.user.id'=>$row->{userId}, - 'post.user.profile'=>formatUserProfileURL($row->{userId}), - 'post.epoch'=>$row->{dateOfPost}, - 'post.date'=>formatPostDate($row->{dateOfPost}), - 'post.time'=>formatPostTime($row->{dateOfPost}) - }); - } - $var{post_loop} = \@post_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); - $var{numberOfPages} = $p->getNumberOfPages; - $var{pageNumber} = $p->getPageNumber; - } - return WebGUI::Template::process($forum->get("searchTemplateId"),"Forum/Search", \%var); -} - -#------------------------------------------------------------------- - -=head2 www_threadLock ( caller ) - -The web method to lock a thread. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_threadLock { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->isModerator); - $post->getThread->lock; - return www_viewThread($caller, $session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_threadStick ( caller ) - -The web method to make a thread sticky. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_threadStick { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->isModerator); - $post->getThread->stick; - return www_viewThread($caller, $session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_threadSubscribe ( caller ) - -The web method to subscribe to a thread. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_threadSubscribe { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($session{user}{userId} != 1); - $post->getThread->subscribe; - return www_viewThread($caller, $session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_threadUnlock ( caller ) - -The web method to unlock a thread. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_threadUnlock { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->isModerator); - $post->getThread->unlock; - return www_viewThread($caller, $session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_threadUnstick ( caller ) - -The web method to make a sticky thread normal again. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_threadUnstick { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->isModerator); - $post->getThread->unstick; - return www_viewThread($caller, $session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_threadUnsubscribe ( caller ) - -The web method to unsubscribe from a thread. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=cut - -sub www_threadUnsubscribe { - my ($caller) = @_; - my $post = WebGUI::Forum::Post->new($session{form}{forumPostId}); - return WebGUI::Privilege::insufficient() unless ($session{user}{userId} != 1); - $post->getThread->unsubscribe; - return www_viewThread($caller, $session{form}{forumPostId}); -} - -#------------------------------------------------------------------- - -=head2 www_viewForum ( caller [ , forumId ] ) - -The web method to display a forum. - -=head3 caller - -The url to get back to the calling object. - -=head3 forumId - -Specify a forumId and call this method directly, rather than over the web. - -=cut - -sub www_viewForum { - my ($caller, $forumId) = @_; - $forumId = $session{form}{forumId} unless ($forumId); - - if($session{scratch}{forumSortBy} ne $session{form}{sortBy}){ - WebGUI::Session::setScratch("forumSortBy",$session{form}{sortBy}); - WebGUI::Session::setScratch("forumSortDir", "desc"); - }else{ - my $sortDir; - if($session{scratch}{forumSortDir} eq "asc"){ - $sortDir = "desc"; - }else{ - $sortDir = "asc"; - } - WebGUI::Session::setScratch("forumSortDir", $sortDir); - } - - my $forum = WebGUI::Forum->new($forumId); - return WebGUI::Privilege::insufficient() unless ($forum->canView); - my $var = getForumTemplateVars($caller, $forum); - return WebGUI::Template::process($forum->get("forumTemplateId"),"Forum", $var); -} - -#------------------------------------------------------------------- - -=head2 www_viewThread ( caller [ , postId ] ) - -The web method to display a thread. - -=head3 caller - -A hash reference containing information passed from the calling object. - -=head3 postId - -Specify a postId and call this method directly, rather than over the web. - -=cut - -sub www_viewThread { - my ($caller, $postId) = @_; - WebGUI::Session::setScratch("forumThreadLayout",$session{form}{layout}); - $postId = $session{form}{forumPostId} unless ($postId); - my $post = WebGUI::Forum::Post->new($postId); - return WebGUI::Privilege::insufficient() unless ($post->getThread->getForum->canView); - my $var = getThreadTemplateVars($caller, $post); - if ($post->get("forumPostId") eq $post->getThread->get("rootPostId") && !$post->canView) { - return www_viewForum($caller, $post->getThread->getForum->get("forumId")); - } else { - return WebGUI::Template::process($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread", $var); - } -} - - -1; -