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 2ede9d41d..8b2f793e3 100644 --- a/docs/upgrades/upgrade_6.2.11-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.11-6.3.0.pl @@ -532,7 +532,6 @@ while (my ($id, $template, $namespace) = $sth->array) { my $newNamespace; if ($namespace eq "Forum") { $newNamespace = "Collaboration"; - $template = '

'.$template; } elsif ($namespace eq "Forum/PostForm") { $newNamespace = "Collaboration/PostForm"; } elsif ($namespace eq "Forum/Search") { @@ -546,6 +545,8 @@ while (my ($id, $template, $namespace) = $sth->array) { $template =~ s/\//ixsg; $template =~ s/\//ixsg; $template =~ s/\//ixsg; + $template =~ s/forum\.title/collaboration.title/ixsg; + $template =~ s/forum\.description/collaboration.description/ixsg; $template =~ s/forum\.//ixsg; $template =~ s/thread\.list\.url/collaboration.url/ixsg; $template =~ s/thread\.new\.url/add.url/ixsg; @@ -608,8 +609,324 @@ while (my ($id, $template, $namespace) = $sth->array) { WebGUI::SQL->write("update template set template=".quote($template).", namespace=".quote($newNamespace)." where templateId=".quote($id)." and namespace=".quote($namespace)); } $sth->finish; +my $defaultThread = ' + + +

+
+ + + + +
+

+
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+ +
+ +
+
+
+ : + + + + + +
+ :
+
+
+ :
+ : + +     [ 1, 2, 3, 4, 5 ] + +
+ + :     [ | ]
+ + + :
+
+
+
+
+
+ +
+ +
+ + [] + + + [] + [] + +
+
+
+
+
+ + + + + + + + + + + class="currentThread"> + + + + + + +
   
+ +
+ + + + + + +
+ +
+ +
+
+
+ : + + + + + +
+ :
+
+
+ :
+ : + +     [ 1, 2, 3, 4, 5 ] + +
+ + :     [ | ]
+ + + :
+
+
+
+
+
+ +
+ +
+ + [] + + + [] + [] + +
+
+
+
+ +
+ + + + + + +
+
+ +
+ +
+
+
+ : + + + + + +
+ :
+
+
+ :
+ : + +     [ 1, 2, 3, 4, 5 ] + +
+ + :     [ | ]
+ + + :
+
+
+
+
+
+ +
+ +
+ + [] + + + [] + [] + +
+
+
+
+
+ +
+ + + + + + + + +
+ + [] + + + [] + + + [] + + + + [] + + [] + + + [] + + [] + + + + + [] + + [] + + +
+ +'; +WebGUI::SQL->write("update template set template=".quote($defaultThread)." where templateId='25' and namespace='Collaboration/Thread'"); + print "\tMigrating USS templates to collaboration templates\n" unless ($quiet); my $sth = WebGUI::SQL->read("select templateId,template,namespace from template where namespace in ('USS','USS/Submission','USS/SubmissionForm')"); diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 2dda6e3c0..e661ce4b9 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1197,9 +1197,7 @@ sub getLineage { my $cmd = "use ".$className; eval ($cmd); WebGUI::ErrorHandler::fatalError("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@); - my $assetObject = eval{$className->new("new")}; - WebGUI::ErrorHandler::fatalError("Couldn't create new asset for ".$className.". Root cause: ".$@) if ($@); - foreach my $definition (@{$assetObject->definition}) { + foreach my $definition (@{$className->definition}) { unless ($definition->{tableName} eq "asset") { my $tableName = $definition->{tableName}; $tables .= ", $tableName "; @@ -1480,7 +1478,8 @@ Name value pairs to add to the URL in the form of: sub getUrl { my $self = shift; my $params = shift; - my $url = WebGUI::URL::gateway($self->get("url"),$params); + my $url = $self->get("url"); + $url = WebGUI::URL::gateway($url,$params); if ($self->get("encryptPage")) { $url = WebGUI::URL::getSiteURL().$url; $url =~ s/http:/https:/; diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 0fa4b4442..8e35a2372 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -68,13 +68,13 @@ sub canView { #------------------------------------------------------------------- -=head2 chopSubject ( ) +=head2 chopTitle ( ) -Cuts a subject string off at 30 characters. +Cuts a title string off at 30 characters. =cut -sub chopSubject { +sub chopTitle { my $self = shift; return substr($self->get("title"),0,30); } @@ -363,16 +363,17 @@ sub getSynopsisAndContentFromFormPost { #------------------------------------------------------------------- sub getTemplateVars { my $self = shift; - my %var = (%{$self->get}); + my %var = %{$self->get}; $var{"userId"} = $self->get("ownerUserId"); $var{"user.isPoster"} = $self->isPoster; $var{"dateSubmitted.human"} = epochToHuman($self->get("dateSubmitted")); $var{"dateUpdated.human"} = epochToHuman($self->get("dateUpdated")); + $var{'title.short'} = $self->chopTitle; $var{content} = $self->formatContent if ($self->getThread); - $var{canEdit} = $self->canEdit if ($self->getThread); + $var{'user.canEdit'} = $self->canEdit if ($self->getThread); $var{"delete.url"} = $self->getDeleteUrl; $var{"edit.url"} = $self->getEditUrl; @@ -383,7 +384,7 @@ sub getTemplateVars { $var{"reply.url"} = $self->getReplyUrl; $var{'reply.withquote.url'} = $self->getReplyUrl(1); - $var{'url'} = WebGUI::URL::getSiteURL().$self->getUrl; + $var{'url'} = $self->getUrl.'#'.$self->getId; $var{'rating.value'} = $self->get("rating")+0; $var{'rate.url.1'} = $self->getRateUrl(1); @@ -593,6 +594,7 @@ sub notifySubscribers { 'notify.subscription.message' => WebGUI::International::get(875,"WebGUI",$u->profileField("language")) }; $lang{$u->profileField("language")}{var} = $self->getTemplateVars($lang{$u->profileField("language")}{var}); + $lang{$u->profileField("language")}{var}{url} = WebGUI::URL::getSiteURL().$self->getUrl; $lang{$u->profileField("language")}{subject} = WebGUI::International::get(523,"WebGUI",$u->profileField("language")); $lang{$u->profileField("language")}{message} = $self->processTemplate($lang{$u->profileField("language")}{var}, $self->getThread->getParent->get("notificationTemplateId")); } @@ -670,10 +672,10 @@ sub rate { WebGUI::SQL->write("insert into Post_rating (assetId,userId,ipAddress,dateOfRating,rating) values (" .quote($self->getId).", ".quote($session{user}{userId}).", ".quote($session{env}{REMOTE_ADDR}).", ".WebGUI::DateTime::time().", $rating)"); - my ($count) = WebGUI::SQL->quickArray("select count(*) from Post_rating where postId=".quote($self->getId)); + my ($count) = WebGUI::SQL->quickArray("select count(*) from Post_rating where assetId=".quote($self->getId)); $count = $count || 1; - my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from Post_rating where postId=".quote($self->getId)); - my $average = round($sum/$count); + my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from Post_rating where assetId=".quote($self->getId)); + my $average = WebGUI::Utility::round($sum/$count); $self->update({rating=>$average}); $self->getThread->rate; } @@ -954,7 +956,7 @@ This is here to stop people from duplicating posts by hitting refresh in their b sub www_redirectToParent { my $self = shift; - WebGUI::HTTP::setRedirect($self->getThread->getParent->getUrl); + WebGUI::HTTP::setRedirect($self->getParent->getUrl); } diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index b75055944..b621539f1 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -21,6 +21,7 @@ use WebGUI::Paginator; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; +use WebGUI::Utility; our @ISA = qw(WebGUI::Asset::Post); @@ -127,7 +128,7 @@ sub getName { #------------------------------------------------------------------- -=head2 getLayoutUrl ( layout [, postId] ) +=head2 getLayoutUrl ( layout ) Formats the url to change the layout of a thread. @@ -135,35 +136,26 @@ Formats the url to change the layout of a thread. A string indicating the type of layout to use. Can be flat, nested, or threaded. -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getLayoutUrl { my $self = shift; my $layout = shift; - my $postId = shift || $self->get("rootPostId"); - return $self->getUrl("layout=".$layout."#".$postId); + return $session{asset}->getUrl("layout=".$layout.'#'.$session{asset}->getId) if (exists $session{asset}); + return $self->getUrl("layout=".$layout); } #------------------------------------------------------------------- -=head2 getLockUrl ( [ postId ] ) +=head2 getLockUrl ( ) Formats the url to lock a thread. -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getLockUrl { my $self = shift; - my $postId = shift || $self->get("rootPostId"); - $self->getUrl("fucn=lock#">$postId); + $self->getUrl("func=lock"); } #------------------------------------------------------------------- @@ -233,38 +225,28 @@ sub getPreviousThread { #------------------------------------------------------------------- -=head2 getStickUrl ( [ postId ] ) +=head2 getStickUrl ( ) Formats the url to make a thread sticky. -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getStickUrl { my $self = shift; - my $postId = shift || $self->get("rootPostId"); - return $self->getUrl("func=stick#".$postId); + return $self->getUrl("func=stick"); } #------------------------------------------------------------------- -=head2 getSubscribeUrl ( [ postId ] ) +=head2 getSubscribeUrl ( ) Formats the url to subscribe to the thread -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getSubscribeUrl { my $self = shift; - my $postId = shift || $self->get("rootPostId"); - return $self->getUrl("func=subscribe#".$postId); + return $self->getUrl("func=subscribe"); } @@ -275,57 +257,42 @@ sub getThread { #------------------------------------------------------------------- -=head2 getUnlockUrl ( [ postId ] ) +=head2 getUnlockUrl ( ) Formats the url to unlock the thread -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getUnlockUrl { my $self = shift; - my $postId = shift || $self->get("rootPostId"); - return $self->getUrl("func=unlock#".$postId); + return $self->getUrl("func=unlock"); } #------------------------------------------------------------------- -=head2 getUnstickUrl ( [ postId ] ) +=head2 getUnstickUrl ( ) Formats the url to unstick the thread -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getUnstickUrl { my $self = shift; - my $postId = shift || $self->get("rootPostId"); - return $self->getUrl("func=unstick#".$postId); + return $self->getUrl("func=unstick"); } #------------------------------------------------------------------- -=head2 getUnsubscribeUrl ( [ postId ] ) +=head2 getUnsubscribeUrl ( ) Formats the url to unsubscribe from the thread -=head3 postId - -The asset id of the post to position on. Defaults to the root post of the thread. - =cut sub getUnsubscribeUrl { my $self = shift; - my $postId = shift || $self->get("rootPostId"); - return $self->getUrl("func=unsubscribe#".$postId); + return $self->getUrl("func=unsubscribe"); } @@ -583,7 +550,7 @@ sub view { my $layout = $session{scratch}{discussionLayout} || $session{user}{discussionLayout}; $var->{'layout.isFlat'} = ($layout eq "flat"); $var->{'layout.isNested'} = ($layout eq "nested"); - $var->{'layout.isThreaded'} = ($layout eq "threaded" || !($var->{'thread.layout.isNested'} || $var->{'thread.layout.isFlat'})); + $var->{'layout.isThreaded'} = ($layout eq "threaded" || !($var->{'layout.isNested'} || $var->{'layout.isFlat'})); $var->{'user.isSubscribed'} = $self->isSubscribed; $var->{'subscribe.url'} = $self->getSubscribeUrl; @@ -599,11 +566,10 @@ sub view { my $p = WebGUI::Paginator->new($self->getUrl,$self->getParent->get("postsPerPage")); my $sql = "select * from asset - left join Post on Post.assetId=asset.assetId left join Thread on Thread.assetId=asset.assetId - where asset.lineage like ".quote($self->get("lineage").'%')." - and asset.assetId<>".quote($self->getId)." - and ( + left join Post on Post.assetId=asset.assetId + where asset.lineage like ".quote($self->get("lineage").'%') + ." and ( Post.status in ('approved','archived')"; $sql .= " or Post.status='pending'" if ($self->getParent->canModerate); $sql .= " or (asset.ownerUserId=".quote($session{user}{userId})." and asset.ownerUserId<>'1') @@ -618,14 +584,17 @@ sub view { foreach my $dataSet (@{$p->getPageData()}) { my $reply = WebGUI::Asset::Post->newByPropertyHashRef($dataSet); $reply->{_thread} = $self; # caching thread for better performance - my $replyVars = $reply->getTemplateVars; - $replyVars->{isCurrent} = $session{asset}->getId eq $reply->getId; - $replyVars->{depth} = $reply->getLineageLength - $self->getLineageLength - 1; + my %replyVars = %{$reply->getTemplateVars}; + $replyVars{isCurrent} = ('/'.$reply->get("url") eq $session{env}{PATH_INFO}); + $replyVars{isThreadRoot} = $self->getId eq $reply->getId; + $replyVars{depth} = $reply->getLineageLength - $self->getLineageLength; + $replyVars{depthX10} = $replyVars{depth}*10; my @depth_loop; - for (my $i=0; $i<$replyVars->{depth}; $i++) { - push(@{$replyVars->{indent_loop}},{depth=>$i}); + #@{$replyVars{indent_loop}} = {}; + for (my $i=0; $i<$replyVars{depth}; $i++) { + push(@{$replyVars{indent_loop}},{depth=>$i}); } - push (@{$var->{post_loop}}, $replyVars); + push (@{$var->{post_loop}}, \%replyVars); } $p->appendTemplateVars($var); $var->{'add.url'} = $self->getParent->getNewThreadUrl; @@ -637,6 +606,9 @@ sub view { $var->{"search.url"} = $self->getParent->getSearchUrl; $var->{"collaboration.url"} = $self->getThread->getParent->getUrl; + $var->{'collaboration.title'} = $self->getParent->get("title"); + $var->{'collaboration.description'} = $self->getParent->get("description"); + return $self->processTemplate($var,$self->getParent->get("threadTemplateId")); } diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index b5b50a073..5a126d0a2 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -929,8 +929,8 @@ sub www_search { # this is for trained professionals only and should not be attempted at home my $sql = "select * from asset - left join Post on Post.assetId=asset.assetId left join Thread on Thread.assetId=asset.assetId + left join Post on Post.assetId=asset.assetId where (asset.className='WebGUI::Asset::Post' or asset.className='WebGUI::Asset::Post::Thread') and asset.lineage like ".quote($self->get("lineage").'%')." and asset.assetId<>".quote($self->getId)."