diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index d9896238a..5e17b7a96 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -32,7 +32,11 @@ use WebGUI::Storage; use WebGUI::User; use WebGUI::Utility; use WebGUI::VersionTag; -our @ISA = qw(WebGUI::Asset); +use Class::C3; +use base qw( + WebGUI::AssetAspect::AutoSynopsis + WebGUI::Asset +); #------------------------------------------------------------------- @@ -86,7 +90,7 @@ sub addChild { $self->session->errorHandler->security("add a ".$properties->{className}." to a ".$self->get("className")); return undef; } - return $self->SUPER::addChild($properties, @other); + return $self->next::method($properties, @other); } #------------------------------------------------------------------- @@ -99,7 +103,7 @@ Override the default method in order to deal with attachments. sub addRevision { my $self = shift; - my $newSelf = $self->SUPER::addRevision(@_); + my $newSelf = $self->next::method(@_); if ($newSelf->get("storageId") && $newSelf->get("storageId") eq $self->get('storageId')) { my $newStorage = WebGUI::Storage->get($self->session,$self->get("storageId"))->copy; $newSelf->update({storageId=>$newStorage->getId}); @@ -130,7 +134,7 @@ Extend the master class to make the default group 7. sub canAdd { my $class = shift; my $session = shift; - $class->SUPER::canAdd($session, undef, '7'); + $class->next::method($session, undef, '7'); } #------------------------------------------------------------------- @@ -229,7 +233,7 @@ increment replies for the parent thread. sub commit { my $self = shift; - $self->SUPER::commit; + $self->next::method; $self->notifySubscribers unless ($self->shouldSkipNotification); @@ -259,7 +263,7 @@ sub cut { my $cs = $thread->getParent; # Cut the asset - my $result = $self->SUPER::cut; + my $result = $self->next::method; # If a post is being cut update the thread reply count first if ($thread->getId ne $self->getId) { @@ -347,7 +351,7 @@ sub definition { className=>'WebGUI::Asset::Post', properties=>$properties, }); - return $class->SUPER::definition($session,$definition); + return $class->next::method($session,$definition); } @@ -362,7 +366,7 @@ Extend the base method to delete the locally cached thread object. sub DESTROY { my $self = shift; $self->{_thread}->DESTROY if (exists $self->{_thread} && ref $self->{_thread} =~ /Thread/); - $self->SUPER::DESTROY; + $self->next::method; } @@ -376,7 +380,7 @@ Extend the base class to handle storage locations. sub exportAssetData { my $self = shift; - my $data = $self->SUPER::exportAssetData; + my $data = $self->next::method; push(@{$data->{storage}}, $self->get("storageId")) if ($self->get("storageId") ne ""); return $data; } @@ -398,7 +402,7 @@ sub fixUrl { my $url = shift; $url =~ s/\./_/g; - $self->SUPER::fixUrl($url); + $self->next::method($url); } #------------------------------------------------------------------- @@ -655,49 +659,6 @@ sub getStorageLocation { #------------------------------------------------------------------- -=head2 getSynopsisAndContent ($synopsis, $body) - -Returns a synopsis taken from the body of the Post, based on either the separator -macro, the first html paragraph, or the first physical line of text as defined by -newlines. - -Returns both the synopsis, and the original body content. - -=head3 $synopsis - -If passed in, it returns that instead of the calculated synopsis. - -=head3 $body - -Body of the Post to use a source for the synopsis. - -=cut - -sub getSynopsisAndContent { - my $self = shift; - my $synopsis = shift; - my $body = shift; - unless ($synopsis) { - my @content; - if( $body =~ /\^\-\;/ ) { - my @pieces = WebGUI::HTML::splitSeparator($body); - $content[0] = shift @pieces; - $content[1] = join '', @pieces; - } - elsif( $body =~ /

/ ) { - @content = WebGUI::HTML::splitTag($body); - } - else { - @content = split("\n",$body); - } - shift @content if $content[0] =~ /^\s*$/; - $synopsis = WebGUI::HTML::filter($content[0],"all"); - } - return ($synopsis,$body); -} - -#------------------------------------------------------------------- - =head2 getTemplateMetadataVars ( $var ) Append metadata as template variables. @@ -871,7 +832,7 @@ Indexing the content of attachments and user defined fields. See WebGUI::Asset:: sub indexContent { my $self = shift; - my $indexer = $self->SUPER::indexContent; + my $indexer = $self->next::method; $indexer->addKeywords($self->get("content")); $indexer->addKeywords($self->get("userDefined1")); $indexer->addKeywords($self->get("userDefined2")); @@ -1058,7 +1019,7 @@ Extends the master method to handle incrementing replies. sub paste { my $self = shift; - $self->SUPER::paste(@_); + $self->next::method(@_); # First, figure out what Thread we're under my $thread = $self->getLineage( [ qw{ self ancestors } ], { @@ -1103,7 +1064,7 @@ non-sticky, locking and unlocking posts. Calls postProcess when it is done. sub processPropertiesFromFormPost { my $self = shift; - $self->SUPER::processPropertiesFromFormPost; + $self->next::method; my $session = $self->session; my $form = $session->form; my $i18n = WebGUI::International->new($session); @@ -1184,15 +1145,6 @@ sub postProcess { #------------------------------------------------------------------- -#sub publish { -# my $self = shift; -# $self->SUPER::publish(@_); -# -# $self->getThread->sumReplies; -#} - -#------------------------------------------------------------------- - =head2 purge Extend the base method to handle cleaning up storage locations. @@ -1207,7 +1159,7 @@ sub purge { $storage->delete if defined $storage; } $sth->finish; - return $self->SUPER::purge; + return $self->next::method; } #------------------------------------------------------------------- @@ -1221,7 +1173,7 @@ Extend the base class to handle caching. sub purgeCache { my $self = shift; WebGUI::Cache->new($self->session,"view_".$self->getThread->getId)->delete if ($self->getThread); - $self->SUPER::purgeCache; + $self->next::method; } #------------------------------------------------------------------- @@ -1235,7 +1187,7 @@ Extend the base method to handle deleting the storage location. sub purgeRevision { my $self = shift; $self->getStorageLocation->delete; - return $self->SUPER::purgeRevision; + return $self->next::method; } @@ -1295,7 +1247,7 @@ the thread rating. sub restore { my $self = shift; - $self->SUPER::restore(@_); + $self->next::method(@_); $self->getThread->sumReplies; $self->getThread->updateThreadRating; } @@ -1336,7 +1288,7 @@ sub setParent { my $self = shift; my $newParent = shift; return 0 unless ($newParent->get("className") eq "WebGUI::Asset::Post" || $newParent->get("className") eq "WebGUI::Asset::Post::Thread"); - return $self->SUPER::setParent($newParent); + return $self->next::method($newParent); } @@ -1379,7 +1331,7 @@ Moves post to the trash, updates reply counter on thread and recalculates the th sub trash { my $self = shift; - $self->SUPER::trash; + $self->next::method; $self->getThread->sumReplies if ($self->isReply); $self->getThread->updateThreadRating; if ($self->getThread->get("lastPostId") eq $self->getId) { @@ -1414,7 +1366,7 @@ sub update { view => $self->get("groupIdView"), edit => $self->get("groupIdEdit") ); - $self->SUPER::update({%$properties, isHidden => 1}); + $self->next::method({%$properties, isHidden => 1}); if ($self->get("ownerUserId") ne $before{owner} || $self->get("groupIdEdit") ne $before{edit} || $self->get("groupIdView") ne $before{view}) { my $storage = $self->getStorageLocation; if (-d $storage->getPath) { @@ -1433,7 +1385,7 @@ Extend the base method to also prepare the Thread containing this Post. sub prepareView { my $self = shift; - $self->SUPER::prepareView; + $self->next::method; unless ($self->getThread->getId eq $self->getId) { # Need the unless to avoid infinite recursion. $self->getThread->prepareView; @@ -1801,7 +1753,7 @@ sub www_editSave { } } } - my $output = $self->SUPER::www_editSave(); + my $output = $self->next::method(); if ($currentTag) { # Go back to our original tag $currentTag->setWorking; } diff --git a/lib/WebGUI/Asset/WikiPage.pm b/lib/WebGUI/Asset/WikiPage.pm index 1db8ed0b2..50cffbf82 100644 --- a/lib/WebGUI/Asset/WikiPage.pm +++ b/lib/WebGUI/Asset/WikiPage.pm @@ -15,6 +15,7 @@ use Class::C3; use base qw( WebGUI::AssetAspect::Subscribable WebGUI::AssetAspect::Comments + WebGUI::AssetAspect::AutoSynopsis WebGUI::Asset ); use Tie::IxHash; @@ -420,6 +421,8 @@ sub processPropertiesFromFormPost { $properties->{isFeatured} = $session->form->get("isFeatured"); } + ($properties->{synopsis}) = $self->getSynopsisAndContent(undef, $self->get('content')); + $self->update($properties); # deal with attachments from the attachments form control @@ -473,6 +476,7 @@ sub scrubContent { my $self = shift; my $content = shift || $self->get("content"); + $content =~ s/\^-\;//g; my $scrubbedContent = WebGUI::HTML::filter($content, $self->getWiki->get("filterCode")); if ($self->getWiki->get("useContentFilter")) { diff --git a/lib/WebGUI/AssetAspect/AutoSynopsis.pm b/lib/WebGUI/AssetAspect/AutoSynopsis.pm new file mode 100644 index 000000000..50ec947b1 --- /dev/null +++ b/lib/WebGUI/AssetAspect/AutoSynopsis.pm @@ -0,0 +1,83 @@ +package WebGUI::AssetAspect::AutoSynopsis; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use Class::C3; +use WebGUI::HTML; + +=head1 NAME + +Package WebGUI::AssetAspect::AutoSynopsis + +=head1 DESCRIPTION + +This is an aspect which provides a method for an asset to create a synopsis based on user submitted content. + +=head1 SYNOPSIS + + use Class::C3; + use base qw(WebGUI::AssetAspect::AutoSynopsis WebGUI::Asset); + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 getSynopsisAndContent ($synopsis, $body) + +Returns a synopsis taken from the body of the Post, based on either the separator +macro, the first html paragraph, or the first physical line of text as defined by +newlines. + +Returns both the synopsis, and the original body content. + +=head3 $synopsis + +If passed in, it returns that instead of the calculated synopsis. + +=head3 $body + +Body of the Post to use a source for the synopsis. + +=cut + +sub getSynopsisAndContent { + my $self = shift; + my $synopsis = shift; + my $body = shift; + unless ($synopsis) { + my @content; + if( $body =~ /\^\-\;/ ) { + my @pieces = WebGUI::HTML::splitSeparator($body); + $content[0] = shift @pieces; + $content[1] = join '', @pieces; + } + elsif( $body =~ /

