Merge commit '4969f31e1f' into WebGUI8

This commit is contained in:
Colin Kuskie 2010-06-26 14:37:31 -07:00
commit e5b82bc861
61 changed files with 2199 additions and 521 deletions

View file

@ -452,6 +452,14 @@ property postReceivedTemplateId => (
hoverHelp => [ 'post received template hoverHelp', 'Asset_Collaboration' ],
default => 'default_post_received1',
);
property unsubscribeTemplateId => (
fieldType => 'template',
namespace => 'Collaboration/Unsubscribe',
tab => 'display',
label => [ 'unsubscribe template', 'Asset_Collaboration' ],
hoverHelp => [ 'unsubscribe template hoverHelp', 'Asset_Collaboration' ],
default => 'default_CS_unsubscribe',
);
with 'WebGUI::Role::Asset::RssFeed';
@ -1557,18 +1565,22 @@ sub subscribe {
#-------------------------------------------------------------------
=head2 unsubscribe ( )
=head2 unsubscribe ( [$user] )
Unsubscribes a user from this collaboration system
=head3 $user
An optional user object to unsubscribe. If the object isn't passed, then it uses the session user.
=cut
sub unsubscribe {
my $self = shift;
my $self = shift;
my $user = shift || $self->session->user;
my $group = WebGUI::Group->new($self->session,$self->subscriptionGroupId);
return
unless $group;
$group->deleteUsers([$self->session->user->userId],[$self->subscriptionGroupId]);
return unless $group;
$group->deleteUsers([$user->userId]);
}
@ -1706,24 +1718,64 @@ sub www_unarchiveAll {
#-------------------------------------------------------------------
=head2 www_unsubscribe ( )
=head2 www_unsubscribe ( [$message] )
The web method to unsubscribe from a collaboration.
=head3 $message
An error message to display to the user.
=cut
sub www_unsubscribe {
my $self = shift;
my $self = shift;
my $message = shift;
if($self->canSubscribe){
$self->unsubscribe;
return $self->www_view;
}else{
return $self->session->privilege->noAccess;
}
else {
my $session = $self->session;
my $i18n = WebGUI::International->new($session, 'Asset_Collaboration');
my $var = $self->get();
$var->{title} = $self->getTitle;
$var->{url} = $self->getUrl;
$var->{formHeader} = WebGUI::Form::formHeader($session)
. WebGUI::Form::hidden($session, { name => 'func', value => 'unsubscribeConfirm', }, ),
$var->{formFooter} = WebGUI::Form::formFooter($session),
$var->{formSubmit} = WebGUI::Form::submit($session, { value => $i18n->get('unsubscribe'), }),
$var->{formEmail} = WebGUI::Form::email($session, { name => 'userEmail', value => $session->form->process('userEmail'), }),
$var->{formMessage} = $message;
return $self->processStyle($self->processTemplate($var, $self->get("unsubscribeTemplateId")));
}
}
#-------------------------------------------------------------------
=head2 www_unsubscribeConfirm ( )
Process the unsubscribe form.
=cut
sub www_unsubscribeConfirm {
my $self = shift;
my $session = $self->session;
return $self->www_view unless $session->form->validToken;
my $email = $session->form->process('userEmail', 'email');
return $self->www_view unless $email;
my $user = WebGUI::User->newByEmail($session, $email);
my $i18n = WebGUI::International->new($session, 'Asset_Collaboration');
if (! $user) {
return $self->www_unsubscribe($i18n->get('no user email error message'));
}
$self->unsubscribe($user);
return $self->www_unsubscribe($i18n->get('You have been unsubscribed'));
}
#-------------------------------------------------------------------
=head2 www_view
Extend the base method to handle the visitor cache timeout.

View file

@ -1896,7 +1896,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate
# gotta get to the page we're working with
$counter++;
next unless ($counter >= ($startIndex * $numberOfResults));
next unless ($counter >= $startIndex+1);
# publish the data for this ticket
my $description = $ticket->description;

View file

@ -43,16 +43,22 @@ for my $i ( 1 .. 5 ) {
with 'WebGUI::Role::Asset::AlwaysHidden';
with 'WebGUI::Role::Asset::RssFeed';
use strict;
use Carp qw( croak );
use File::Find;
use File::Spec;
use File::Temp qw{ tempdir };
use JSON qw();
use Image::ExifTool qw( :Public );
use JSON;
use Tie::IxHash;
use WebGUI::International;
use WebGUI::HTML;
use WebGUI::ProgressBar;
use WebGUI::Storage;
# Do not move this instruction!
use Archive::Any;
=head1 NAME
@ -88,6 +94,12 @@ The name of the file archive to import.
A base set of properties to add to each file in the archive.
=head3 sortBy
Order in which files should be added to the gallery album. Legal values are
'name', 'date' and 'fileOrder'. If missing or invalid, files will be added as
ordered in the archive (default; corresponding to 'fileOrder').
=head3 $outputSub
A callback to use for outputting data, most likely to a progress bar. It expects the
@ -100,6 +112,7 @@ sub addArchive {
my $self = shift;
my $filename = shift;
my $properties = shift;
my $sortBy = shift;
my $outputSub = shift || sub {};
my $gallery = $self->getParent;
my $session = $self->session;
@ -119,6 +132,33 @@ sub addArchive {
find( {
wanted => $wanted,
}, $tempdirName );
# Sort files by date
if ($sortBy eq 'date') {
# Hash for storing last modified timestamps
my %mtimes;
my $exifTool = Image::ExifTool->new;
# Make ExifTool return epoch timestamps
$exifTool->Options('DateFormat', '%s');
# Iterate through all files
foreach my $file (@files) {
# Extract exif data from image
$exifTool->ExtractInfo( $file );
# Get last modified timestamp from exif data
$mtimes{$file} = $exifTool->GetValue('ModifyDate');
# Use last modified date of file as fallback
$mtimes{$file} = (stat($file))[9] unless $mtimes{$file};
}
# Sort files based on last modified timestamps
@files = sort { $mtimes{$a} <=> $mtimes{$b} } @files;
}
# Sort files by name
elsif ($sortBy eq 'name') {
@files = sort @files;
}
for my $filePath (@files) {
my ($volume, $directory, $filename) = File::Spec->splitpath( $filePath );
@ -955,12 +995,29 @@ sub www_addArchive {
name => "keywords",
value => ( $form->get("keywords") ),
});
$var->{ form_location }
= WebGUI::Form::Text( $session, {
name => "location",
value => ( $form->get("location") ),
});
$var->{ form_friendsOnly }
= WebGUI::Form::yesNo( $session, {
name => "friendsOnly",
value => ( $form->get("friendsOnly") ),
});
$var->{ form_sortBy }
= WebGUI::Form::RadioList( $session, {
name => "sortBy",
value => [ "name" ],
options => {
name => $i18n->get("addArchive sortBy name", 'Asset_GalleryAlbum'),
date => $i18n->get("addArchive sortBy date", 'Asset_GalleryAlbum'),
fileOrder => $i18n->get("addArchive sortBy fileOrder", 'Asset_GalleryAlbum'),
},
});
return $self->processStyle(
$self->processTemplate($var, $self->getParent->templateIdAddArchive)
@ -978,26 +1035,39 @@ Process the form for adding an archive.
sub www_addArchiveSave {
my $self = shift;
# Return error message if the user viewing does not have permission to add files
return $self->session->privilege->insufficient unless $self->canAddFile;
my $session = $self->session;
my $form = $self->session->form;
my $i18n = WebGUI::International->new( $session, 'Asset_GalleryAlbum' );
my $pb = WebGUI::ProgressBar->new($session);
# Retrieve properties and sort order from form variables
my $properties = {
keywords => $form->get("keywords"),
location => $form->get("location"),
friendsOnly => $form->get("friendsOnly"),
};
my $sortBy = $form->get("sortBy");
# Create progress bar to keep the connection alive
$pb->start($i18n->get('Uploading archive'), $session->url->extras('adminConsole/assets.gif'));
# Retrieve storage containing the uploaded archive
my $storageId = $form->get("archive", "File");
my $storage = WebGUI::Storage->get( $session, $storageId );
if (!$storage) {
return $pb->finish($self->getUrl('func=addArchive;error='.$i18n->get('addArchive error too big')));
}
my $filename = $storage->getPath( $storage->getFiles->[0] );
eval { $self->addArchive( $filename, $properties, sub{ $pb->update(sprintf $i18n->get(shift), @_); }); };
# Get the full path to the archive
my $filename = $storage->getPath( $storage->getFiles->[0] );
# Try to add files in archive as photos
eval { $self->addArchive( $filename, $properties, $sortBy, sub{ $pb->update(sprintf $i18n->get(shift), @_); }); };
# Delete storage containing archive
$storage->delete;
if ( my $error = $@ ) {
return $pb->finish($self->getUrl('func=addArchive;error='.sprintf $i18n->get('addArchive error generic'), $error ));

View file

@ -71,11 +71,23 @@ property hasTerms => (
);
property sortItems => (
tab => 'properties',
fieldType => 'yesNo',
default => 1,
fieldType => 'selectBox',
default => 'none',
label => ['sortItemsLabel', 'Asset_SyndicatedContent'],
hoverHelp => ['sortItemsLabel description', 'Asset_SyndicatedContent'],
options => \&_sortItems_options,
);
sub _sortItems_options {
my $session = shift->session;
my $i18n = WebGUI::International->new($session,'Asset_SyndicatedContent');
tie my %o, 'Tie::IxHash', (
none => $i18n->get('no order'),
feed => $i18n->get('feed order'),
pubDate_asc => $i18n->get('publication date ascending'),
pubDate_des => $i18n->get('publication date descending'),
);
return \%o;
}
has '+uiLevel' => (
default => 6,
);
@ -114,11 +126,15 @@ Combines all feeds into a single XML::FeedPP object.
=cut
sub generateFeed {
my $self = shift;
my $limit = shift || $self->maxHeadlines;
my $self = shift;
my $limit = shift || $self->maxHeadlines;
my $session = $self->session;
my ( $log, $cache ) = $session->quick(qw( log cache ));
my $feed = XML::FeedPP::Atom->new();
my $log = $session->log;
my $cache = $session->cache;
my $sort = $self->sortItems;
my %opt = (use_ixhash => 1) if $sort eq 'feed';
my $feed = XML::FeedPP::Atom->new(%opt);
# build one feed out of many
my $newlyCached = 0;
@ -151,7 +167,7 @@ sub generateFeed {
# care of any encoding specified in the XML prolog
utf8::downgrade($value, 1);
eval {
my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string');
my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string', %opt);
$feed->merge_channel($singleFeed);
$feed->merge_item($singleFeed);
};
@ -183,9 +199,14 @@ sub generateFeed {
}
# sort them by date and remove any duplicate from the OR based term matching above
if ($self->sortItems) {
if ($sort =~ /^pubDate/) {
$feed->sort_item();
}
if ($sort =~ /_asc$/) {
my @items = $feed->get_item;
$feed->clear_item;
$feed->add_item($_) for (reverse @items);
}
# limit the feed to the maximum number of headlines (or the feed generator limit).
$feed->limit_item($limit);
@ -270,10 +291,19 @@ sub getTemplateVariables {
$item{descriptionFirst25words} =~ s/(((\S+)\s+){25}).*/$1/s;
$item{descriptionFirst10words} = $item{descriptionFirst25words};
$item{descriptionFirst10words} =~ s/(((\S+)\s+){10}).*/$1/s;
$item{descriptionFirst2paragraphs} = $item{description};
$item{descriptionFirst2paragraphs} =~ s/^((.*?\n){2}).*/$1/s;
$item{descriptionFirstParagraph} = $item{descriptionFirst2paragraphs};
$item{descriptionFirstParagraph} =~ s/^(.*?\n).*/$1/s;
if ($description =~ /<p>/) {
my $html = $description;
$html =~ tr/\n/ /s;
my @paragraphs = map { "<p>".$_."</p>" } WebGUI::HTML::splitTag($html,3);
$item{descriptionFirstParagraph} = $paragraphs[0];
$item{descriptionFirst2paragraphs} = join '', @paragraphs[0..1];
}
else {
$item{descriptionFirst2paragraphs} = $item{description};
$item{descriptionFirst2paragraphs} =~ s/^((.*?\n){2}).*/$1/s;
$item{descriptionFirstParagraph} = $item{descriptionFirst2paragraphs};
$item{descriptionFirstParagraph} =~ s/^(.*?\n).*/$1/s;
}
$item{descriptionFirst4sentences} = $item{description};
$item{descriptionFirst4sentences} =~ s/^((.*?\.){4}).*/$1/s;
$item{descriptionFirst3sentences} = $item{descriptionFirst4sentences};

View file

@ -502,6 +502,7 @@ sub view {
if(isIn($sortBy,@sortByUserProperties)){
$sortBy = 'users.'.$sortBy;
}
$sortBy = join '.', map { $self->session->db->quoteIdentifier($_) } split /\./, $sortBy;
$sql .= " order by ".$sortBy." ".$sortOrder;
($defaultPublicProfile) = $self->session->db->quickArray("SELECT dataDefault FROM userProfileField WHERE fieldName='publicProfile'");

View file

@ -972,19 +972,13 @@ sub www_search {
wikiHomeUrl=>$self->getUrl,
addPageUrl=>$self->getUrl("func=add;class=WebGUI::Asset::WikiPage;title=".$queryString),
};
if (defined $queryString) {
$self->session->scratch->set('wikiSearchQueryString', $queryString);
}
else {
$queryString = $self->session->scratch->get('wikiSearchQueryString');
}
$self->appendSearchBoxVars($var, $queryString);
if (length $queryString) {
my $search = WebGUI::Search->new($self->session);
$search->search({ keywords => $queryString,
lineage => [$self->lineage],
classes => ['WebGUI::Asset::WikiPage'] });
my $rs = $search->getPaginatorResultSet($self->getUrl("func=search"));
my $rs = $search->getPaginatorResultSet($self->getUrl("func=search;query=".$queryString));
$rs->appendTemplateVars($var);
my @results = ();
foreach my $row (@{$rs->getPageData}) {