migrating uss and forum to collaboration
This commit is contained in:
parent
4dd121e634
commit
2abe8c078c
9 changed files with 1116 additions and 1663 deletions
|
|
@ -31,6 +31,64 @@ use WebGUI::Asset::USS_submission;
|
|||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub appendTemplateLabels {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
my $i18n = WebGUI::International->new("Collaboration");
|
||||
$var->{'question.label'} = WebGUI::International::get(85,"USS");
|
||||
$var->{'title.label'} = WebGUI::International::get(35,"USS");
|
||||
$var->{'link.header.label'} = WebGUI::International::get(90,"USS");
|
||||
$var->{'visitorName.label'} = WebGUI::International::get(438);
|
||||
$var->{'question.header.label'} = WebGUI::International::get(84,"USS");
|
||||
$var->{'submission.header.label'} = WebGUI::International::get(19,"USS");
|
||||
$var->{'body.label'} = WebGUI::International::get(31,"USS");
|
||||
$var->{'answer.label'} = WebGUI::International::get(86,"USS");
|
||||
$var->{'description.label'} = WebGUI::International::get(85);
|
||||
$var->{'contentType.label'} = WebGUI::International::get(1007);
|
||||
$var->{'startDate.label'} = WebGUI::International::get(497);
|
||||
$var->{'endDate.label'} = WebGUI::International::get(498);
|
||||
$var->{'url.label'} = WebGUI::International::get(91,"USS");
|
||||
$var->{'newWindow.label'} = WebGUI::International::get(92,"USS");
|
||||
$var->{'newpost.header'} = WebGUI::International::get(1064);
|
||||
$var->{'sticky.label'} = WebGUI::International::get(1013);
|
||||
$var->{'subscribe.label'} = WebGUI::International::get(873);
|
||||
$var->{'lock.label'} = WebGUI::International::get(1012);
|
||||
$var->{'message.label'} = WebGUI::International::get(230);
|
||||
$var->{'subject.label'} = WebGUI::International::get(229);
|
||||
$var->{'image.label'} = WebGUI::International::get(32,"USS");
|
||||
$var->{'attachment.label'} = WebGUI::International::get(33,"USS");
|
||||
$var->{"user.label"} = "User";
|
||||
$var->{"title.label"} = "Title";
|
||||
$var->{"subject.label"} = "Subject";
|
||||
$var->{"status.label"} = "Status";
|
||||
$var->{"date.label"} = "Date";
|
||||
$var->{"approve.label"} = "Approve";
|
||||
$var->{"delete.label"} = "Delete";
|
||||
$var->{"deny.label"} = "Deny";
|
||||
$var->{"edit.label"} = "Edit";
|
||||
$var->{"reply.label"} = "Reply";
|
||||
$var->{"views.label"} = "Views";
|
||||
$var->{"rating.label"} = "Rating";
|
||||
$var->{"rate.label"} = "Rate";
|
||||
$var->{"layout.label"} = "Layout";
|
||||
$var->{"nested.label"} = "Nested";
|
||||
$var->{"threaded.label"} = "Threaded";
|
||||
$var->{"flat.label"} = "Flat";
|
||||
$var->{"lock.label"} = "Lock";
|
||||
$var->{"unlock.label"} = "Unlock";
|
||||
$var->{"stick.label"} = "Make Sticky";
|
||||
$var->{"unstick.label"} = "Unstick";
|
||||
$var->{"subscribe.label"} = "Subscribe";
|
||||
$var->{"unsubscribe.label"} = "Unsubscribe";
|
||||
$var->{"previous.label"} = "Previous";
|
||||
$var->{"next.label"} = "Next";
|
||||
$var->{"next.label"} = "Search";
|
||||
$var->{"back.label"} = "Back";
|
||||
$var->{"add.label"} = "Add";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub canModerate {
|
||||
my $shift;
|
||||
|
|
@ -190,18 +248,10 @@ sub definition {
|
|||
fieldType=>"template",
|
||||
defaultValue=>undef
|
||||
},
|
||||
postPreviewTemplateId =>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>undef
|
||||
},
|
||||
postFormTemplateId =>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>undef
|
||||
},
|
||||
postTemplateId =>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>undef
|
||||
},
|
||||
threadTemplateId =>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>undef
|
||||
|
|
@ -256,24 +306,12 @@ sub getEditForm {
|
|||
-namespace=>"Collaboration/Thread",
|
||||
-label=>"Thread Template"
|
||||
);
|
||||
$tabform->getTab("display")->template(
|
||||
-name=>"postTemplateId",
|
||||
-value=>$self->getValue("postTemplateId"),
|
||||
-namespace=>"Collaboration/Post",
|
||||
-label=>"Post Template"
|
||||
);
|
||||
$tabform->getTab("display")->template(
|
||||
-name=>"postFormTemplateId",
|
||||
-value=>$self->getValue("postFormTemplateId"),
|
||||
-namespace=>"Collaboration/PostForm",
|
||||
-label=>"Post Form Template"
|
||||
);
|
||||
$tabform->getTab("display")->template(
|
||||
-name=>"postPreviewTemplateId",
|
||||
-value=>$self->getValue("postPreviewTemplateId"),
|
||||
-namespace=>"Collaboration/Preview",
|
||||
-label=>"Post Preview Template"
|
||||
);
|
||||
$tabform->getTab("display")->template(
|
||||
-name=>"searchTemplateId",
|
||||
-value=>$self->getValue("SearchTemplateId"),
|
||||
|
|
@ -400,7 +438,7 @@ sub getName {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 formatNewThreadURL ( callback, forumId )
|
||||
=head2 getNewThreadUrl( )
|
||||
|
||||
Formats the url to start a new thread.
|
||||
|
||||
|
|
@ -408,7 +446,20 @@ Formats the url to start a new thread.
|
|||
|
||||
sub getNewThreadUrl {
|
||||
my $self = shift;
|
||||
$self->getUrl("func=add&class=WebGUI::Asset::Post");
|
||||
$self->getUrl("func=add&class=WebGUI::Asset::Post::Thread");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getRssUrl ( )
|
||||
|
||||
Formats the url to start a new thread.
|
||||
|
||||
=cut
|
||||
|
||||
sub getRssUrl {
|
||||
my $self = shift;
|
||||
$self->getUrl("func=viewRSS");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -599,19 +650,6 @@ sub setLastPost {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub status {
|
||||
my $self = shift;
|
||||
my $status = shift;
|
||||
if ($status eq "approved") {
|
||||
return "Approved";
|
||||
} elsif ($status eq "denied") {
|
||||
return "Denied";
|
||||
} elsif ($status eq "pending") {
|
||||
return "Pending";
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 subscribe ( )
|
||||
|
|
@ -646,55 +684,70 @@ sub unsubscribe {
|
|||
#-------------------------------------------------------------------
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $scratchSortBy = $self->getId."_sortBy";
|
||||
my $scratchSortDir = $self->getId."_sortDir";
|
||||
if($session{scratch}{$scratchSortBy} ne $session{form}{sortBy}){
|
||||
WebGUI::Session::setScratch($scratchSortBy,$session{form}{sortBy});
|
||||
WebGUI::Session::setScratch($scratchSortDir, "desc");
|
||||
}else{
|
||||
my $sortDir;
|
||||
if($session{scratch}{$scratchSortDir} eq "asc"){
|
||||
$sortDir = "desc";
|
||||
}else{
|
||||
$sortDir = "asc";
|
||||
}
|
||||
WebGUI::Session::setScratch($scratchSortDir, $sortDir);
|
||||
}
|
||||
my $numResults = $self->get("threadsPerPage");
|
||||
my %var;
|
||||
$var{"readmore.label"} = "Read More";
|
||||
$var{"responses.label"} = "Responses";
|
||||
$var{canPost} = $self->canPost;
|
||||
$var{"post.url"} = $self->getUrl('func=add&class=WebGUI::Asset::Thread');
|
||||
$var{"post.label"} = "Add a post.";
|
||||
$var{"addquestion.label"} = "Add a question.";
|
||||
$var{"addlink.label"} = "Add a link.";
|
||||
$var{"search.label"} = "Search";
|
||||
$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} = $self->canModerate;
|
||||
$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");
|
||||
$var{canPost} = $self->canPost;
|
||||
$var{"post.url"} = $self->getNewThreadUrl;
|
||||
$var{"rss.url"} = $self->getRssUrl;
|
||||
$var{canModerate} = $self->canModerate;
|
||||
WebGUI::Style::setLink($var{"rss.url"},{ rel=>'alternate', type=>'application/rss+xml', title=>'RSS' });
|
||||
#$var{"search.Form"} = WebGUI::Search::form({func=>'view',search=>1});
|
||||
#$var{"search.url"} = WebGUI::Search::toggleURL("func=view");
|
||||
my $constraints;
|
||||
if ($session{scratch}{search}) {
|
||||
$numResults = $session{scratch}{numResults};
|
||||
$constraints = WebGUI::Search::buildConstraints([qw(Post.username asset.synopsis asset.title Post.content Post.userDefined1 Post.userDefined2 Post.userDefined3 Post.userDefined4 Post.userDefined5)]);
|
||||
}
|
||||
if ($constraints ne "") {
|
||||
$constraints = "Post.status='approved' and ".$constraints;
|
||||
} else {
|
||||
#if ($session{scratch}{search}) {
|
||||
# $numResults = $session{scratch}{numResults};
|
||||
# $constraints = WebGUI::Search::buildConstraints([qw(Post.username asset.synopsis asset.title Post.content Post.userDefined1 Post.userDefined2 Post.userDefined3 Post.userDefined4 Post.userDefined5)]);
|
||||
# }
|
||||
# if ($constraints ne "") {
|
||||
# $constraints = "Post.status='approved' and ".$constraints;
|
||||
# } else {
|
||||
$constraints = "(Post.status='approved' or (asset.ownerUserId=".quote($session{user}{userId})." and asset.ownerUserId<>'1')";
|
||||
if ($var{canModerate}) {
|
||||
$constraints .= " or Post.status='pending'";
|
||||
}
|
||||
$constraints .= ")";
|
||||
}
|
||||
#}
|
||||
my $p = WebGUI::Paginator->new($self->getUrl,$numResults);
|
||||
my $sql = "select asset.*,Post.*
|
||||
my $sql = "select *
|
||||
from Thread
|
||||
left join asset on Thread.assetId=asset.parentId
|
||||
left join asset on Thread.assetId=asset.assetId
|
||||
left join Post on Post.assetId=asset.assetId
|
||||
where Thread.parentId=".quote($self->getId)." and asset.state='published' and asset.className='WebGUI::Asset::Post' and $constraints
|
||||
where Thread.parentId=".quote($self->getId)." and asset.state='published' and asset.className='WebGUI::Asset::Post::Thread' 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 $post = WebGUI::Asset::USS_submission->newByPropertyHashRef($row);
|
||||
my $controls = deleteIcon('func=delete',$post->getUrl,"Delete").editIcon('func=edit',$post->getUrl);
|
||||
my $post = WebGUI::Asset::Post->newByPropertyHashRef($row);
|
||||
$post->{_parent} = $self; # caching parent for efficiency
|
||||
my $controls = deleteIcon('func=delete',$post->get("url"),"Delete").editIcon('func=edit',$post->get("ur"));
|
||||
if ($self->get("sortBy") eq "lineage") {
|
||||
if ($self->get("sortOrder") eq "desc") {
|
||||
$controls .= moveUpIcon('func=demote',$post->get("url")).moveDownIcon('func=promote',$post->get("url"));
|
||||
|
|
@ -712,8 +765,8 @@ sub view {
|
|||
"id"=>$post->getId,
|
||||
"url"=>$post->getUrl,
|
||||
"synopsis"=>$post->get("synopsis"),
|
||||
"content"=>WebGUI::HTML::format(WebGUI::HTML::filter($post->get("content"),$self->get("filterCode")),$post->get("contentType")),
|
||||
"reply.count"=>$post->getResponseCount,
|
||||
"content"=>$self->formatContent,
|
||||
"reply.count"=>$post->get("replies"),
|
||||
"title"=>$post->get("title"),
|
||||
"userDefined1"=>$post->get("userDefined1"),
|
||||
"userDefined2"=>$post->get("userDefined2"),
|
||||
|
|
@ -727,11 +780,15 @@ sub view {
|
|||
# "submission.image"=>$submission->getImageUrl,
|
||||
"date.submitted"=>epochToHuman($post->get("dateSubmitted")),
|
||||
"date.updated"=>epochToHuman($post->get("dateUpdated")),
|
||||
"userProfile.url"=>$post->getUrl("op=viewProfile&uid=".$post->get("ownerUserId")),
|
||||
"edit.url"=>$submission->getUrl("func=edit"),
|
||||
'controls'=>$submission->getToolbar,
|
||||
"userProfile.url"=>$post->getUserProfileUrl,
|
||||
"edit.url"=>$post->getEditUrl,
|
||||
'controls'=>$controls,
|
||||
'inDateRange'=>$inDateRange,
|
||||
"currentUserIsOwner"=>($session{user}{userId} eq $post->get("ownerUserId") && $session{user}{userId} ne "1")
|
||||
"isSecond"=>(($i+1)%2==0),
|
||||
"isThird"=>(($i+1)%3==0),
|
||||
"isFourth"=>(($i+1)%4==0),
|
||||
"isFifth"=>(($i+1)%5==0),
|
||||
"currentUserIsPoster"=>$post->isPoster
|
||||
});
|
||||
$i++;
|
||||
}
|
||||
|
|
@ -749,28 +806,22 @@ sub www_edit {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_search ( caller )
|
||||
=head2 www_search ( )
|
||||
|
||||
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 $self = shift;
|
||||
WebGUI::Session::setScratch($self->getId."_all",$session{form}{all});
|
||||
WebGUI::Session::setScratch($self->getId."_atLeastOne",$session{form}{atLeastOne});
|
||||
WebGUI::Session::setScratch($self->getId."_exactPhrase",$session{form}{exactPhrase});
|
||||
WebGUI::Session::setScratch($self->getId."_without",$session{form}{without});
|
||||
WebGUI::Session::setScratch($self->getId."_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::formHeader({action=>$self->getUrl});
|
||||
$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} });
|
||||
|
|
@ -879,56 +930,34 @@ sub www_unsubscribe {
|
|||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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);
|
||||
# format the date according to rfc 822 (for RSS export)
|
||||
my @_months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
||||
sub _get_rfc822_date {
|
||||
my ($time) = @_;
|
||||
my ($year, $mon, $mday, $hour, $min, $sec) = WebGUI::DateTime::localtime($time);
|
||||
my $month = $_months[$mon - 1];
|
||||
return sprintf("%02d %s %04d %02d:%02d:%02d GMT",
|
||||
$mday, $month, $year, $hour, $min, $sec);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# encode a string to include in xml (for RSS export)
|
||||
sub _xml_encode {
|
||||
my $text = shift;
|
||||
$text =~ s/&/&/g;
|
||||
$text =~ s/</</g;
|
||||
$text =~ s/\]\]>/\]\]>/g;
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# 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 $self = shift;
|
||||
$self->logView() if ($session{setting}{passiveProfilingEnabled});
|
||||
my $encTitle = _xml_encode($self->get("title"));
|
||||
my $encDescription = _xml_encode($self->get("description"));
|
||||
my $encUrl = _xml_encode($self->getUrl);
|
||||
my $xml = qq~<?xml version="1.0"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
|
|
@ -936,25 +965,21 @@ sub www_viewRSS {
|
|||
<link>$encUrl</link>
|
||||
<description>$encDescription</description>
|
||||
~;
|
||||
|
||||
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 $sth = WebGUI::SQL->read("select *
|
||||
from Thread
|
||||
left join asset on Thread.assetId=asset.parentId
|
||||
left join Post on Post.assetId=asset.assetId
|
||||
where Thread.parentId=".quote($self->getId)." and asset.state='published'
|
||||
and asset.className='WebGUI::Asset::Post::Thread' and Post.status='approved'
|
||||
order by ".$self->getValue("sortBy")." ".$self->getValue("sortOrder"));
|
||||
my $i = 1;
|
||||
while (my $data = $sth->hashref) {
|
||||
my $post = WebGUI::Asset::Post::Thread->newByPropertyHashRef($data);
|
||||
|
||||
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);
|
||||
|
||||
my $encUrl = _xml_encode($post->getUrl);
|
||||
my $encTitle = _xml_encode($post->get("title"));
|
||||
my $encPubDate = _xml_encode(_get_rfc822_date($post->get("dateUpdated")));
|
||||
my $encDescription = _xml_encode($self->get("synopsis"));
|
||||
$xml .= qq~
|
||||
<item>
|
||||
<title>$encTitle</title>
|
||||
|
|
@ -964,6 +989,8 @@ sub www_viewRSS {
|
|||
<pubDate>$encPubDate</pubDate>
|
||||
</item>
|
||||
~;
|
||||
$i++;
|
||||
last if ($i == $$self->get("threadsPerPage");
|
||||
}
|
||||
|
||||
$xml .=qq~
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue