working on new discussion system
This commit is contained in:
parent
b84c79ab96
commit
a4d391b52a
6 changed files with 81 additions and 52 deletions
|
|
@ -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)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue