continuing work on new discussion system
This commit is contained in:
parent
6fc3817f85
commit
df6d6fe93d
8 changed files with 223 additions and 25 deletions
|
|
@ -26,14 +26,14 @@ create table forumReplacement (
|
|||
|
||||
create table forumPost (
|
||||
forumPostId int not null primary key,
|
||||
parentId int not null,
|
||||
parentId int not null default 0,
|
||||
forumThreadId int not null,
|
||||
userId int not null,
|
||||
username varchar(30),
|
||||
subject varchar(255),
|
||||
message text,
|
||||
dateOfPost int,
|
||||
views int,
|
||||
views int not null default 0,
|
||||
status varchar(30) not null default 'approved',
|
||||
contentType varchar(30) not null default 'some html'
|
||||
);
|
||||
|
|
@ -114,3 +114,21 @@ insert into international (internationalId,languageId,namespace,message,lastUpda
|
|||
delete from template where templateId=1 and namespace='DataForm';
|
||||
INSERT INTO template VALUES (1,'Mail Form','<tmpl_if displayTitle>\n <h1><tmpl_var title></h1>\n</tmpl_if>\n\n<tmpl_loop error_loop>\n <li><b><tmpl_var error.message></b>\n</tmpl_loop>\n\n\n<tmpl_if description>\n <tmpl_var description><p />\n</tmpl_if>\n\n<tmpl_if canEdit>\n <a href=\"<tmpl_var entryList.url>\"><tmpl_var entryList.label></a>\n · <a href=\"<tmpl_var export.tab.url>\"><tmpl_var export.tab.label></a>\n <tmpl_if entryId>\n · <a href=\"<tmpl_var delete.url>\"><tmpl_var delete.label></a>\n </tmpl_if>\n <tmpl_if session.var.adminOn>\n · <a href=\"<tmpl_var addField.url>\"><tmpl_var addField.label></a>\n </tmpl_if>\n <p /> \n</tmpl_if>\n\n<tmpl_var form.start>\n<table>\n<tmpl_loop field_loop>\n <tmpl_unless field.isHidden>\n <tr><td class=\"formDescription\" valign=\"top\">\n <tmpl_if session.var.adminOn><tmpl_if canEdit><tmpl_var field.controls></tmpl_if></tmpl_if>\n <tmpl_var field.label>\n </td><td class=\"tableData\" valign=\"top\">\n <tmpl_if field.isDisplayed>\n <tmpl_var field.value>\n <tmpl_else>\n <tmpl_var field.form>\n </tmpl_if>\n <tmpl_if field.required>*</tmpl_if>\n <span class=\"formSubtext\"><br /><tmpl_var field.subtext></span>\n </td></tr>\n </tmpl_unless>\n</tmpl_loop>\n<tr><td></td><td><tmpl_var form.send></td></tr>\n</table>\n\n<tmpl_var form.end>\n','DataForm');
|
||||
|
||||
insert into incrementer values ('forumId',1000);
|
||||
insert into incrementer values ('forumThreadId',1000);
|
||||
insert into incrementer values ('forumPostId',1000);
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1010;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1010,1,'WebGUI','Text', 1060433369,'A content type of text.');
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1011;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1011,1,'WebGUI','Code', 1060433339,'A content type of source code.');
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1009;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1009,1,'WebGUI','HTML', 1060433286,'A content type of HTML.');
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1008;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1008,1,'WebGUI','Mixed Text and HTML', 1060433234,'A content type of mixed HTML and text.');
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1007;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1007,1,'WebGUI','Content Type', 1060432032,'The type of content to be posted, like HTML, source code, text, etc.');
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1013;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1013,1,'WebGUI','Make sticky?', 1060434033,'A message indicating whether the moderator wants to make this message stay at the top of the discussion.');
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=1012;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1012,1,'WebGUI','Lock this thread?', 1060433963,'A message indicating whether the moderator wants to lock the thread as he posts.');
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,11 @@ Base forms package. Eliminates some of the normal code work that goes along with
|
|||
$html = WebGUI::Form::checkbox({name=>"whichOne", value=>"red"});
|
||||
$html = WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days});
|
||||
$html = WebGUI::Form::combo({name=>"fruit",options=>\%fruit});
|
||||
$html = WebGUI::Form::contentType({name=>"contentType");
|
||||
$html = WebGUI::Form::date({name=>"endDate", value=>$endDate});
|
||||
$html = WebGUI::Form::dateTime({name=>"begin", value=>$begin});
|
||||
$html = WebGUI::Form::email({name=>"emailAddress"});
|
||||
$html = WebGUI::Form::fieldType({name=>"fieldType",types=>\%supportedTypes});
|
||||
$html = WebGUI::Form::fieldType({name=>"fieldType");
|
||||
$html = WebGUI::Form::file({name=>"image"});
|
||||
$html = WebGUI::Form::formHeader();
|
||||
$html = WebGUI::Form::filterContent({value=>"javascript"});
|
||||
|
|
@ -258,6 +259,63 @@ sub combo {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 contentType ( hashRef )
|
||||
|
||||
Returns a content type select list field. This is usually used to help tell WebGUI how to treat posted content.
|
||||
|
||||
=over
|
||||
|
||||
=item name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=item types
|
||||
|
||||
An array reference of field types to be displayed. The types are "mixed", "html", "code", and "text". Defaults to all.
|
||||
|
||||
=item value
|
||||
|
||||
The default value for this form element. Defaults to "mixed".
|
||||
|
||||
=item extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub contentType {
|
||||
my (%hash, $output, $type);
|
||||
tie %hash, 'Tie::IxHash';
|
||||
# NOTE: What you are about to see is bad code. Do not attempt this
|
||||
# without adult supervision. =) It was done this way because a huge
|
||||
# if/elsif construct executes much more quickly than a bunch of
|
||||
# unnecessary database hits.
|
||||
my @types = qw(mixed html code text);
|
||||
$_[0]->{types} = \@types unless ($_[0]->{types});
|
||||
foreach $type (@{$_[0]->{types}}) {
|
||||
if ($type eq "text") {
|
||||
$hash{text} = WebGUI::International::get(1010);
|
||||
} elsif ($type eq "mixed") {
|
||||
$hash{code} = WebGUI::International::get(1008);
|
||||
} elsif ($type eq "code") {
|
||||
$hash{code} = WebGUI::International::get(1011);
|
||||
} elsif ($type eq "html") {
|
||||
$hash{html} = WebGUI::International::get(1009);
|
||||
}
|
||||
}
|
||||
return selectList({
|
||||
options=>\%hash,
|
||||
name=>$_[0]->{name},
|
||||
value=>$_[0]->{value},
|
||||
extras=>$_[0]->{extras}
|
||||
});
|
||||
}
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 date ( hashRef )
|
||||
|
||||
Returns a date field.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ This package helps in the processing of the form variables that are returned fro
|
|||
$value = WebGUI::FormProcessor::checkbox("whichOne");
|
||||
$value = WebGUI::FormProcessor::checkList("dayOfWeek");
|
||||
$value = WebGUI::FormProcessor::combo("fruit");
|
||||
$value = WebGUI::FormProcessor::contentType("text");
|
||||
$value = WebGUI::FormProcessor::date("endDate");
|
||||
$value = WebGUI::FormProcessor::dateTime("whenToDoIt");
|
||||
$value = WebGUI::FormProcessor::email("emailAddress");
|
||||
|
|
@ -132,6 +133,26 @@ sub combo {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 contentType ( name )
|
||||
|
||||
Returns a content type. Defaults to "mixed".
|
||||
|
||||
=over
|
||||
|
||||
=item name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub contentType {
|
||||
return ($session{form}{$_[0]} || "mixed");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 date ( name )
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ sub addView {
|
|||
|
||||
sub create {
|
||||
my ($self, $data) = @_;
|
||||
$data->{forumPostId} = "new";
|
||||
$data->{dateOfPost} = WebGUI::DateTime::time();
|
||||
my $forumPostId = WebGUI::SQL->setRow("forumPost","forumPostId",$data);
|
||||
$data->{forumPostId} = "new";
|
||||
my $forumPostId = WebGUI::SQL->setRow("forumPost","forumPostId", $data);
|
||||
$self = WebGUI::Forum::Post->new($forumPostId);
|
||||
if ($data->{parentId} > 0) {
|
||||
$self->getThread->addReply($forumPostId,$self->get("dateOfPost"));
|
||||
|
|
@ -34,10 +34,10 @@ sub get {
|
|||
|
||||
sub getReplies {
|
||||
my ($self) = @_;
|
||||
my @replies;
|
||||
my @replies = ();
|
||||
my $sth = WebGUI::SQL->read("select forumPostId from forumPost where parentId=".$self->get("forumPostId")." order by forumPostId");
|
||||
while (my ($postId) = $sth->array) {
|
||||
push(@replies,WebGUI::Forum::Post->new($postId));
|
||||
while (my @data = $sth->array) {
|
||||
push(@replies,WebGUI::Forum::Post->new($data[0]));
|
||||
}
|
||||
$sth->finish;
|
||||
return \@replies;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package WebGUI::Forum::Thread;
|
||||
|
||||
use strict;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Forum;
|
||||
use WebGUI::Forum::Post;
|
||||
use WebGUI::Session;
|
||||
|
|
@ -8,7 +9,7 @@ use WebGUI::SQL;
|
|||
|
||||
sub addReply {
|
||||
my ($self, $dateOfReply) = @_;
|
||||
WebGUI::SQL->write("update forumThread set replies=replies+1, lastR where forumThreadId=".$self->get("forumThreadId"));
|
||||
WebGUI::SQL->write("update forumThread set replies=replies+1, lastReply=".WebGUI::DateTime::time()." where forumThreadId=".$self->get("forumThreadId"));
|
||||
#add method to notify users for subscriptions
|
||||
}
|
||||
|
||||
|
|
@ -20,17 +21,16 @@ sub addView {
|
|||
sub create {
|
||||
my ($self, $data, $postData) = @_;
|
||||
$data->{forumThreadId} = "new";
|
||||
my $forumThreadId = WebGUI::SQL->setRow("forumThread","forumThreadId",$data);
|
||||
$self = WebGUI::Forum::Thread->new($forumThreadId);
|
||||
$postData->{forumThreadId} = $forumThreadId;
|
||||
$postData->{forumThreadId} = WebGUI::SQL->setRow("forumThread","forumThreadId", $data);
|
||||
$self = WebGUI::Forum::Thread->new($postData->{forumThreadId});
|
||||
$postData->{parentId} = 0;
|
||||
my $post = WebGUI::Discuss::Post->create($postData);
|
||||
my $post = WebGUI::Forum::Post->create($postData);
|
||||
$self->set({
|
||||
rootPostId=>$post->get("forumPostId"),
|
||||
lastPostId=>$post->get("forumPostId"),
|
||||
lastPostDate=>$post->get("dateOfPost")
|
||||
});
|
||||
$self->{_post}{$post->{forumPostId}} = $post;
|
||||
$self->{_post}{$post->get("forumPostId")} = $post;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,12 @@ sub viewForum {
|
|||
my $threads = $p->getPageData;
|
||||
foreach my $thread (@{$threads}) {
|
||||
my $root = WebGUI::Forum::Post->new($thread->{rootPostId});
|
||||
my $last = WebGUI::Forum::Post->new($thread->{lastPostId});
|
||||
my $last;
|
||||
if ($thread->{rootPostId} == $thread->{lastPostId}) { #saves the lookup if it's the same id
|
||||
$last = $root;
|
||||
} else {
|
||||
$last = WebGUI::Forum::Post->new($thread->{lastPostId});
|
||||
}
|
||||
push(@thread_loop,{
|
||||
'thread.views'=>$thread->{views},
|
||||
'thread.replies'=>$thread->{replies},
|
||||
|
|
@ -166,6 +171,7 @@ sub www_post {
|
|||
$var->{isReply} = ($session{form}{parentId} ne "");
|
||||
$var->{isEdit} = ($session{form}{forumPostId} ne "");
|
||||
$var->{isVisitor} = ($session{user}{userId} == 1);
|
||||
$var->{isNewMessage} = ($var->{isNewThread} || $var->{isReply});
|
||||
$var->{'form.begin'} = WebGUI::Form::formHeader({
|
||||
action=>$callback
|
||||
});
|
||||
|
|
@ -187,15 +193,24 @@ sub www_post {
|
|||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
if ($var->{isNewMessage}) {
|
||||
$var->{'subscribe.label'} = WebGUI::International::get(873);
|
||||
$var->{'subscribe.form'} = WebGUI::Form::yesNo({
|
||||
name=>'subscribe',
|
||||
value=>1
|
||||
});
|
||||
if ($forum->isModerator) {
|
||||
$var->{'sticky.label'} = 'Make Sticky';
|
||||
$var->{'sticky.form'} = WebGUI::Form::yesNo({
|
||||
name=>'sticky',
|
||||
$var->{'lock.label'} = WebGUI::International::get(1012);
|
||||
$var->{'lock.form'} = WebGUI::Form::yesNo({
|
||||
name=>'isLocked',
|
||||
value=>0
|
||||
});
|
||||
}
|
||||
|
|
@ -206,6 +221,10 @@ sub www_post {
|
|||
$message = $post->get("message");
|
||||
$forum = $post->getThread->getForum;
|
||||
}
|
||||
$var->{'contentType.label'} = WebGUI::International::get(1007);
|
||||
$var->{'contentType.form'} = WebGUI::Form::contentType({
|
||||
name=>'contentType'
|
||||
});
|
||||
$var->{isModerator} = $forum->isModerator;
|
||||
$var->{allowReplacements} = $forum->get("allowReplacements");
|
||||
if ($forum->get("allowRichEdit")) {
|
||||
|
|
@ -244,15 +263,28 @@ sub www_postSave {
|
|||
my ($callback) = @_;
|
||||
my $forumId = $session{form}{forumId};
|
||||
my $threadId = $session{form}{forumThreadId};
|
||||
my $postId = $session{form}{forumPostId};
|
||||
my $thread;
|
||||
if ($session{form}{parentId} > 0) {
|
||||
my $parentPost = WebGUI::Forum::Post->new($session{form}{parentId});
|
||||
$forumId = $parentPost->getThread->get("forumId");
|
||||
$threadId = $parentPost->get("forumThreadId");
|
||||
return www_viewThread($callback,$postId);
|
||||
}
|
||||
if ($threadId < 1) {
|
||||
$threadId = WebGUI::Forum::Thread->create({
|
||||
forumId=>$forumId
|
||||
if ($forumId) {
|
||||
$thread = WebGUI::Forum::Thread->create({
|
||||
forumId=>$forumId,
|
||||
isSticky=>$session{form}{isSticky},
|
||||
isLocked=>$session{form}{isLocked}
|
||||
}, {
|
||||
subject=>$session{form}{subject},
|
||||
message=>$session{form}{message},
|
||||
userId=>$session{user}{userId},
|
||||
username=>($session{form}{visitorName} || $session{user}{alias}),
|
||||
contentType=>$session{form}{contentType}
|
||||
});
|
||||
$thread->subscribe($session{user}{userId}) if ($session{form}{subscribe});
|
||||
return viewForum($callback, $forumId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ Package that makes HTML forms typed data and significantly reduces the code need
|
|||
-options=>\%fruit,
|
||||
-label=>"Choose a fruit or enter your own."
|
||||
);
|
||||
$f->contentType(
|
||||
-name=>"contentType"
|
||||
);
|
||||
$f->date(
|
||||
-name=>"endDate",
|
||||
-label=>"End Date",
|
||||
|
|
@ -67,7 +70,6 @@ Package that makes HTML forms typed data and significantly reduces the code need
|
|||
);
|
||||
$f->fieldType(
|
||||
-name=>"dataType",
|
||||
-options=>\%supportedTypes,
|
||||
-label=>"Type of Field"
|
||||
);
|
||||
$f->file(
|
||||
|
|
@ -420,6 +422,73 @@ sub combo {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 contentType ( name, types [ label, value, extras, subtext, uiLevel ] )
|
||||
|
||||
Adds a content type select list field to this form.
|
||||
|
||||
=over
|
||||
|
||||
=item name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=item types
|
||||
|
||||
An array reference of field types to be displayed. The valid types are "code", "mixed", "html", and "text". Defaults to all types.
|
||||
|
||||
=item label
|
||||
|
||||
The left column label for this form row. Defaults to "Content Type".
|
||||
|
||||
=item value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=item extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=item subtext
|
||||
|
||||
Extra text to describe this form element or to provide special instructions.
|
||||
|
||||
=item uiLevel
|
||||
|
||||
The UI level for this field. See the WebGUI developer's site for details. Defaults to "3".
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub contentType {
|
||||
my ($output);
|
||||
my ($self, @p) = @_;
|
||||
my ($name, $types, $label, $value, $extras, $subtext, $uiLevel) =
|
||||
rearrange([qw(name types label value extras subtext uiLevel)], @p);
|
||||
$uiLevel = 3 if ($uiLevel eq "");
|
||||
if (_uiLevelChecksOut($uiLevel)) {
|
||||
$label = WebGUI::International::get(1007) unless ($label);
|
||||
$output = WebGUI::Form::fieldType({
|
||||
"name"=>$name,
|
||||
"types"=>$types,
|
||||
"value"=>$value,
|
||||
"extras"=>$extras
|
||||
});
|
||||
$output .= _subtext($subtext);
|
||||
$output = $self->_tableFormRow($label,$output);
|
||||
} else {
|
||||
$output = WebGUI::Form::hiddenList({
|
||||
"name"=>$name,
|
||||
types=>$types,
|
||||
"value"=>$value
|
||||
});
|
||||
}
|
||||
$self->{_data} .= $output;
|
||||
}
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 date ( name [ label, value, extras, subtext, size, noDate, uiLevel ] )
|
||||
|
||||
Adds a date row to this form.
|
||||
|
|
|
|||
|
|
@ -272,8 +272,8 @@ Specify the name of one of the incrementers in the incrementer table.
|
|||
|
||||
sub getNextId {
|
||||
my ($id);
|
||||
($id) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId='$_[0]'",$_[1]);
|
||||
WebGUI::SQL->write("update incrementer set nextValue=nextValue+1 where incrementerId='$_[0]'",$_[1]);
|
||||
($id) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId='$_[0]'");
|
||||
WebGUI::SQL->write("update incrementer set nextValue=nextValue+1 where incrementerId='$_[0]'");
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
|
@ -636,7 +636,7 @@ A database handler to use. Defaults to the WebGUI database handler.
|
|||
sub setRow {
|
||||
my ($self, $table, $keyColumn, $data, $dbh) = @_;
|
||||
if ($data->{$keyColumn} eq "new") {
|
||||
$data->{$keyColumn} = WebGUI::SQL->getNextId($keyColumn);
|
||||
$data->{$keyColumn} = getNextId($keyColumn);
|
||||
WebGUI::SQL->write("insert into $table ($keyColumn) values ($data->{$keyColumn})", $dbh);
|
||||
}
|
||||
my (@pairs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue