From a4d391b52a4b38c709e514811813568c08a8a131 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 13 Jul 2003 03:28:03 +0000 Subject: [PATCH] working on new discussion system --- docs/upgrades/upgrade_5.4.1-5.5.0.sql | 1 + lib/WebGUI/Forum.pm | 1 + lib/WebGUI/Forum/Post.pm | 51 +++++++++++++++++--------- lib/WebGUI/Forum/Thread.pm | 1 + lib/WebGUI/Forum/Web.pm | 52 ++++++++++++++++++++++----- lib/WebGUI/HTML.pm | 27 -------------- 6 files changed, 81 insertions(+), 52 deletions(-) diff --git a/docs/upgrades/upgrade_5.4.1-5.5.0.sql b/docs/upgrades/upgrade_5.4.1-5.5.0.sql index 4c3aadd13..59a6bba80 100644 --- a/docs/upgrades/upgrade_5.4.1-5.5.0.sql +++ b/docs/upgrades/upgrade_5.4.1-5.5.0.sql @@ -59,6 +59,7 @@ create table forumThread ( create table forumRead ( userId int not null, forumPostId int not null, + forumThreadId int not null, lastRead int not null, primary key (userId, postId) ); diff --git a/lib/WebGUI/Forum.pm b/lib/WebGUI/Forum.pm index b5a61c996..72addbfe4 100644 --- a/lib/WebGUI/Forum.pm +++ b/lib/WebGUI/Forum.pm @@ -35,6 +35,7 @@ sub new { sub set { my ($self, $data) = @_; + $data->{forumId} = $self->get("forumId") unless ($data->{forumId}); WebGUI::SQL->setRow("forum","forumId",$data); $self->{_properties} = $data; } diff --git a/lib/WebGUI/Forum/Post.pm b/lib/WebGUI/Forum/Post.pm index d477548b1..dae95e0a2 100644 --- a/lib/WebGUI/Forum/Post.pm +++ b/lib/WebGUI/Forum/Post.pm @@ -1,6 +1,7 @@ package WebGUI::Forum::Post; -use WebGUI::Discuss::Thread; +use WebGUI::DateTime; +use WebGUI::Forum::Thread; use WebGUI::Session; use WebGUI::SQL; @@ -30,18 +31,6 @@ sub get { return $self->{_properties}->{$key}; } -sub getTemplateVars { - my ($self) = @_; - my $properties = $self->get; - my %var = %{$properties}; - $var->{subject} = WebGUI::HTML::filter($var->{subject},"none"); - $var->{message} = WebGUI::HTML::filter($var->{subject},$self->getThread->getForum->get("filterPosts")); - if ($self->getThread->getForum->get("allowReplacements")) { - # do the replacement thing - } - $var->{dateOfPost} = WebGUI::DateTime::epochToHuman($var->{dateOfPost}); -} - sub getThread { my ($self) = @_; unless (exists $self->{_thread}) { @@ -50,13 +39,19 @@ sub getThread { return $self->{_thread}; } +sub isMarkedRead { + my ($self, $userId) = @_; + $userId = $session{user}{userId} unless ($userId); + my ($isRead) = WebGUI::SQL->quickArray("select count(*) from forumRead where userId=$userId and forumPostId=".$self->get("forumPostId")); + return $isRead; +} + sub markRead { my ($self, $userId) = @_; $userId = $session{user}{userId} unless ($userId); - my ($alreadyMarked) = WebGUI::SQL->quickArray("select count(*) from forumRead userId,forumPostId"); - unless ($alreadyMarked) { - WebGUI::SQL->write("insert into forumRead (userId, forumPostId, lastRead) values ($userId, - ".$self->get("forumPostId").", ".WebGUI::DateTime::time().")"); + unless (isMarkedRead($userId)) { + WebGUI::SQL->write("insert into forumRead (userId, forumPostId, forumThreadId, lastRead) values ($userId, + ".$self->get("forumPostId").", ".$self->get("forumThreadId").", ".WebGUI::DateTime::time().")"); } } @@ -68,9 +63,31 @@ sub new { sub set { my ($self, $data) = @_; + $data->{forumPostId} = $self->get("forumPostId") unless ($data->{forumId}); WebGUI::SQL->setRow("forumPost","forumPostId",$data); $self->{_properties} = $data; } +sub setStatusApproved { + my ($self) = @_; + $self->set({status=>'approved'}); +} + +sub setStatusDenied { + my ($self) = @_; + $self->set({status=>'denied'}); +} + +sub setStatusPending { + my ($self) = @_; + $self->set({status=>'pending'}); +} + +sub unmarkRead { + my ($self, $userId) = @_; + $userId = $session{user}{userId} unless ($userId); + WebGUI::SQL->write("delete from forumRead where userId=$userId and forumPostId=".$self->get("forumPostId")); +} + 1; diff --git a/lib/WebGUI/Forum/Thread.pm b/lib/WebGUI/Forum/Thread.pm index 6864ac7df..72bdac1ee 100644 --- a/lib/WebGUI/Forum/Thread.pm +++ b/lib/WebGUI/Forum/Thread.pm @@ -93,6 +93,7 @@ sub new { sub set { my ($self, $data) = @_; + $data->{forumThreadId} = $self->get("forumThreadId") unless ($data->{forumThreadId}); WebGUI::SQL->setRow("forumThread","forumThreadId",$data); $self->{_properties} = $data; } diff --git a/lib/WebGUI/Forum/Web.pm b/lib/WebGUI/Forum/Web.pm index da14d0daa..42d47fdcd 100644 --- a/lib/WebGUI/Forum/Web.pm +++ b/lib/WebGUI/Forum/Web.pm @@ -1,29 +1,65 @@ -package WebGUI::Discuss::Web; +package WebGUI::Forum::Web; -use WebGUI::Discuss; -use WebGUI::Discuss::Post; -use WebGUI::Discuss::Thread; +use WebGUI::DateTime; +use WebGUI::Forum; +use WebGUI::Forum::Post; +use WebGUI::Forum::Thread; +use WebGUI::HTML::Filter; use WebGUI::Session; +use WebGUI::Template; +sub getPostTemplateVars { + my ($post, $thread, $forum) = @_; + my %var; + $var->{'post.subject'} = WebGUI::HTML::filter($post->get("subject"),"none"); + $var->{'post.message'} = WebGUI::HTML::filter($post->get("message"),$forum->get("filterPosts")); + if ($forum->get("allowReplacements")) { + my $sth = WebGUI::SQL->read("select pattern,replaceWith from forumReplacement"); + while (my ($pattern,$replaceWith) = $sth->array) { + $var->{'post.message'} =~ s/\Q$pattern/$replaceWith/g; + } + $sth->finish; + } + $var->{'post.date'} = WebGUI::DateTime::epochToHuman($post->get("dateOfPost"),"%z"); + $var->{'post.time'} = WebGUI::DateTime::epochToHuman($post->get("dateOfPost"),"%Z"); + $var->{'post.views'} = $post->get("views"); + $var->{'post.status'} = getStatus($post->get("status")); + $var->{'post.isLocked'} = $post->isLocked; + $var->{'post.isModerator'} = $forum->isModerator; + $var->{'post.username'} = $post->get("username"); + $var->{'post.userId'} = $post->get("userId"); + $var->{'post.userProfile'} = WebGUI::URL::page("op=viewProfile&uid=".$post->get("userId")); + $var->{'post.id'} = $post->get("forumPostId"); + $var->{'post.full'} = WebGUI::Template::process(WebGUI::Template::get($forum->get("postTemplate"),"Forum/Post"), \%var); +} -sub post { +sub getStatus { } -sub postSave { +sub www_post { + +} + +sub www_postSave { my $forumId = $session{form}{forumId}; my $threadId = $session{form}{forumThreadId}; if ($session{form}{parentId} > 0) { - my $parentPost = WebGUI::Discuss::Post->new($session{form}{parentId}); + my $parentPost = WebGUI::Forum::Post->new($session{form}{parentId}); $forumId = $parentPost->getThread->get("forumId"); $threadId = $parentPost->get("forumThreadId"); } if ($threadId < 1) { - $threadId = WebGUI::Discuss::Thread->create({ + $threadId = WebGUI::Forum::Thread->create({ forumId=>$forumId }); } } +sub www_viewPost { + +} + + 1; diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index 928a5f57a..6327b56d5 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -32,7 +32,6 @@ A package for manipulating and massaging HTML. use WebGUI::HTML; $html = WebGUI::HTML::cleanSegment($html); $html = WebGUI::HTML::filter($html); - $html = WebGUI::HTML::searchAndReplace($html); =head1 METHODS @@ -128,32 +127,6 @@ sub filter { } } -#------------------------------------------------------------------- - -=head2 searchAndReplace ( html ) - -Replaces all occurrences of strings specified in the config file. - -=over - -=item html - -The HTML segment you want to have search and replaced. - -=back - -=cut - -sub searchAndReplace { - my $content = shift; - foreach my $search (keys %{$session{config}{searchAndReplace}}) { - my $replace = $session{config}{searchAndReplace}{$search}; - $content =~ s/\Q$search/$replace/g; - } - return $content; -} - - 1;