/ ) { + @content = WebGUI::HTML::splitTag($body); + } + else { + @content = split("\n",$body); + } + shift @content if $content[0] =~ /^\s*$/; + $synopsis = WebGUI::HTML::filter($content[0],"all"); + } + return ($synopsis,$body); +} + +1; diff --git a/t/Asset/Post.t b/t/Asset/Post.t index ec495ae1a..a460d31b3 100644 --- a/t/Asset/Post.t +++ b/t/Asset/Post.t @@ -19,7 +19,7 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 16; # increment this value for each test you create +use Test::More tests => 17; # increment this value for each test you create use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Post; use WebGUI::Asset::Post::Thread; @@ -113,6 +113,7 @@ ok($post->canEdit(), "User in groupIdEditUserGroup group can edit post after the # ###################################################################### +can_ok($post, 'getSynopsisAndContent'); my ($synopsis, $content) = $post->getSynopsisAndContent('', q|Brandheiße Neuigkeiten rund um's Klettern für euch aus der Region |); is($synopsis, q|Brandheiße Neuigkeiten rund um's Klettern für euch aus der Region |, 'getSynopsisAndContent: UTF8 characters okay'); diff --git a/t/Asset/WikiPage.t b/t/Asset/WikiPage.t index 79815baaa..853a7566c 100644 --- a/t/Asset/WikiPage.t +++ b/t/Asset/WikiPage.t @@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 17; # increment this value for each test you create +use Test::More tests => 18; # increment this value for each test you create use Test::Deep; use WebGUI::Asset::Wobject::WikiMaster; use WebGUI::Asset::WikiPage; @@ -91,3 +91,4 @@ $comments = $wikipage->get('comments'); is($comments->[0]{comment}, $secondComment, "you can delete a comment"); is($wikipage->get('averageCommentRating'), 1, 'average rating is adjusted after deleting a comment'); +can_ok($wikipage, 'getSynopsisAndContent');