merged with SVN to get friends stuff

This commit is contained in:
Doug Bell 2007-10-26 00:50:05 +00:00
commit 7e12c6c2f0
73 changed files with 3262 additions and 424 deletions

View file

@ -1326,6 +1326,23 @@ sub indexContent {
return $indexer;
}
#-------------------------------------------------------------------
=head2 loadModule ( $session, $className )
Loads an asset module if it's not already in memory. This is a class method. Returns undef on failure to load, otherwise returns the classname.
=cut
sub loadModule {
my ($class, $session, $className) = @_;
(my $module = $className . '.pm') =~ s{::|'}{/}g;
if (eval { require $module; 1 }) {
return $className;
}
$session->errorHandler->error("Couldn't compile asset package: ".$className.". Root cause: ".$@);
return;
}
#-------------------------------------------------------------------
@ -1687,14 +1704,9 @@ sub new {
}
}
if ($className) {
my $cmd = "use ".$className;
eval ($cmd);
if ($@) {
$session->errorHandler->error("Couldn't compile asset package: ".$className.". Root cause: ".$@);
return undef;
}
$class = $className;
if ($className) {
$class = $class->loadModule($session, $className);
return undef unless (defined $class);
}
my $cache = WebGUI::Cache->new($session, ["asset",$assetId,$revisionDate]);
@ -1777,13 +1789,8 @@ sub newByPropertyHashRef {
my $properties = shift;
return undef unless defined $properties;
return undef unless exists $properties->{className};
my $className = $properties->{className};
my $cmd = "use ".$className;
eval ($cmd);
if ($@) {
$session->errorHandler->warn("Couldn't compile asset package: ".$className.". Root cause: ".$@);
return undef;
}
my $className = $class->loadModule($session, $properties->{className});
return undef unless (defined $className);
bless {_session=>$session, _properties => $properties}, $className;
}
@ -2206,7 +2213,8 @@ Adds a new Asset based upon the class of the current form. Returns the Asset cal
sub www_add {
my $self = shift;
my %prototypeProperties;
my $class = $self->session->form->process("class","className");
my $class = $self->loadModule($self->session, $self->session->form->process("class","className"));
return undef unless (defined $class);
return $self->session->privilege->insufficient() unless ($class->canAdd($self->session));
if ($self->session->form->process('prototype')) {
my $prototype = WebGUI::Asset->new($self->session, $self->session->form->process("prototype"),$class);

View file

@ -19,7 +19,7 @@ use base 'WebGUI::Asset::File';
use WebGUI::Storage::Image;
use WebGUI::HTMLForm;
use WebGUI::Utility;
use WebGUI::Form::Image;
=head1 NAME

View file

@ -91,7 +91,7 @@ sub definition {
#----------------------------------------------------------------------------
=head2 appendTemplateVarsForCommentForm ( vars )
=head2 appendTemplateVarsForCommentForm ( var )
Add the template variables necessary for the comment form to the given hash
reference. Returns the hash reference for convenience.
@ -100,11 +100,11 @@ reference. Returns the hash reference for convenience.
sub appendTemplateVarsForCommentForm {
my $self = shift;
my $vars = shift;
my $var = shift;
# ...
return $vars;
return $var;
}
#----------------------------------------------------------------------------
@ -151,9 +151,27 @@ sub canEdit {
Returns true if the user can view this asset. C<userId> is a WebGUI user ID.
If no user is passed, checks the current user.
Users can view this photo if they can view the parent asset. If this is a
C<friendsOnly> photo, then they must also be in the owners friends list.
=cut
# Inherited from superclass
sub canView {
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $album = $self->getParent;
return 0 unless $album->canView($userId);
if ($self->isFriendsOnly) {
# ...
}
# Passed all checks
return 1;
}
#----------------------------------------------------------------------------
@ -321,6 +339,19 @@ sub i18n {
#----------------------------------------------------------------------------
=head2 isFriendsOnly ( )
Returns true if this Photo is friends only. Returns false otherwise.
=cut
sub isFriendsOnly {
my $self = shift;
return $self->get("friendsOnly");
}
#----------------------------------------------------------------------------
=head2 makeResolutions ( [resolutions] )
Create the specified resolutions for this Photo. If resolutions is not

View file

@ -72,16 +72,12 @@ sub addRevision {
my $now = time();
if ($threadId eq "") { # new post
if ($newSelf->getParent->isa("WebGUI::Asset::Wobject::Collaboration")) {
$newSelf->update({threadId=>$newSelf->getId, dateSubmitted=>$now});
$newSelf->update({threadId=>$newSelf->getId});
} else {
$newSelf->update({threadId=>$newSelf->getParent->get("threadId"), dateSubmitted=>$now});
$newSelf->update({threadId=>$newSelf->getParent->get("threadId")});
}
delete $newSelf->{_thread};
}
$newSelf->update({
dateUpdated=>$now,
});
$newSelf->getThread->unmarkRead;
return $newSelf;
@ -99,7 +95,7 @@ sub canEdit {
my $self = shift;
return (($self->session->form->process("func") eq "add" || ($self->session->form->process("assetId") eq "new" && $self->session->form->process("func") eq "editSave" && $self->session->form->process("class","className") eq "WebGUI::Asset::Post")) && $self->getThread->getParent->canPost) || # account for new posts
($self->isPoster && $self->getThread->getParent->get("editTimeout") > ($self->session->datetime->time() - $self->get("dateUpdated"))) ||
($self->isPoster && $self->getThread->getParent->get("editTimeout") > ($self->session->datetime->time() - $self->get("revisionDate"))) ||
$self->getThread->getParent->canEdit;
}
@ -150,7 +146,7 @@ sub commit {
my $u = WebGUI::User->new($self->session, $self->get("ownerUserId"));
$u->karma($self->getThread->getParent->get("karmaPerPost"), $self->getId, "Collaboration post");
}
$self->getThread->incrementReplies($self->get("dateUpdated"),$self->getId) if ($self->isReply);
$self->getThread->incrementReplies($self->get("revisionDate"),$self->getId) if ($self->isReply);
}
}
@ -176,15 +172,6 @@ sub definition {
fieldType=>"hidden",
defaultValue=>undef
},
dateSubmitted => {
noFormPost=>1,
fieldType=>"hidden",
defaultValue=>$session->datetime->time()
},
dateUpdated => {
fieldType=>"hidden",
defaultValue=>$session->datetime->time()
},
username => {
fieldType=>"hidden",
defaultValue=>$session->form->process("visitorUsername") || $session->user->profileField("alias") || $session->user->username
@ -311,6 +298,12 @@ sub formatContent {
return $msg;
}
#-------------------------------------------------------------------
# Too slow to try to find out children, just always assume new data
sub getContentLastModified {
return time();
}
#-------------------------------------------------------------------
sub getAutoCommitWorkflowId {
my $self = shift;
@ -511,8 +504,8 @@ sub getTemplateVars {
$var{"user.isPoster"} = $self->isPoster;
$var{"avatar.url"} = $self->getAvatarUrl;
$var{"userProfile.url"} = $self->getUrl("op=viewProfile;uid=".$self->get("ownerUserId"));
$var{"dateSubmitted.human"} =$self->session->datetime->epochToHuman($self->get("dateSubmitted"));
$var{"dateUpdated.human"} =$self->session->datetime->epochToHuman($self->get("dateUpdated"));
$var{"dateSubmitted.human"} =$self->session->datetime->epochToHuman($self->get("creationDate"));
$var{"dateUpdated.human"} =$self->session->datetime->epochToHuman($self->get("revisionDate"));
$var{'title.short'} = $self->chopTitle;
$var{content} = $self->formatContent if ($self->getThread);
$var{'user.canEdit'} = $self->canEdit if ($self->getThread);
@ -689,7 +682,7 @@ Returns a boolean indicating whether this post is new (not an edit).
sub isNew {
my $self = shift;
return $self->get("dateSubmitted") eq $self->get("dateUpdated");
return $self->get("creationDate") == $self->get("revisionDate");
}
#-------------------------------------------------------------------
@ -1021,19 +1014,23 @@ Moves post to the trash and updates reply counter on thread.
=cut
sub trash {
my $self = shift;
$self->SUPER::trash;
$self->getThread->sumReplies if ($self->isReply);
if ($self->getThread->get("lastPostId") eq $self->getId) {
my $threadLineage = $self->getThread->get("lineage");
my ($id, $date) = $self->session->db->quickArray("select Post.assetId, Post.dateSubmitted from Post, asset where asset.lineage like ".$self->session->db->quote($threadLineage.'%')." and Post.assetId<>".$self->session->db->quote($self->getId)." and asset.assetId=Post.assetId and asset.state='published' order by Post.dateSubmitted desc");
$self->getThread->update({lastPostId=>$id, lastPostDate=>$date});
}
if ($self->getThread->getParent->get("lastPostId") eq $self->getId) {
my $forumLineage = $self->getThread->getParent->get("lineage");
my ($id, $date) = $self->session->db->quickArray("select Post.assetId, Post.dateSubmitted from Post, asset where asset.lineage like ".$self->session->db->quote($forumLineage.'%')." and Post.assetId<>".$self->session->db->quote($self->getId)." and asset.assetId=Post.assetId and asset.state='published' order by Post.dateSubmitted desc");
$self->getThread->getParent->update({lastPostId=>$id, lastPostDate=>$date});
}
my $self = shift;
$self->SUPER::trash;
$self->getThread->sumReplies if ($self->isReply);
if ($self->getThread->get("lastPostId") eq $self->getId) {
my $threadLineage = $self->getThread->get("lineage");
my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where
lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%'
order by creationDate desc",[$threadLineage.'%', $self->getId]);
$self->getThread->update({lastPostId=>$id, lastPostDate=>$date});
}
if ($self->getThread->getParent->get("lastPostId") eq $self->getId) {
my $forumLineage = $self->getThread->getParent->get("lineage");
my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where
lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%'
order by creationDate desc",[$forumLineage.'%', $self->getId]);
$self->getThread->getParent->update({lastPostId=>$id, lastPostDate=>$date});
}
}
#-------------------------------------------------------------------

View file

@ -63,7 +63,7 @@ sub commit {
my $self = shift;
$self->SUPER::commit;
if ($self->isNew) {
$self->getParent->incrementThreads($self->get("dateUpdated"),$self->getId);
$self->getParent->incrementThreads($self->get("revisionDate"),$self->getId);
}
}
@ -623,6 +623,7 @@ sub setLastPost {
$self->getParent->setLastPost($id,$date);
}
#-------------------------------------------------------------------
sub normalizeLastPost {
my $self = shift;
# Hmm. Is this right?
@ -704,14 +705,21 @@ Moves thread to the trash and updates reply counter on thread.
=cut
sub trash {
my $self = shift;
$self->SUPER::trash;
$self->getParent->sumReplies;
if ($self->getParent->get("lastPostId") eq $self->getId) {
my $parentLineage = $self->getThread->get("lineage");
my ($id, $date) = $self->session->db->quickArray("select Post.assetId, Post.dateSubmitted from Post, asset where asset.lineage like ".$self->session->db->quote($parentLineage.'%')." and Post.assetId<>".$self->session->db->quote($self->getId)." and Post.assetId=asset.assetId and asset.state='published' order by Post.dateSubmitted desc");
$self->getParent->setLastPost('','') ? $self->getParent->setLastPost($id,$date) : $id;
my $self = shift;
$self->SUPER::trash;
$self->getParent->sumReplies;
if ($self->getParent->get("lastPostId") eq $self->getId) {
my $parentLineage = $self->getThread->get("lineage");
my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where
lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%'
order by creationDate desc",[$parentLineage.'%', $self->getId]);
if (defined $id) {
$self->getParent->setLastPost($id,$date);
}
else {
$self->getParent->setLastPost('','');
}
}
}
@ -884,10 +892,9 @@ sub view {
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->getParent->get("postsPerPage"));
my $sql = "select asset.assetId, asset.className, assetData.revisionDate as revisionDate, assetData.url as url from asset
left join assetData on assetData.assetId=asset.assetId
left join Post on Post.assetId=assetData.assetId and assetData.revisionDate=Post.revisionDate
where asset.lineage like ".$self->session->db->quote($self->get("lineage").'%')
." and asset.state='published'
and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId
and assetData.revisionDate=(SELECT max(assetData.revisionDate) from assetData where assetData.assetId=asset.assetId
and (
assetData.status in ('approved','archived')
or assetData.tagId=".$self->session->db->quote($self->session->scratch->get("versionTag"));
@ -898,7 +905,7 @@ sub view {
order by ";
if ($layout eq "flat") {
$sql .= "Post.dateSubmitted";
$sql .= "asset.creationDate";
} else {
$sql .= "asset.lineage";
}

View file

@ -119,7 +119,7 @@ sub www_view {
$subvar = {};
@$subvar{'title', 'link', 'description'} = $self->_tlsOfAsset($item);
$subvar->{guid} = $subvar->{link};
$subvar->{pubDate} = _escapeXml($self->session->datetime->epochToMail($item->get('dateUpdated')));
$subvar->{pubDate} = _escapeXml($self->session->datetime->epochToMail($item->get('revisionDate')));
} elsif (ref $item eq 'HASH') {
foreach my $key (keys %$item) {
$subvar->{$key} = _escapeXml($item->{$key});

View file

@ -191,7 +191,7 @@ sub getEditForm {
#-------------------------------------------------------------------
=head2 getList ( session, namespace )
=head2 getList ( session, namespace [,clause] )
Returns a hash reference containing template ids and template names of all the templates in the specified namespace.
@ -203,7 +203,12 @@ A reference to the current session.
=head3 namespace
Specify the namespace to build the list for.
Specify the namespace to build the list for. If no namespace is specified,
then an empty hash reference will be returned.
=head3 clause
An extra clause that can be used to further limit the list, such as "assetData.status='approved'
=cut
@ -211,8 +216,15 @@ sub getList {
my $class = shift;
my $session = shift;
my $namespace = shift;
my $sql = "select asset.assetId, assetData.revisionDate from template left join asset on asset.assetId=template.assetId left join assetData on assetData.revisionDate=template.revisionDate and assetData.assetId=template.assetId where template.namespace=".$session->db->quote($namespace)." and template.showInForms=1 and asset.state='published' and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=".$session->db->quote($session->scratch->get("versionTag")).")) order by assetData.title";
my $sth = $session->dbSlave->read($sql);
my $clause = shift;
if ($clause) {
$clause = ' and ' . $clause;
}
else {
$clause = '';
}
my $sql = "select asset.assetId, assetData.revisionDate from template left join asset on asset.assetId=template.assetId left join assetData on assetData.revisionDate=template.revisionDate and assetData.assetId=template.assetId where template.namespace=? and template.showInForms=1 and asset.state='published' and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=?)) $clause order by assetData.title";
my $sth = $session->dbSlave->read($sql, [$namespace, $session->scratch->get("versionTag")]);
my %templates;
tie %templates, 'Tie::IxHash';
while (my ($id, $version) = $sth->array) {

View file

@ -44,7 +44,6 @@ sub addRevision {
my $now = time();
$newSelf->update({
isHidden => 1,
dateUpdated=>$now,
});
return $newSelf;
}
@ -227,17 +226,21 @@ sub processPropertiesFromFormPost {
my $self = shift;
$self->SUPER::processPropertiesFromFormPost(@_);
my $actionTaken = ($self->session->form->process("assetId") eq "new") ? "Created" : "Edited";
$self->update({ groupIdView => $self->getWiki->get('groupIdView'),
groupIdEdit => $self->getWiki->get('groupToAdminister'),
my $wiki = $self->getWiki;
$self->update({ groupIdView => $wiki->get('groupIdView'),
groupIdEdit => $wiki->get('groupToAdminister'),
actionTakenBy => $self->session->user->userId,
actionTaken => $actionTaken,
});
if ($self->getWiki->canAdminister) {
if ($wiki->canAdminister) {
$self->update({isProtected => $self->session->form("isProtected")});
}
my $options = {
maxImageSize => $wiki->get('maxImageSize'),
thumbnailSize => $wiki->get('thumbnailSize'),
};
# deal with attachments from the attachments form control
my @attachments = $self->session->form->param("attachments");
my @tags = ();
@ -252,6 +255,7 @@ sub processPropertiesFromFormPost {
groupIdView => $self->get("groupIdView"),
});
}
$asset->applyConstraints($options);
push(@tags, $asset->get("tagId"));
$asset->setVersionTag($self->get("tagId"));
}

View file

@ -975,7 +975,7 @@ sub view {
$var->{"urlSearch"} = $self->getSearchUrl;
$var->{"urlPrint"} = $self->getUrl("type=".$params->{type}.";start=".$params->{start}.";print=1");
$var->{"urlIcal"} = $self->getUrl(
sprintf "func=ical;type=%s;start=%d",
sprintf "func=ical;type=%s;start=%s",
$params->{type},
$params->{start},
);
@ -1510,7 +1510,7 @@ sub www_ical {
#}
#else
#{
$dt_start = WebGUI::DateTime->new($self->session, time-60*60*24*30)->set_time_zone($session->user->profileField("timeZone"));
$dt_start = WebGUI::DateTime->new($self->session, time)->set_time_zone($session->user->profileField("timeZone"));
#}
}
else {
@ -1667,7 +1667,7 @@ sub www_search {
keywords => $keywords,
classes => ['WebGUI::Asset::Event'],
lineage => [$self->get("lineage")],
join => "join Event on assetIndex.assetId=Event.assetId",
join => "join Event on assetIndex.assetId=Event.assetId and assetIndex.revisionDate=Event.revisionDate",
columns => ['Event.startDate','Event.startTime'],
);

View file

@ -93,15 +93,17 @@ sub appendPostListTemplateVars {
my $p = shift;
my $page = $p->getPageData;
my $i = 0;
my ($icon, $datetime) = $self->session->quick(qw(icon datetime));
foreach my $row (@$page) {
my $post = WebGUI::Asset->new($self->session,$row->{assetId}, $row->{className}, $row->{revisionDate});
$post->{_parent} = $self; # caching parent for efficiency
my $controls = $self->session->icon->delete('func=delete',$post->get("url"),"Delete").$self->session->icon->edit('func=edit',$post->get("url"));
my $controls = $icon->delete('func=delete',$post->get("url"),"Delete") . $icon->edit('func=edit',$post->get("url"));
if ($self->get("sortBy") eq "lineage") {
if ($self->get("sortOrder") eq "desc") {
$controls .= $self->session->icon->moveUp('func=demote',$post->get("url")).$self->session->icon->moveDown('func=promote',$post->get("url"));
} else {
$controls .= $self->session->icon->moveUp('func=promote',$post->get("url")).$self->session->icon->moveDown('func=demote',$post->get("url"));
$controls .= $icon->moveUp('func=demote',$post->get("url")).$icon->moveDown('func=promote',$post->get("url"));
}
else {
$controls .= $icon->moveUp('func=promote',$post->get("url")).$icon->moveDown('func=demote',$post->get("url"));
}
}
my @rating_loop;
@ -114,13 +116,13 @@ sub appendPostListTemplateVars {
if ($self->get("displayLastReply")) {
my $lastPost = $post->getLastPost();
%lastReply = (
"lastReply.url"=>$lastPost->getUrl.'#'.$lastPost->getId,
"lastReply.title"=>$lastPost->get("title"),
"lastReply.user.isVisitor"=>$lastPost->get("ownerUserId") eq "1",
"lastReply.username"=>$lastPost->get("username"),
"lastReply.userProfile.url"=>$lastPost->WebGUI::Asset::Post::getPosterProfileUrl(),
"lastReply.dateSubmitted.human"=>$self->session->datetime->epochToHuman($lastPost->get("dateSubmitted"),"%z"),
"lastReply.timeSubmitted.human"=>$self->session->datetime->epochToHuman($lastPost->get("dateSubmitted"),"%Z")
"lastReply.url" => $lastPost->getUrl.'#'.$lastPost->getId,
"lastReply.title" => $lastPost->get("title"),
"lastReply.user.isVisitor" => $lastPost->get("ownerUserId") eq "1",
"lastReply.username" => $lastPost->get("username"),
"lastReply.userProfile.url" => $lastPost->getPosterProfileUrl(),
"lastReply.dateSubmitted.human" => $datetime->epochToHuman($lastPost->get("creationDate"),"%z"),
"lastReply.timeSubmitted.human" => $datetime->epochToHuman($lastPost->get("creationDate"),"%Z"),
);
}
$hasRead = $post->isMarkedRead;
@ -133,32 +135,32 @@ sub appendPostListTemplateVars {
}
my %postVars = (
%{$post->get},
"id"=>$post->getId,
"url"=>$url,
rating_loop=>\@rating_loop,
"content"=>$post->formatContent,
"status"=>$post->getStatus,
"thumbnail"=>$post->getThumbnailUrl,
"image.url"=>$post->getImageUrl,
"dateSubmitted.human"=>$self->session->datetime->epochToHuman($post->get("dateSubmitted"),"%z"),
"dateUpdated.human"=>$self->session->datetime->epochToHuman($post->get("dateUpdated"),"%z"),
"timeSubmitted.human"=>$self->session->datetime->epochToHuman($post->get("dateSubmitted"),"%Z"),
"timeUpdated.human"=>$self->session->datetime->epochToHuman($post->get("dateUpdated"),"%Z"),
"userProfile.url"=>$post->getPosterProfileUrl,
"user.isVisitor"=>$post->get("ownerUserId") eq "1",
"edit.url"=>$post->getEditUrl,
'controls'=>$controls,
"isSecond"=>(($i+1)%2==0),
"isThird"=>(($i+1)%3==0),
"isFourth"=>(($i+1)%4==0),
"isFifth"=>(($i+1)%5==0),
"user.hasRead" => $hasRead,
"user.isPoster"=>$post->isPoster,
"avatar.url"=>$post->getAvatarUrl,
"id" => $post->getId,
"url" => $url,
rating_loop => \@rating_loop,
"content" => $post->formatContent,
"status" => $post->getStatus,
"thumbnail" => $post->getThumbnailUrl,
"image.url" => $post->getImageUrl,
"dateSubmitted.human" => $datetime->epochToHuman($post->get("creationDate"),"%z"),
"dateUpdated.human" => $datetime->epochToHuman($post->get("revisionDate"),"%z"),
"timeSubmitted.human" => $datetime->epochToHuman($post->get("creationDate"),"%Z"),
"timeUpdated.human" => $datetime->epochToHuman($post->get("revisionDate"),"%Z"),
"userProfile.url" => $post->getPosterProfileUrl,
"user.isVisitor" => $post->get("ownerUserId") eq "1",
"edit.url" => $post->getEditUrl,
'controls' => $controls,
"isSecond" => (($i+1)%2==0),
"isThird" => (($i+1)%3==0),
"isFourth" => (($i+1)%4==0),
"isFifth" => (($i+1)%5==0),
"user.hasRead" => $hasRead,
"user.isPoster" => $post->isPoster,
"avatar.url" => $post->getAvatarUrl,
%lastReply
);
$post->getTemplateMetadataVars(\%postVars);
if ($row->{className} eq 'WebGUI::Asset::Post::Thread') {
if ($row->{className} =~ m/^WebGUI::Asset::Post::Thread/) {
$postVars{'rating'} = $post->get('threadRating');
}
push(@{$var->{post_loop}}, \%postVars );
@ -363,8 +365,8 @@ sub definition {
my %sortByOptions;
tie %sortByOptions, 'Tie::IxHash';
%sortByOptions = (lineage=>$i18n->get('sequence'),
dateUpdated=>$i18n->get('date updated'),
dateSubmitted=>$i18n->get('date submitted'),
"assetData.revisionDate"=>$i18n->get('date updated'),
creationDate=>$i18n->get('date submitted'),
title=>$i18n->get('title'),
userDefined1=>$i18n->get('user defined 1'),
userDefined2=>$i18n->get('user defined 2'),
@ -611,7 +613,7 @@ sub definition {
},
sortBy =>{
fieldType=>"selectBox",
defaultValue=>'dateUpdated',
defaultValue=>'assetData.revisionDate',
tab=>'display',
options=>\%sortByOptions,
label=>$i18n->get('sort by'),
@ -753,6 +755,12 @@ sub duplicate {
return $newAsset;
}
#-------------------------------------------------------------------
# Too slow to try to find out children, just always assume new data
sub getContentLastModified {
return time();
}
#-------------------------------------------------------------------
sub getEditTabs {
my $self = shift;
@ -781,7 +789,8 @@ sub getRssItems {
# XXX copied and reformatted this query from www_viewRSS, but why is it constructed like this?
# And it's duplicated inside view, too! Eeeagh! And it uses the versionTag scratch var...
my ($sortBy, $sortOrder) = ($self->getValue('sortBy'), $self->getValue('sortOrder'));
my @postIds = $self->session->db->buildArray(<<"SQL", [$self->getId, $self->session->scratch->get('versionTag')]);
my @postIds = $self->session->db->buildArray(<<"SQL", [$self->getId, $self->session->scratch->get('versionTag')]);
SELECT asset.assetId
FROM Thread
LEFT JOIN asset ON Thread.assetId = asset.assetId
@ -823,7 +832,7 @@ SQL
'link' => $postUrl,
guid => $postUrl,
description => $post->get('synopsis'),
pubDate => $datetime->epochToMail($post->get('dateUpdated')),
pubDate => $datetime->epochToMail($post->get('revisionDate')),
attachmentLoop => $attachmentLoop,
userDefined1 => $post->get("userDefined1"),
userDefined2 => $post->get("userDefined2"),
@ -925,7 +934,7 @@ sub getThreadsPaginator {
my $scratchSortBy = $self->getId."_sortBy";
my $scratchSortOrder = $self->getId."_sortDir";
my $sortBy = $self->session->form->process("sortBy") || $self->session->scratch->get($scratchSortBy) || $self->get("sortBy");
my $sortOrder = $self->session->scratch->get($scratchSortOrder) || $self->get("sortOrder");
my $sortOrder = $self->session->scratch->get($scratchSortOrder) || $self->get("sortOrder");
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
} elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") {
@ -936,13 +945,13 @@ sub getThreadsPaginator {
}
$self->session->scratch->set($scratchSortOrder, $sortOrder);
}
$sortBy ||= "dateUpdated";
$sortBy ||= "assetData.revisionDate";
$sortOrder ||= "desc";
# Sort by the thread rating instead of the post rating. other places don't care about threads.
if ($sortBy eq 'rating') {
$sortBy = 'threadRating';
}
$sortBy = $self->session->db->dbh->quote_identifier($sortBy);
my $sql = "
select
asset.assetId,
@ -1007,7 +1016,7 @@ sub getViewTemplateVars {
$var{'sortby.username.url'} = $self->getSortByUrl("username");
$var{'karmaIsEnabled'} = $self->session->setting->get("useKarma");
$var{'sortby.karmaRank.url'} = $self->getSortByUrl("karmaRank");
$var{'sortby.date.url'} = $self->getSortByUrl("dateSubmitted");
$var{'sortby.date.url'} = $self->getSortByUrl("creationDate");
$var{'sortby.lastreply.url'} = $self->getSortByUrl("lastPostDate");
$var{'sortby.views.url'} = $self->getSortByUrl("views");
$var{'sortby.replies.url'} = $self->getSortByUrl("replies");

View file

@ -95,15 +95,29 @@ sub definition {
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
sub discernUserId {
my $self = shift;
return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId;
}
#-------------------------------------------------------------------
sub getContentPositions {
my $self = shift;
my $dummy = $self->initialize unless $self->get("isInitialized");
my $u = WebGUI::User->new($self->session, $self->discernUserId);
return $u->profileField($self->getId.'contentPositions')
return $u->profileField($self->getContentPositionsId)
|| $self->getContentPositionsDefault;
}
#-------------------------------------------------------------------
sub getContentPositionsId {
my $self = shift;
my $id = "contentPositions".$self->getId;
$id =~ s/-/_/g;
return $id;
}
#-------------------------------------------------------------------
=head2 getContentPositionsDefault ( )
@ -117,13 +131,7 @@ sub getContentPositionsDefault {
my $dummy = $self->initialize unless $self->get("isInitialized");
# The default positions are saved under the "Visitor" user
my $u = WebGUI::User->new($self->session, 1);
return $u->profileField($self->getId.'contentPositions');
}
#-------------------------------------------------------------------
sub discernUserId {
my $self = shift;
return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId;
return $u->profileField($self->getContentPositionsId);
}
#-------------------------------------------------------------------
@ -154,13 +162,13 @@ sub getEditForm {
#-------------------------------------------------------------------
sub initialize {
my $self = shift;
my $userPrefField = WebGUI::ProfileField->create($self->session,$self->getId.'contentPositions',{
my $userPrefField = WebGUI::ProfileField->create($self->session,$self->getContentPositionsId,{
label=>'\'Dashboard User Preference - Content Positions\'',
visible=>0,
protected=>1,
editable=>0,
required=>0,
fieldType=>'text'
fieldType=>'textarea'
});
$self->update({isInitialized=>1});
}
@ -201,6 +209,17 @@ sub processPropertiesFromFormPost {
}
}
#-------------------------------------------------------------------
sub purge {
my $self = shift;
my $userPrefField = WebGUI::ProfileField->new($self->session,$self->getContentPositionsId);
if (defined $userPrefField) {
$userPrefField->delete;
}
$self->SUPER::purge(@_);
}
#-------------------------------------------------------------------
sub view {
my $self = shift;
@ -309,7 +328,7 @@ sub www_setContentPositions {
return 'empty' unless $self->get("isInitialized");
my $dummy = $self->initialize unless $self->get("isInitialized");
my $u = WebGUI::User->new($self->session, $self->discernUserId);
my $success = $u->profileField($self->getId.'contentPositions',$self->session->form->process("map")) eq $self->session->form->process("map");
my $success = $u->profileField($self->getContentPositionsId,$self->session->form->process("map")) eq $self->session->form->process("map");
return "Map set: ".$self->session->form->process("map") if $success;
return "Map failed to set.";
}

View file

@ -503,6 +503,8 @@ sub getRecordTemplateVars {
$where .= " and b.DataForm_entryId=".$self->session->db->quote($var->{entryId});
$join = "left join DataForm_entryData as b on a.DataForm_fieldId=b.DataForm_fieldId";
$select .= ", b.value";
$var->{"delete.url"} = $self->getUrl('func=deleteEntry;entryId='.$var->{entryId});
$var->{"delete.label"} = $i18n->get(90);
}
my %data;
tie %data, 'Tie::CPHash';
@ -628,8 +630,6 @@ sub getTemplateVars {
$var->{"entryList.label"} = $i18n->get(86);
$var->{"export.tab.url"} = $self->getUrl('func=exportTab');
$var->{"export.tab.label"} = $i18n->get(84);
$var->{"delete.url"} = $self->getUrl('func=deleteEntry;entryId='.$var->{entryId});
$var->{"delete.label"} = $i18n->get(90);
$var->{"addField.url"} = $self->getUrl('func=editField');
$var->{"addField.label"} = $i18n->get(76);
$var->{"deleteAllEntries.url"} = $self->getUrl("func=deleteAllEntriesConfirm");
@ -816,7 +816,7 @@ sub sendEmail {
sentBy => $self->session->user->userId,
subject=>$subject,
message=>$message,
status=>'complete'
status=>'unread'
});
if ($cc) {
my $mail = WebGUI::Mail::Send->create($self->session,{to=>$cc, replyTo=>$from, subject=>$subject, from=>$from});

View file

@ -281,6 +281,14 @@ sub www_compare {
unless (scalar(@cmsList)) {
@cmsList = $self->session->form->checkList("listingId");
}
my ($style, $url) = ($self->session->style, $self->session->url);
$style->setLink($url->extras('/yui/build/container/assets/container.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setLink($url->extras('/hoverhelp.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setScript($url->extras('/yui/build/yahoo/yahoo-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/dom/dom-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/event/event-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/container/container-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/hoverhelp.js'),{ type=>'text/javascript' });
my ( %var, @prodcol, @datecol);
my $max = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("maxComparisonsPrivileged") : $self->get("maxComparisons");
$var{isTooMany} = (scalar(@cmsList)>$max);
@ -303,12 +311,20 @@ sub www_compare {
lastUpdated=>$self->session->datetime->epochToHuman($data->{lastUpdated},"%z")
});
}
my $i18n = WebGUI::International->new($self->session,'Asset_Matrix');
my %goodBad = (
"No" => $i18n->get("no"),
"Yes" => $i18n->get("yes"),
"Free Add On" => $i18n->get("free"),
"Costs Extra" => $i18n->get("extra"),
"Limited" => $i18n->get("limited"),
);
$var{product_loop} = \@prodcol;
$var{lastupdated_loop} = \@datecol;
my @categoryloop;
foreach my $category ($self->getCategories()) {
my @rowloop;
my $select = "select a.label, a.description";
my $select = "select a.fieldType, a.label, a.description";
my $from = "from Matrix_field a";
my $tableCount = "b";
foreach my $cms (@cmsList) {
@ -321,17 +337,17 @@ sub www_compare {
while (my @row = $sth->array) {
my @columnloop;
my $first = 1;
my $type = shift @row;
foreach my $value (@row) {
my $desc = "";
if ($first) {
$desc = $row[1];
shift(@row);
$desc =~ s/\n//g;
$desc =~ s/\r//g;
$desc =~ s/'/\\\'/g;
$desc =~ s/"/\&quot;/g;
$first = 0;
}
elsif ($type eq 'goodBad') {
$value = $goodBad{$value};
}
my $class = lc($value);
$class =~ s/\s/_/g;
$class =~ s/\W//g;
@ -729,7 +745,7 @@ sub www_editListingSave {
addEditStampToPosts => 0,
usePreview => 1,
sortOrder => 'desc',
sortBy => 'dateUpdated',
sortBy => 'assetData.revisionDate',
rssTemplateId=>'PBtmpl0000000000000142',
notificationTemplateId=>'PBtmpl0000000000000027',
searchTemplateId=>'PBtmpl0000000000000031',
@ -972,10 +988,6 @@ sub www_search {
my $sth = $self->session->db->read("select name, fieldType, label, description from Matrix_field where category = ".$self->session->db->quote($category)." order by label");
my @loop;
while (my $data = $sth->hashRef) {
$data->{description} =~ s/\n//g;
$data->{description} =~ s/\r//g;
$data->{description} =~ s/'/\\\'/g;
$data->{description} =~ s/"/\&quot;/g;
if ($data->{fieldType} ne "goodBad") {
$data->{form} = WebGUI::Form::text($self->session,{
name=>$data->{name},
@ -1214,16 +1226,22 @@ sub www_viewDetail {
$var{views} = $listing->{views};
$var{compares} = $listing->{compares};
$var{clicks} = $listing->{clicks};
my $sth = $self->session->db->read("select a.value, b.name, b.label, b.description, category from Matrix_listingData a left join
my $sth = $self->session->db->read("select a.value, b.name, b.label, b.description, category, fieldType from Matrix_listingData a left join
Matrix_field b on a.fieldId=b.fieldId and b.assetId=? where listingId=? order by b.label",[$self->getId, $listingId]);
while (my $data = $sth->hashRef) {
$data->{description} =~ s/\n//g;
$data->{description} =~ s/\r//g;
$data->{description} =~ s/'/\\\'/g;
$data->{description} =~ s/"/\&quot;/g;
$data->{class} = lc($data->{value});
my %goodBad = (
"No" => $i18n->get("no"),
"Yes" => $i18n->get("yes"),
"Free Add On" => $i18n->get("free"),
"Costs Extra" => $i18n->get("extra"),
"Limited" => $i18n->get("limited"),
);
while (my $data = $sth->hashRef) {
$data->{class} = lc($data->{value});
$data->{class} =~ s/\s/_/g;
$data->{class} =~ s/\W//g;
if ($data->{fieldType} eq 'goodBad') {
$data->{value} = $goodBad{$data->{value}};
}
my $cat = $self->session->url->urlize($data->{category})."_loop";
push(@{$var{$cat}},$data);
}

View file

@ -119,9 +119,9 @@ sub view {
if (defined $lastPost) {
%lastPostVars = (
'forum.lastPost.url' => $lastPost->getUrl,
'forum.lastPost.date' => $self->session->datetime->epochToHuman($lastPost->get("dateSubmitted"),"%z"),
'forum.lastPost.time' => $self->session->datetime->epochToHuman($lastPost->get("dateSubmitted"),"%Z"),
'forum.lastPost.epoch' => $lastPost->get("dateSubmitted"),
'forum.lastPost.date' => $self->session->datetime->epochToHuman($lastPost->get("creationDate"),"%z"),
'forum.lastPost.time' => $self->session->datetime->epochToHuman($lastPost->get("creationDate"),"%Z"),
'forum.lastPost.epoch' => $lastPost->get("creationDate"),
'forum.lastPost.subject' => $lastPost->get("title"),
'forum.lastPost.user.hasRead' => $lastPost->getThread->isMarkedRead,
'forum.lastPost.user.id' => $lastPost->get("ownerUserId"),

View file

@ -1055,14 +1055,14 @@ sub www_editProject {
my $hpdLabel = $i18n->get('hours per day label');
my $hpdHoverHelp = $i18n->get('hours per day hoverhelp');
$hpdHoverHelp =~ s/'/\\'/g;
my $hpdValue = $form->get("hoursPerDay") || $project->{hoursPerDay} || "8.0";
my $hpdStyle = ($dunitValue eq "days"?"display:none":"");
my $html = qq|
<tr id="hoursper" style="$hpdStyle">
<td class="formDescription" onmouseover="return escape('$hpdHoverHelp')" valign="top" style="width: 180px;">
<label for="hoursPerDay_formId">$hpdLabel</label>
<td class="formDescription" valign="top" style="width: 180px;">
<div class="wg-hoverhelp">$hpdHoverHelp</div>
<label for="hoursPerDay_formId">$hpdLabel</label>
</td>
<td valign="top" class="tableData" style="width: *;">
<input id="hoursPerDay_formId" type="text" name="hoursPerDay" value="$hpdValue" size="11" maxlength="14" />

View file

@ -40,12 +40,16 @@ sub appendRecentChanges {
my $self = shift;
my $var = shift;
my $limit = shift || $self->get("recentChangesCount") || 50;
foreach my $asset (@{$self->getLineage(["children"], {
returnObjects => 1,
limit => $limit,
includeOnlyClasses =>["WebGUI::Asset::WikiPage"],
orderByClause => "assetData.revisionDate desc"
})}) {
my $revisions = $self->session->db->read("select asset.assetId, assetData.revisionDate, asset.className
from asset left join assetData using (assetId) where asset.parentId=? and asset.className
like ? order by assetData.revisionDate desc limit ?", [$self->getId,
"WebGUI::Asset::WikiPage%", $limit]);
while (my ($id, $version, $class) = $revisions->array) {
my $asset = WebGUI::Asset->new($self->session, $id, $class, $version);
unless (defined $asset) {
$self->session->errorHandler->error("Asset $id $class $version could not be instanciated.");
next;
}
my $user = WebGUI::User->new($self->session, $asset->get("actionTakenBy"));
my $specialAction = '';
my $isAvailable = 1;

View file

@ -363,16 +363,18 @@ sub getLineage {
}
# now lets add in all of the siblings in every level between ourself and the asset we wish to pedigree
if (isIn("pedigree",@{$relatives}) && exists $rules->{assetToPedigree}) {
my @mods;
my $lineage = $rules->{assetToPedigree}->get("lineage");
my $length = $rules->{assetToPedigree}->getLineageLength;
for (my $i = $length; $i > 0; $i--) {
my $line = substr($lineage,0,$i*6);
push(@mods,"( asset.lineage like ".$self->session->db->quote($line.'%')." and length(asset.lineage)=".(($i+1)*6).")");
last if ($self->getLineageLength == $i);
}
push(@whereModifiers, "(".join(" or ",@mods).")") if (scalar(@mods));
}
my $pedigreeLineage = $rules->{assetToPedigree}->get("lineage");
if (substr($pedigreeLineage,0,length($lineage)) eq $lineage) {
my @mods;
my $length = $rules->{assetToPedigree}->getLineageLength;
for (my $i = $length; $i > 0; $i--) {
my $line = substr($pedigreeLineage,0,$i*6);
push(@mods,"( asset.lineage like ".$self->session->db->quote($line.'%')." and length(asset.lineage)=".(($i+1)*6).")");
last if ($self->getLineageLength == $i);
}
push(@whereModifiers, "(".join(" or ",@mods).")") if (scalar(@mods));
}
}
# deal with custom joined tables if we must
my $tables = "asset left join assetData on asset.assetId=assetData.assetId ";
if (exists $rules->{joinClass}) {
@ -422,7 +424,10 @@ sub getLineage {
$where .= ' and (asset.className in ('.$self->session->db->quoteAndJoin($rules->{includeOnlyClasses}).'))';
}
## finish up our where clause
$where .= ' and ('.join(" or ",@whereModifiers).')' if (scalar(@whereModifiers));
if (!scalar(@whereModifiers)) {
return [];
}
$where .= ' and ('.join(" or ",@whereModifiers).')';
if (exists $rules->{whereClause} && $rules->{whereClause}) {
$where .= ' and ('.$rules->{whereClause}.')';
}

View file

@ -300,7 +300,8 @@ sub createAccountSave {
my $properties;
$properties->{connectDN} = $connectDN;
$properties->{ldapUrl} = $connection->{ldapUrl};
$properties->{ldapConnection} = $connection->{ldapLinkId};
return $self->SUPER::createAccountSave($username,$properties,$password,$profile);
}
@ -503,7 +504,8 @@ sub login {
if ($self->validUsername($username)) {
$self->SUPER::createAccountSave($username, {
connectDN => $self->getConnectDN,
ldapUrl => $self->getLDAPConnection->{ldapUrl}
ldapUrl => $self->getLDAPConnection->{ldapUrl},
ldapConnection => $self->getLDAPConnection->{ldapLinkId},
},$identifier);
$hasAuthenticated = 1;

View file

@ -257,10 +257,10 @@ sub displayFormWithWrapper {
my $self = shift;
if ($self->passUiLevelCheck) {
my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper;
my $hoverCode = $self->getHoverCode($hoverHelp, $self->get('id') . '_wrapper');
$hoverHelp &&= '<div class="wg-hoverhelp">' . $hoverHelp . '</div>';
return '<tr'.$rowClass.'>
<td'.$labelClass.' valign="top" style="width: 25%;">'.$self->get("label").'</td>
<td valign="top"'.$fieldClass.' style="width: 75%;">'.$self->displayForm().$subtext.$hoverCode."</td>
<td'.$labelClass.' valign="top" style="width: 25%;">'.$self->get("label") . $hoverHelp . '</td>
<td valign="top"'.$fieldClass.' style="width: 75%;">'.$self->displayForm().$subtext."</td>
</tr>\n";
} else {
return $self->toHtmlAsHidden;
@ -542,8 +542,9 @@ sub prepareWrapper {
$labelClass = qq| class="$labelClass" | if($self->get("labelClass"));
my $fieldClass = $self->get("fieldClass");
$fieldClass = qq| class="$fieldClass" | if($self->get("fieldClass"));
my $hoverHelp = $self->get("hoverHelp");
my $subtext = $self->get("subtext");
my $hoverHelp = $self->get("hoverHelp") || '';
$hoverHelp =~ s/^\s+//;
my $subtext = $self->get("subtext");
$subtext = qq| <span class="formSubtext">$subtext</span>| if ($subtext);
return ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext);
}
@ -625,10 +626,10 @@ sub toHtmlWithWrapper {
if ($self->passUiLevelCheck) {
my $rawField = $self->toHtml(); # has to be called before prepareWrapper for some controls, namely captcha.
my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper;
my $hoverCode = $self->getHoverCode($hoverHelp, $self->get('id') . '_description');
$hoverHelp &&= '<div class="wg-hoverhelp">' . $hoverHelp . '</div>';
return '<tr'.$rowClass.' id="'.$self->get("id").'_row">
<td'.$labelClass.' id="' . $self->get('id') . '_description" valign="top" style="width: 180px;"><label for="'.$self->get("id").'">'.$self->get("label").'</label></td>
<td valign="top"'.$fieldClass.'>'.$rawField . $subtext . $hoverCode . "</td>
<td'.$labelClass.' valign="top" style="width: 180px;"><label for="'.$self->get("id").'">'.$self->get("label").'</label>' . $hoverHelp . '</td>
<td valign="top"'.$fieldClass.'>'.$rawField . $subtext . "</td>
</tr>\n";
} else {
return $self->toHtmlAsHidden;
@ -637,43 +638,6 @@ sub toHtmlWithWrapper {
#-------------------------------------------------------------------
=head2 getHoverCode ( hoverHelp, attachId )
Generated the code to add hover help to html elements.
=head3 hoverHelp
The text in include in the hover help.
=head3 attachId
The id of the HTML element to attach the hover help to.
=cut
sub getHoverCode {
my $self = shift;
my $style = $self->session->style;
my $url = $self->session->url;
my $hoverHelp = shift;
my $attachId = shift;
$hoverHelp =~ s/\r/ /g;
$hoverHelp =~ s/\n/ /g;
$hoverHelp =~ s/'/\\'/g;
$hoverHelp =~ s/^\s+//;
return ''
unless $hoverHelp;
my $hover = '<script type="text/javascript">var tooltip = new YAHOO.widget.Tooltip("' . $attachId . '_tooltip", { context: "' . $attachId . '", text: \'' . $hoverHelp . '\', autodismissdelay: 100000, width: "300px"});</script>';
$style->setLink($url->extras('/hoverhelp.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setScript($url->extras('/yui/build/yahoo/yahoo-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/dom/dom-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/event/event-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/container/container-min.js'),{ type=>'text/javascript' });
return $hover;
}
#-------------------------------------------------------------------
=head2 passUiLevelCheck ( )
Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc.

View file

@ -143,7 +143,7 @@ sub displayValue {
return '' unless $self->get("value");
my $location = WebGUI::Storage->get($self->session,$self->get("value"));
my $file = shift @{ $location->getFiles };
my $fileValue = sprintf qq|<img src="%s" />&nbsp;%s|, $location->getFileIconUrl($file), $file;
my $fileValue = sprintf qq|<img src="%s" />&nbsp;<a href="%s">%s</a>|, $location->getFileIconUrl($file), $location->getUrl($file), $file;
return $fileValue;
}

View file

@ -59,6 +59,10 @@ The namespace for the list of templates to return. If this is omitted, all templ
A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName().
=head4 onlyCommitted
If true, this will limit the list of template to only include templates that are committed.
=cut
sub definition {
@ -79,6 +83,9 @@ sub definition {
namespace=>{
defaultValue=>undef
},
onlyCommitted=>{
defaultValue=>''
},
dbDataType => {
defaultValue => "VARCHAR(22) BINARY",
},
@ -96,14 +103,15 @@ Renders a template picker control.
sub toHtml {
my $self = shift;
my $templateList = WebGUI::Asset::Template->getList($self->session, $self->get("namespace"));
#Remove entries from template list that the user does not have permission to view.
for my $assetId ( keys %{$templateList} ) {
my $asset = WebGUI::Asset::Template->new($self->session, $assetId);
if (!$asset->canView($self->session->user->userId)) {
delete $templateList->{$assetId};
}
my $onlyCommitted = $self->get('onlyCommitted') ? "assetData.status='approved'" : $self->get('onlyCommitted');
my $templateList = WebGUI::Asset::Template->getList($self->session, $self->get("namespace"), $onlyCommitted);
#Remove entries from template list that the user does not have permission to view.
for my $assetId ( keys %{$templateList} ) {
my $asset = WebGUI::Asset::Template->new($self->session, $assetId);
if (!$asset->canView($self->session->user->userId)) {
delete $templateList->{$assetId};
}
}
$self->set("options", $templateList);
return $self->SUPER::toHtml();
}

318
lib/WebGUI/Friends.pm Normal file
View file

@ -0,0 +1,318 @@
package WebGUI::Friends;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 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::InsideOut qw(id register public readonly);
use WebGUI::DateTime;
use WebGUI::HTML;
use WebGUI::Inbox;
use WebGUI::International;
use WebGUI::User;
use WebGUI::Utility;
readonly session => my %session;
readonly user => my %user;
=head1 NAME
WebGUI::Friends
=head1 SYNOPSIS
my $friends = WebGUI::Friends->new($session, $user);
$friends->add(\@userIds);
$friends->remove(\@userIds);
=head1 DESCRIPTION
A user relationship management system.
=head1 METHODS
=cut
#-------------------------------------------------------------------
=head2 add ( \@userIds )
Add friends. Also adds the reciprocal relationship.
=head3 userIds
An array reference of userIds to add as friends.
=cut
sub add {
my $self = shift;
my $userIds = shift;
my $me = $self->user;
$me->friends->addUsers($userIds);
foreach my $userId (@{$userIds}) {
my $friend = WebGUI::User->new($self->session, $userId);
$friend->friends->addUsers([$me->userId]);
}
}
#-------------------------------------------------------------------
=head2 approveAddRequest ( inviteId )
Sends an approval, sets up the relationship, and deletes the invitation.
=head3 inviteId
The unique idenitifer for this invitation.
=cut
sub approveAddRequest {
my $self = shift;
my $inviteId = shift;
my $db = $self->session->db;
my $invite = $self->getAddRequest($inviteId);
$self->add([$invite->{inviterId}]);
my $i18n = WebGUI::International->new($self->session, "Friends");
my $inbox = WebGUI::Inbox->new($self->session);
$inbox->addMessage({
message => sprintf($i18n->get("invitation accepted by user"), $self->user->getWholeName),
subject => $i18n->get('friends invitation accepted'),
userId => $invite->{inviterId},
status => 'unread',
sentBy => $self->user->userId,
});
$inbox->getMessage($invite->{messageId})->setStatus('completed');
$db->deleteRow("friendInvitations", "inviteId", $inviteId);
}
#-------------------------------------------------------------------
=head2 delete ( \@userIds )
Remove friends.
=head3 userIds
An array reference of userIds to remove from friends list.
=cut
sub delete {
my $self = shift;
my $userIds = shift;
$self->user->friends->deleteUsers($userIds);
}
#-------------------------------------------------------------------
=head2 getAddRequest ( inviteId )
Returns the invitation data as a hash reference.
=cut
sub getAddRequest {
my $self = shift;
my $inviteId = shift;
my $invite = $self->session->db->getRow('friendInvitations', 'inviteId', $inviteId);
}
#-------------------------------------------------------------------
=head getAllPendingAddRequests ( session )
Class method. Returns a WebGUI::SQL::ResultSet object with all the unanswered add requests.
=cut
sub getAllPendingAddRequests {
my $class = shift;
my $session = shift;
return $session->db->read("select * from friendInvitations order by dateSent");
}
#-------------------------------------------------------------------
=head2 isFriend ( userId )
Returns a booelean indicating whether the userId is already a friend of this user.
=head3 userId
The userId to check against this user.
=cut
sub isFriend {
my $self = shift;
my $userId = shift;
return isIn($userId, @{$self->user->friends->getUsers});
}
#-------------------------------------------------------------------
=head2 new ( session, user )
Constructor.
=head3 session
A reference to the current WebGUI::Session object.
=head3 user
A reference to a WebGUI::User object that we're going to manage the friends of. Defaults to the current user
attached to the session.
=cut
sub new {
my $class = shift;
my $session = shift;
my $user = shift || $session->user;
my $self = register($class);
$session{id $self} = $session;
$user{id $self} = $user;
return $self;
}
#-------------------------------------------------------------------
=head2 rejectAddRequest ( inviteId )
Sends a rejection notice, and deletes the invitation.
=head3 inviteId
The id of an invitation.
=cut
sub rejectAddRequest {
my $self = shift;
my $inviteId = shift;
my $db = $self->session->db;
my $invite = $self->getAddRequest($inviteId);
my $i18n = WebGUI::International->new($self->session, "Friends");
my $inbox = WebGUI::Inbox->new($self->session);
$inbox->addMessage({
message => sprintf($i18n->get("friends invitation not accepted by user"), $self->user->getWholeName),
subject => $i18n->get('friends invitation not accepted'),
userId => $invite->{inviterId},
status => 'unread',
});
$inbox->getMessage($invite->{messageId})->setStatus('completed');
$self->session->db->deleteRow("friendInvitations", "inviteId", $inviteId);
}
#-------------------------------------------------------------------
=head2 sendAddRequest ( userId, message )
Sends a request to another user to be added to this user's friends list. Returns an invitationId.
=head3 userId
The user to invite to be a friend.
=head3 message
The message to lure them to accept.
=cut
sub sendAddRequest {
my $self = shift;
my $userId = shift;
my $comments = shift;
my $i18n = WebGUI::International->new($self->session, "Friends");
# No sneaky attack paths...
$comments = WebGUI::HTML::filter($comments);
# Create the invitation url.
my $inviteId = $self->session->id->generate();
my $inviteUrl = $self->session->url->append($self->session->url->getSiteURL, 'op=friendRequest;inviteId='.$inviteId);
# Build the message
my $messageText = sprintf $i18n->get("invitation approval email"), $self->user->getWholeName, $self->session->url->getSiteURL, $comments, $inviteUrl;
# send message
my $message = WebGUI::Inbox->new($self->session)->addMessage({
message => $messageText,
subject => $i18n->get("friends network invitation"),
userId => $userId,
status => 'pending',
sentBy => $self->user->userId,
});
# Create the invitation record.
$self->session->db->setRow(
'friendInvitations',
'inviteId',
{
inviterId => $self->user->userId,
friendId => $userId,
dateSent => WebGUI::DateTime->new($self->session, time)->toMysql,
comments => $comments,
messageId => $message->getId,
},
$inviteId,
);
return $inviteId;
}
#-------------------------------------------------------------------
=head2 sendMessage ( subject, message, [ userIds ] )
=head3 subject
The subject of the message.
=head3 message
The message itself.
=head3 userIds
An array reference of userIds to send the message to. Defaults to all friends.
=cut
sub sendMessage {
my $self = shift;
my $subject = shift || "Untitled";
my $message = shift;
my $userIds = shift || $self->user->friends->getUsers;
my $inbox = WebGUI::Inbox->new($self->session);
my $myId = $self->user->userId;
foreach my $userId (@{$userIds}) {
$inbox->addPrivateMessage({
message => $message,
subject => $subject,
userId => $userId,
sentBy => $myId,
status => 'unread',
});
}
}
1;

View file

@ -215,6 +215,15 @@ Returns the HTML for this form object.
sub print {
my $self = shift;
my $style = $self->session->style;
my $url = $self->session->url;
$style->setLink($url->extras('/yui/build/container/assets/container.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setLink($url->extras('/hoverhelp.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setScript($url->extras('/yui/build/yahoo/yahoo-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/dom/dom-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/event/event-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/container/container-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/hoverhelp.js'),{ type=>'text/javascript' });
return $self->{_header}.$self->{_data}.$self->{_footer};
}

View file

@ -4,7 +4,7 @@ use strict;
use WebGUI::Image::Palette;
use Carp qw(croak);
my $graphicsPackage;
our $graphicsPackage;
BEGIN {
if (eval { require Graphics::Magick; 1 }) {
$graphicsPackage = 'Graphics::Magick';
@ -264,8 +264,12 @@ sub setImageHeight {
my $self = shift;
my $height = shift;
#$self->image->set(size => $self->getImageWidth.'x'.$height);
$self->image->Extent(height => $height);
if ($graphicsPackage eq 'Graphics::Magick') {
$self->image->Resize(height => $height);
}
else {
$self->image->Extent(height => $height);
}
$self->image->Colorize(fill => $self->getBackgroundColor);
$self->{_properties}->{height} = $height;
}
@ -285,9 +289,12 @@ Teh width of the image in pixels.
sub setImageWidth {
my $self = shift;
my $width = shift;
#$self->image->set(size => $width.'x'.$self->getImageHeight);
$self->image->Extent(width => $width);
if ($graphicsPackage eq 'Graphics::Magick') {
$self->image->Resize(width => $width);
}
else {
$self->image->Extent(width => $width);
}
$self->image->Colorize(fill => $self->getBackgroundColor);
$self->{_properties}->{width} = $width;
}
@ -410,8 +417,13 @@ sub text {
my $anchorX = $properties{x};
my $anchorY = $properties{y};
my ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) = $self->image->QueryMultilineFontMetrics(%properties);
my %testProperties = %properties;
delete $testProperties{align};
delete $testProperties{style};
delete $testProperties{fill};
delete $testProperties{alignHorizontal};
delete $testProperties{alignVertical};
my ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) = $self->image->QueryFontMetrics(%testProperties);
# Process horizontal alignment
if ($properties{alignHorizontal} eq 'center') {

View file

@ -422,8 +422,8 @@ sub getLabelDimensions {
my ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) = $self->image->QueryFontMetrics(
font => $self->getLabelFont->getFile,
# stroke => $self->getLabelColor,
fill => $self->getLabelColor,
style => 'Normal',
# fill => $self->getLabelColor,
# style => 'Normal',
pointsize => $self->getLabelFontSize,
%$properties,
text => $text,

View file

@ -172,33 +172,31 @@ sub drawLabels {
my $self = shift;
my $location = shift;
my %anchorPoint = %{$self->getFirstAnchorLocation};# %$location;
my %anchorPoint = %{$self->getFirstAnchorLocation};
# Draw x-axis labels
foreach (@{$self->getLabel}) {
my $text = $self->wrapLabelToWidth($_, $self->getAnchorSpacing->{x});
foreach my $text (@{$self->getLabel}) {
$self->drawLabel($text, (
alignHorizontal => 'center',
alignVertical => 'top',
align => 'Center',
align => 'left',
rotate => 90,
x => $anchorPoint{x},
y => $anchorPoint{y},
));
$anchorPoint{x} += $self->getAnchorSpacing->{x}; #$groupWidth + $self->getGroupSpacing;
$anchorPoint{x} += $self->getAnchorSpacing->{x};
$anchorPoint{y} += $self->getAnchorSpacing->{y};
}
# Draw y-axis labels
$anchorPoint{x} = $self->getChartOffset->{x} - $self->getLabelOffset;
$anchorPoint{y} = $self->getChartOffset->{y} + $self->getChartHeight;
# for (1 .. $self->getYRange / $self->getYGranularity) {
foreach (@{$self->getYLabels}) {
$self->drawLabel($_, (
alignHorizontal => 'right',
alignVertical => 'center',
x => $anchorPoint{x}, #$self->getChartOffset->{x} - $self->getLabelOffset,
y => $anchorPoint{y}, #$self->getChartOffset->{y} + $self->getChartHeight - $self->getPixelsPerUnit * $_*$self->getYGranularity,
x => $anchorPoint{x},
y => $anchorPoint{y},
));
$anchorPoint{y} -= $self->getPixelsPerUnit * $self->getYGranularity
}
@ -244,6 +242,19 @@ sub formNamespace {
return $self->SUPER::formNamespace.'_XYGraph';
}
#-------------------------------------------------------------------
=head2 getAnchorSpacing ()
This method MUST be overridden by all sub classes.
=cut
sub getAnchorSpacing {
die "You were supposed to override this method in the sub class.";
}
#-------------------------------------------------------------------
=head2 getAxisColor ( )

View file

@ -4,6 +4,7 @@ use strict;
use WebGUI::Image::Graph::XYGraph;
use List::Util;
use POSIX;
use WebGUI::Utility;
our @ISA = qw(WebGUI::Image::Graph::XYGraph);
@ -250,7 +251,7 @@ sub getAnchorSpacing {
my $numberOfGroups = List::Util::max(map {scalar @$_} @{$self->getDataset});
my $spacing = ($self->getChartWidth - ($numberOfGroups-1) * $self->getGroupSpacing) / $numberOfGroups + $self->getGroupSpacing;
my $spacing = round(($self->getChartWidth - ($numberOfGroups-1) * $self->getGroupSpacing) / $numberOfGroups + $self->getGroupSpacing);
return {
x => $spacing,
@ -319,7 +320,7 @@ sub getFirstAnchorLocation {
my $self = shift;
return {
x => $self->getChartOffset->{x} + ($self->getAnchorSpacing->{x} - $self->getGroupSpacing) / 2,
x => round($self->getChartOffset->{x} + ($self->getAnchorSpacing->{x} - $self->getGroupSpacing) / 2),
y => $self->getChartOffset->{y} + $self->getChartHeight
}
}
@ -344,10 +345,14 @@ sub processDataSet {
for my $currentElement (0 .. $maxElements-1) {
my @thisSet = ();
for my $currentDataset (0 .. $numberOfDatasets - 1) {
my $color = $palette->getColor($currentDataset);
if ($numberOfDatasets == 1) {
$color = $palette->getNextColor;
}
push(@thisSet, {
height => $self->{_datasets}->[$currentDataset]->[$currentElement] || 0,
fillColor => $palette->getColor($currentDataset)->getFillColor,
strokeColor => $palette->getColor($currentDataset)->getStrokeColor,
fillColor => $color->getFillColor,
strokeColor => $color->getStrokeColor,
});
}
push(@{$self->{_bars}}, [ @thisSet ]);

View file

@ -55,6 +55,33 @@ sub addMessage {
#-------------------------------------------------------------------
=head2 addPrivateMessage ( properties[, userToSend] )
Adds a new private message to the inbox if the user accepts private messages.
=head3 properties
See WebGUI::Inbox::Message::addMessage() for details.
=cut
sub addPrivateMessage {
my $self = shift;
my $messageData = shift;
my $isReply = shift;
my $userId = $messageData->{userId};
my $sentBy = $messageData->{sentBy} || $self->session->user->userId;
return undef unless $userId;
my $u = WebGUI::User->new($self->session,$userId);
return undef unless ($isReply || $u->acceptsPrivateMessages($sentBy));
return $self->addMessage($messageData);
}
#-------------------------------------------------------------------
=head2 DESTROY ( )
Deconstructor.

View file

@ -72,6 +72,10 @@ A userId of a user attached to this message.
A groupId of a group attached to this message.
=head4 sentBy
A userId that created this message. Defaults to '3' (Admin).
=cut
sub create {

View file

@ -236,8 +236,10 @@ sub parseParts {
my $body = $message->bodyhandle;
if (defined $body) {
my $disposition = $message->head->get("Content-Disposition");
$disposition =~ m/filename=\"(.*)\"/;
my $filename = $1;
my $filename = "";
if($disposition =~ m/filename=\"(.*)\"/) {
$filename = $1;
}
return [{content => $body->as_string, type=>$type, filename=>$filename}];
}
my @parts = ();

View file

@ -165,11 +165,20 @@ sub getOperations {
'viewInboxMessage' => 'WebGUI::Operation::Inbox',
'sendPrivateMessage' => 'WebGUI::Operation::Inbox',
'sendPrivateMessageSave' => 'WebGUI::Operation::Inbox',
'deletePrivateMessage' => 'WebGUI::Operation::Inbox',
'inviteUser' => 'WebGUI::Operation::Invite',
'inviteUserSave' => 'WebGUI::Operation::Invite',
'acceptInvite' => 'WebGUI::Operation::Invite',
'addFriend' => 'WebGUI::Operation::Friends',
'addFriendSave' => 'WebGUI::Operation::Friends',
'friendRequest' => 'WebGUI::Operation::Friends',
'friendRequestSave' => 'WebGUI::Operation::Friends',
'manageFriends' => 'WebGUI::Operation::Friends',
'removeFriends' => 'WebGUI::Operation::Friends',
'sendMessageToFriends' => 'WebGUI::Operation::Friends',
'copyLDAPLink' => 'WebGUI::Operation::LDAPLink',
'deleteLDAPLink' => 'WebGUI::Operation::LDAPLink',
'editLDAPLink' => 'WebGUI::Operation::LDAPLink',

View file

@ -0,0 +1,376 @@
package WebGUI::Operation::Friends;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
use strict;
use WebGUI::Form;
use WebGUI::Friends;
use WebGUI::User;
use WebGUI::International;
use WebGUI::Operation::Shared;
=head1 NAME
Package WebGUI::Operation::Friends
=head1 DESCRIPTION
Operation handler for handling the friends network.
=cut
#-------------------------------------------------------------------
=head2 www_addFriend ( )
Form for inviting a user to become your friend.
=cut
sub www_addFriend {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $friendId = $session->form->get('userId');
my $protoFriend = WebGUI::User->new($session, $friendId);
my $i18n = WebGUI::International->new($session, 'Friends');
# Check for non-existant user id.
if ((!$protoFriend->username) || (!$protoFriend->profileField('ableToBeFriend'))) {
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('add to friends'),
$i18n->get('does not want to be a friend'),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $session->style->userStyle($output);
}
my $output = join '',
sprintf("<h1>%s</h1>\n", $i18n->get('add to friends')),
'<p>',
sprintf($i18n->get('add to friends description'),
$protoFriend->getWholeName),
'</p>',
WebGUI::Form::formHeader($session),
WebGUI::Form::hidden($session,
{
name => 'op',
value => 'addFriendSave',
}
),
WebGUI::Form::hidden($session,
{
name => 'friendId',
value => $friendId,
}
),
WebGUI::Form::textarea($session,
{
name => 'comments',
value => sprintf($i18n->get('default friend comments'), $protoFriend->getFirstName, $session->user->getFirstName),
}
),
WebGUI::Form::Submit($session,
{
value => $i18n->get('add')
}
),
WebGUI::Form::Button($session,
{
value => $i18n->get('cancel', 'WebGUI'),
extras => q|onclick="history.go(-1);" class="backwardButton"|,
}
),
WebGUI::Form::formFooter($session),
;
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 www_addFriendSave ( )
Post process the form, check for required fields, handle inviting users who are already
members (determined by email address) and send the email.
=cut
sub www_addFriendSave {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $friendId = $session->form->get('friendId');
my $protoFriend = WebGUI::User->new($session, $friendId);
my $i18n = WebGUI::International->new($session, 'Friends');
# Check for non-existant user id.
if ((!$protoFriend->username) || (!$protoFriend->profileField('ableToBeFriend'))) {
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('add to friends'),
$i18n->get('does not want to be a friend'),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $session->style->userStyle($output);
}
my $friends = WebGUI::Friends->new($session);
$friends->sendAddRequest($friendId, $session->form->get('comments'));
# display result
my $output = sprintf(
q!<h1>%s</h1><p>%s</p><p><a href="%s">%s</a></p><p><a href="%s">%s</a></p>!,
$i18n->get('add to friends'),
sprintf($i18n->get('add to friends confirmation'), $protoFriend->getWholeName),
$session->url->append($session->url->getRequestedUrl, 'op=viewProfile;uid='.$friendId),
sprintf($i18n->get('add to friends profile'), $protoFriend->getFirstName),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI'),
);
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 www_friendRequest ( )
Form for the friend to accept or deny the request.
=cut
sub www_friendRequest {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $i18n = WebGUI::International->new($session, 'Friends');
my $inviteId = $session->form->get('inviteId');
my $friends = WebGUI::Friends->new($session);
my $invitation = $friends->getAddRequest($inviteId);
##Invalid invite ID
unless (exists $invitation->{friendId}) { ##No userId corresponds to the inviteId
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('invalid invite code'),
$i18n->get('invalid invite code message'),
$session->url->page("op=viewInbox"),
$i18n->get('354', 'WebGUI');
return $session->style->userStyle($output);
}
##Already a friend (check friendId already in the group)
if ($friends->isFriend($invitation->{inviterId})) {
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('invalid invite code'),
$i18n->get('already a friend'),
$session->url->page("op=viewInbox"),
$i18n->get('354', 'WebGUI');
return $session->style->userStyle($output);
}
##Someone else's invite (check friendId vs current userId).
if ($session->user->userId ne $invitation->{friendId}) { ##This isn't your invitation, dude.
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('invalid invite code'),
$i18n->get('not the right user'),
$session->url->page("op=viewInbox"),
$i18n->get('354', 'WebGUI');
return $session->style->userStyle($output);
}
##Everything looks good. Make the form!
my $inviter = WebGUI::User->new($session, $invitation->{inviterId});
my $output = join '',
sprintf("<h1>%s</h1>\n", $i18n->get('friend request')),
'<p>',
sprintf($i18n->get('friend request description'),
$inviter->getWholeName),
'</p>',
WebGUI::Form::formHeader($session),
WebGUI::Form::hidden($session,
{
name => 'op',
value => 'friendRequestSave',
}
),
WebGUI::Form::hidden($session,
{
name => 'inviteId',
value => $inviteId,
}
),
WebGUI::Form::textarea($session,
{
name => 'comments',
value => $invitation->{comments},
extras => 'disabled=disabled',
}
),
WebGUI::Form::Submit($session, ##Approve
{
name => 'doWhat',
value => $i18n->get('572', 'WebGUI'),
}
),
WebGUI::Form::Submit($session, ##Deny
{
name => 'doWhat',
value => $i18n->get('574', 'WebGUI'),
}
),
WebGUI::Form::formFooter($session),
;
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 www_friendRequestSave ( )
Handle form data from the friend's response to the invitation
=cut
sub www_friendRequestSave {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $i18n = WebGUI::International->new($session, 'Friends');
my $doWhat = $session->form->get('doWhat');
my $inviteId = $session->form->get('inviteId');
my $friends = WebGUI::Friends->new($session);
my $invite = $friends->getAddRequest($inviteId);
my $inviter = WebGUI::User->new($session, $invite->{inviterId});
##Invalid invite ID
if (!$invite->{inviterId}) { ##No userId corresponds to the inviteId
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('invalid invite code'),
$i18n->get('invalid invite code message'),
$session->url->page("op=viewInbox"),
$i18n->get('354', 'WebGUI');
return $session->style->userStyle($output);
}
##If deny, change the status of the request to denied.
if ($doWhat ne $i18n->get('572', 'WebGUI')) { ##request denied
$friends->rejectAddRequest($inviteId);
##Return screen that says they denied the request.
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('friend request'),
sprintf($i18n->get('you have not been added'), $inviter->getWholeName),
$session->url->page("op=viewInbox"),
$i18n->get('354', 'WebGUI');
return $session->style->userStyle($output);
}
##If accepted,
# set the status to accepted.
$friends->approveAddRequest($inviteId);
# Return screen that says they accepted the request.
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('friend request'),
sprintf($i18n->get('you have been added'), $inviter->getWholeName),
$session->url->page("op=viewInbox"),
$i18n->get('354', 'WebGUI');
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 www_manageFriends ( )
Display the list of friends and allow the user to remove friends or
send private messages to a subset of them.
=cut
sub www_manageFriends {
my $session = shift;
my ($user, $url, $style) = $session->quick(qw(user url style));
return $session->privilege->insufficient() unless ($user->isInGroup(2));
my $i18n = WebGUI::International->new($session, 'Friends');
##You have no friends!
my $friends = $user->friends->getUsers;
unless (scalar(@{$friends})) {
my $output = sprintf qq!<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>!,
$i18n->get('my friends'),
$i18n->get('no friends'),
$url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $style->userStyle($output);
}
# show the friend manager
my %var = (
"account.options" => WebGUI::Operation::Shared::accountOptions($session),
formHeader => WebGUI::Form::formHeader($session)
. WebGUI::Form::hidden($session, { name => 'op', value => 'sendMessageToFriends', }),
removeFriendButton => WebGUI::Form::button($session, { value => $i18n->get('remove'), extras => q|onclick="confirmRemovalOfFriends(form);"|, }),
subjectForm => WebGUI::Form::text($session, { name=>"subject" }),
sendMessageButton => WebGUI::Form::Submit($session, { value => $i18n->get('send message'), }),
messageForm => WebGUI::Form::textarea($session, { name=>"message" }),
formFooter => WebGUI::Form::formFooter($session),
);
foreach my $userId (@{ $friends}) {
my $friend = WebGUI::User->new($session, $userId);
push(@{$var{friends}}, {
name => $friend->getWholeName,
profileUrl => $url->append($url->getRequestedUrl, 'op=viewProfile;uid='.$userId),
status => ($friend->isOnline ? $i18n->get('online') : $i18n->get('offline')),
checkboxForm => WebGUI::Form::checkbox($session, { name => 'userId', value => $userId, }),
});
}
my $template = WebGUI::Asset->new(
$session,
$session->setting->get("manageFriendsTemplateId"),
"WebGUI::Asset::Template",
);
return $style->userStyle($template->process(\%var));
}
#-------------------------------------------------------------------
=head2 www_removeFriends ()
Removes friends from the current user's friends list.
=cut
sub www_removeFriends {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my @users = $session->form->param("userId");
WebGUI::Friends->new($session)->delete(\@users);
return www_manageFriends($session);
}
#-------------------------------------------------------------------
=head2 www_sendMessageToFriends ()
Sends a message to selected friends.
=cut
sub www_sendMessageToFriends {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my @users = $session->form->param("userId");
my $friends = WebGUI::Friends->new($session);
$friends->sendMessage($session->form->process("subject", "text"), $session->form->process("message","textarea"), \@users);
return www_manageFriends($session);
}
1;

View file

@ -153,7 +153,7 @@ sub www_sendPrivateMessage {
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
unless($userTo->profileField("allowPrivateMessages")) {
unless($userTo->acceptsPrivateMessages($user->userId)) {
$vars->{'error_msg'} = $i18n->get('private message blocked error');
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
@ -213,7 +213,15 @@ sub www_sendPrivateMessageSave {
}
}
unless($isReply || $userTo->profileField("allowPrivateMessages")) {
my $message = WebGUI::Inbox->new($session)->addPrivateMessage({
message => $form->get("message"),
subject => $form->get("subject"),
userId => $uid,
status => 'unread',
sentBy => $user->userId
},$isReply);
unless(defined $message) {
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
$i18n->get('private message error'),
$i18n->get('private message blocked error'),
@ -222,15 +230,6 @@ sub www_sendPrivateMessageSave {
return $style->userStyle($output);
}
WebGUI::Inbox->new($session)->addMessage({
message => $form->get("message"),
subject => $form->get("subject"),
userId => $uid,
status => 'unread',
sentBy => $user->userId
});
my $output = sprintf qq!<p>%s</p><a href="%s">%s</a>!,
$i18n->get('private message sent'),
@ -270,7 +269,7 @@ sub www_viewInbox {
#Cache the base url
my $inboxUrl = $session->url->page('op=viewInbox');
$vars->{ title } = $i18n->get(159);
$vars->{'subject_label' } = $i18n->get(351);
$vars->{'subject_url' } = $inboxUrl.$pn_url.";sortBy=subject";
@ -287,6 +286,8 @@ sub www_viewInbox {
my $adminUser = WebGUI::User->new($session,3)->username;
my $messages = WebGUI::Inbox->new($session)->getMessagesForUser($session->user,$rpp,$pn,$sortBy);
foreach my $message (@$messages) {
next if($message->get('status') eq 'deleted');
my $hash = {};
$hash->{ message_url } = $session->url->page('op=viewInboxMessage;messageId='.$message->getId);
$hash->{ subject } = $message->get("subject");
@ -332,6 +333,27 @@ sub www_viewInbox {
#-------------------------------------------------------------------
=head2 www_deletePrivateMessage ( )
Mark a private message in the inbox as deleted.
=cut
sub www_deletePrivateMessage {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
#Get the message
my $message = WebGUI::Inbox->new($session)->getMessage($session->form->param("messageId"));
if(defined $message) {
# set the message status to 'deleted'
$message->setStatus("deleted");
}
return www_viewInbox($session);
}
#-------------------------------------------------------------------
=head2 www_viewInboxMessage ( )
Templated display of a single message for the user.
@ -367,6 +389,8 @@ sub www_viewInboxMessage {
$vars->{'dateStamp'} =$session->datetime->epochToHuman($message->get("dateStamp"));
$vars->{'status' } = _status($session)->{$message->get("status")};
$vars->{ message } = $message->get("message");
$vars->{ delete_text } = $i18n->get("private message delete text");
$vars->{ delete_url } = '?op=deletePrivateMessage;messageId=' . $message->getId;
unless ($vars->{message} =~ /\<a/ig) {
$vars->{message} =~ s/(http\S*)/\<a href=\"$1\"\>$1\<\/a\>/g;
}

View file

@ -23,6 +23,7 @@ use WebGUI::Utility;
use WebGUI::ProfileField;
use WebGUI::ProfileCategory;
use WebGUI::Operation::Shared;
use WebGUI::Operation::Friends;
=head1 NAME
@ -280,39 +281,45 @@ A reference to the current session.
=cut
sub www_viewProfile {
my $session = shift;
my $u = WebGUI::User->new($session,$session->form->process("uid"));
my $i18n = WebGUI::International->new($session);
my $vars = {};
$vars->{displayTitle} = $i18n->get(347).' '.$u->username;
my $session = shift;
my $u = WebGUI::User->new($session,$session->form->process("uid"));
my $i18n = WebGUI::International->new($session);
my $vars = {};
$vars->{displayTitle} = $i18n->get(347).' '.$u->username;
return $session->privilege->notMember() if($u->username eq "");
return $session->privilege->notMember() if($u->username eq "");
return $session->style->userStyle($vars->{displayTitle}.'. '.$i18n->get(862)) if($u->profileField("publicProfile") < 1 && ($session->user->userId ne $session->form->process("uid") || $session->user->isInGroup(3)));
return $session->privilege->insufficient() if(!$session->user->isInGroup(2));
return $session->style->userStyle($vars->{displayTitle}.'. '.$i18n->get(862)) if($u->profileField("publicProfile") < 1 && ($session->user->userId ne $session->form->process("uid") || $session->user->isInGroup(3)));
return $session->privilege->insufficient() if(!$session->user->isInGroup(2));
my @array = ();
foreach my $category (@{WebGUI::ProfileCategory->getCategories($session)}) {
next unless ($category->get("visible"));
push(@array, {'profile.category' => $category->getLabel});
foreach my $field (@{$category->getFields}) {
next unless ($field->get("visible"));
next if ($field->get("fieldName") eq "email" && !$u->profileField("publicEmail"));
push(@array, {
'profile.label' => $field->getLabel,
'profile.value' => $field->formField(undef,2,$u)
});
}
}
$vars->{'profile.elements'} = \@array;
if ($session->user->userId eq $session->form->process("uid")) {
$vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
}
my @array = ();
foreach my $category (@{WebGUI::ProfileCategory->getCategories($session)}) {
next unless ($category->get("visible"));
push(@array, {'profile.category' => $category->getLabel});
foreach my $field (@{$category->getFields}) {
next unless ($field->get("visible"));
next if ($field->get("fieldName") eq "email" && !$u->profileField("publicEmail"));
push @array, {
'profile.label' => $field->getLabel,
'profile.value' => $field->formField(undef,2,$u),
};
}
}
$vars->{'profile.elements'} = \@array;
if ($session->user->userId eq $session->form->process("uid")) {
$vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
}
else {
push(@{$vars->{'profile.accountOptions'}}, {'options.display' => '<a href="'.$session->url->page('op=sendPrivateMessage;uid='.$session->form->process("uid")).'">'.$i18n->get('send private message').'</a>'});
## TODO: Make this more legible code, maybe refactor into a method
push @{$vars->{'profile.accountOptions'}}, {
'options.display' => '<a href="'.$session->url->page("op=addFriend;userId=".$u->userId).'">'.$i18n->get('add to friends list', 'Friends').'</a>',
}, {
'options.display' => '<a href="'.$session->url->page('op=sendPrivateMessage;uid='.$session->form->process("uid")).'">'.$i18n->get('send private message').'</a>',
};
}
return $session->style->userStyle(WebGUI::Asset::Template->new($session,"PBtmpl0000000000000052")->process($vars));
return $session->style->userStyle(WebGUI::Asset::Template->new($session,"PBtmpl0000000000000052")->process($vars));
}

View file

@ -441,6 +441,15 @@ sub definition {
namespace=>"userInvite/Email",
defaultValue=>$setting->get("userInvitationsEmailTemplateId"),
});
push(@fields, {
tab => "user",
fieldType => "template",
defaultValue => "managefriends_________",
namespace => "friends/manage",
name => "manageFriendsTemplateId",
label => $i18n->get("manage friends template", "Friends"),
hoverHelp => $i18n->get("manage friends template help", "Friends"),
});
# auth settings
my $options;
foreach (@{$session->config->get("authMethods")}) {

View file

@ -73,6 +73,11 @@ TODO: DOCUMENT ME
push @array, {
'options.display' => sprintf('<a href=%s>%s</a>', $session->url->page('op=inviteUser'), $i18n->get('invite a friend')),
};
}
unless ($op eq "manageFriends") {
push @array, {
'options.display' => sprintf('<a href=%s>%s</a>', $session->url->page('op=manageFriends'), $i18n->get('see my friends', 'Friends')),
};
}
my %logout;
$logout{'options.display'} = '<a href="'.$session->url->page('op=auth;method=logout').'">'.$i18n->get(64).'</a>';

View file

@ -578,66 +578,87 @@ ENDCODE
name=>rand(100000),
timeout=>10
);
if (! $remote) {
my $output = $i18n->get('spectre not running error');
return $ac->render($output, $i18n->get('show running workflows'));
}
my $sitename = $session->config()->get('sitename')->[0];
my $workflowResult = $remote->post_respond('workflow/getJsonStatus',$sitename);
if (! defined $workflowResult) {
$remote->disconnect();
my $output = $i18n->get('spectre no info error');
return $ac->render($output, $i18n->get('show running workflows'));
my $workflowResult;
if ($remote) {
$workflowResult = $remote->post_respond('workflow/getJsonStatus',$sitename);
if (!defined $workflowResult) {
$remote->disconnect();
$output = $i18n->get('spectre no info error');
}
}
else {
$output = $i18n->get('spectre not running error')
}
my $workflowsHref = jsonToObj($workflowResult);
if (defined $workflowResult) {
my $workflowsHref = jsonToObj($workflowResult);
my $workflowTitleFor = $session->db->buildHashRef(<<"");
SELECT wi.instanceId, w.title
FROM WorkflowInstance wi
JOIN Workflow w USING (workflowId)
my $workflowTitleFor = $session->db->buildHashRef(<<"");
SELECT wi.instanceId, w.title
FROM WorkflowInstance wi
JOIN Workflow w USING (workflowId)
my $lastActivityFor = $session->db->buildHashRef(<<"");
SELECT wi.instanceId, wa.title
FROM WorkflowInstance wi
JOIN WorkflowActivity wa ON wi.currentActivityId = wa.activityId
my $lastActivityFor = $session->db->buildHashRef(<<"");
SELECT wi.instanceId, wa.title
FROM WorkflowInstance wi
JOIN WorkflowActivity wa ON wi.currentActivityId = wa.activityId
for my $workflowType (qw( Suspended Waiting Running )) {
my $workflowsAref = $workflowsHref->{$workflowType};
my $workflowCount = @$workflowsAref;
for my $workflowType (qw( Suspended Waiting Running )) {
my $workflowsAref = $workflowsHref->{$workflowType};
my $workflowCount = @$workflowsAref;
my $titleHeader = $i18n->get('title header');
my $priorityHeader = $i18n->get('priority header');
my $activityHeader = $i18n->get('activity header');
my $lastStateHeader = $i18n->get('last state header');
my $lastRunTimeHeader = $i18n->get('last run time header');
$output .= sprintf $i18n->get('workflow type count'), $workflowCount, $workflowType;
$output .= '<table style="width: 100%;">';
$output .= "<tr><th>$titleHeader</th><th>$priorityHeader</th><th>$activityHeader</th>";
$output .= "<th>$lastStateHeader</th><th>$lastRunTimeHeader</th></tr>";
my $titleHeader = $i18n->get('title header');
my $priorityHeader = $i18n->get('priority header');
my $activityHeader = $i18n->get('activity header');
my $lastStateHeader = $i18n->get('last state header');
my $lastRunTimeHeader = $i18n->get('last run time header');
$output .= sprintf $i18n->get('workflow type count'), $workflowCount, $workflowType;
$output .= '<table style="width: 100%;">';
$output .= "<tr><th>$titleHeader</th><th>$priorityHeader</th><th>$activityHeader</th>";
$output .= "<th>$lastStateHeader</th><th>$lastRunTimeHeader</th></tr>";
for my $workflow (@$workflowsAref) {
my($priority, $id, $instance) = @$workflow;
for my $workflow (@$workflowsAref) {
my($priority, $id, $instance) = @$workflow;
my $originalPriority = ($instance->{priority} - 1) * 10;
my $instanceId = $instance->{instanceId};
my $title = $workflowTitleFor->{$instanceId} || '(no title)';
my $lastActivity = $lastActivityFor->{$instanceId} || '(none)';
my $lastRunTime = $instance->{lastRunTime} || '(never)';
my $originalPriority = ($instance->{priority} - 1) * 10;
my $instanceId = $instance->{instanceId};
my $title = $workflowTitleFor->{$instanceId} || '(no title)';
my $lastActivity = $lastActivityFor->{$instanceId} || '(none)';
my $lastRunTime = $instance->{lastRunTime} || '(never)';
$output .= '<tr>';
$output .= "<td>$title</td>";
$output .= qq[<td><a id="priority-$instanceId" href="javascript:void(0);" title="Edit Priority" onclick="showEditPriorityForm('$instanceId')">$priority</a>/$originalPriority</td>];
$output .= "<td>$lastActivity</td>";
$output .= "<td>$instance->{lastState}</td>";
$output .= "<td>$lastRunTime</td>";
$output .= '<tr>';
$output .= "<td>$title</td>";
$output .= qq[<td><a id="priority-$instanceId" href="javascript:void(0);" title="Edit Priority" onclick="showEditPriorityForm('$instanceId')">$priority</a>/$originalPriority</td>];
$output .= "<td>$lastActivity</td>";
$output .= "<td>$instance->{lastState}</td>";
$output .= "<td>$lastRunTime</td>";
if ($isAdmin) {
my $run = $i18n->get('run');
my $href = $session->url->page(qq[op=runWorkflow;instanceId=$instanceId]);
$output .= qq[<td><a href="$href">$run</a></td>];
if ($isAdmin) {
my $run = $i18n->get('run');
my $href = $session->url->page(qq[op=runWorkflow;instanceId=$instanceId]);
$output .= qq[<td><a href="$href">$run</a></td>];
}
$output .= "</tr>\n";
}
$output .= '</table>';
}
}
else {
$output .= '<table width="100%">';
my $rs = $session->db->read("select Workflow.title, WorkflowInstance.lastStatus, WorkflowInstance.runningSince, WorkflowInstance.lastUpdate, WorkflowInstance.instanceId from WorkflowInstance left join Workflow on WorkflowInstance.workflowId=Workflow.workflowId order by WorkflowInstance.runningSince desc");
while (my ($title, $status, $runningSince, $lastUpdate, $id) = $rs->array) {
my $class = $status || "complete";
$output .= '<tr class="'.$class.'">'
.'<td>'.$title.'</td>'
.'<td>'.$session->datetime->epochToHuman($runningSince).'</td>';
if ($status) {
$output .= '<td>'
.$status.' / '.$session->datetime->epochToHuman($lastUpdate)
.'</td>';
}
$output .= '<td><a href="'.$session->url->page("op=runWorkflow;instanceId=".$id).'">'.$i18n->get("run").'</a></td>'
if ($isAdmin);
$output .= "</tr>\n";
}
$output .= '</table>';

View file

@ -680,12 +680,12 @@ sub setDataByQuery {
my $pageNumber = $self->getPageNumber;
my $rowsPerPage = $self->{_rpp};
#Handle dynamicPageNumber requests or custom limts the old way as it winds up being most efficient
if ((defined $dynamicPageNumberKey && $pageNumber == 1) || $sql =~ m/limit/i) {
$dbh ||= $self->session->dbSlave;
#Handle dynamicPageNumber requests or custom limits, or non-mysql the old way as it winds up being most efficient
if ($dbh->getDriver ne 'mysql' || (defined $dynamicPageNumberKey && $pageNumber == 1) || $sql =~ m/limit/i) {
return $self->_setDataByQuery(@_);
}
$dbh ||= $self->session->dbSlave;
#Calculate where to start
my $start = ( ($pageNumber - 1) * $rowsPerPage );

View file

@ -459,6 +459,19 @@ sub getNextId {
#-------------------------------------------------------------------
=head2 getDriver ( )
Returns the DBI driver used by this database link
=cut
sub getDriver {
my $self = shift;
return $self->{_dbh}->{Driver}->{Name};
}
#-------------------------------------------------------------------
=head2 getRow ( table, key, keyValue )
Returns a row of data as a hash reference from the specified table.

View file

@ -226,8 +226,17 @@ Returns an HTML string with all the necessary components to draw the tab form.
sub print {
my $self = shift;
$self->session->style->setScript($self->session->url->extras('tabs/tabs.js'),{type=>"text/javascript"});
$self->session->style->setLink($self->{_css},{rel=>"stylesheet", rev=>"stylesheet",type=>"text/css"});
my $style = $self->session->style;
my $url = $self->session->url;
$style->setScript($url->extras('tabs/tabs.js'),{type=>"text/javascript"});
$style->setLink($self->{_css},{rel=>"stylesheet", rev=>"stylesheet",type=>"text/css"});
$style->setLink($url->extras('/yui/build/container/assets/container.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setLink($url->extras('/hoverhelp.css'),{ type=>'text/css', rel=>"stylesheet" });
$style->setScript($url->extras('/yui/build/yahoo/yahoo-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/dom/dom-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/event/event-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/yui/build/container/container-min.js'),{ type=>'text/javascript' });
$style->setScript($url->extras('/hoverhelp.js'),{ type=>'text/javascript' });
my $output = $self->{_form};
$output .= $self->{_hidden};
my $i = 1;

View file

@ -97,6 +97,37 @@ sub addToGroups {
$self->session->stow->delete("gotGroupsForUser");
}
#-------------------------------------------------------------------
=head2 acceptsPrivateMessages ( userId )
Returns a boolean of whether or not the user can receive private messages from the user passed in
=head3 userId
userId to determine if the user accepts private messages from
=cut
sub acceptsPrivateMessages {
my $self = shift;
my $userId = shift;
my $pmSetting = $self->profileField('allowPrivateMessages');
return 0 if ($pmSetting eq "none");
return 1 if ($pmSetting eq "all");
if($pmSetting eq "friends") {
my $friendsGroup = $self->friends;
my $sentBy = WebGUI::User->new($self->session,$userId);
#$self->session->errorHandler->warn($self->isInGroup($friendsGroup->getId));
return $sentBy->isInGroup($friendsGroup->getId);
}
return 1;
}
#-------------------------------------------------------------------
=head2 authMethod ( [ value ] )
@ -163,22 +194,24 @@ Deletes this user.
=cut
sub delete {
my $self = shift;
my $self = shift;
$self->uncache;
my $db = $self->session->db;
foreach my $groupId (@{$self->getGroups($self->userId)}) {
WebGUI::Group->new($self->session,$groupId)->deleteUsers([$self->userId]);
}
$self->session->db->write("delete from inbox where userId=? and (groupId is null or groupId='')",[$self->{_userId}]);
$self->friends->delete if ($self->{_user}{"friendsGroup"} ne "");
$db->write("delete from inbox where userId=? and (groupId is null or groupId='')",[$self->{_userId}]);
require WebGUI::Operation::Auth;
my $authMethod = WebGUI::Operation::Auth::getInstance($self->session,$self->authMethod,$self->{_userId});
$authMethod->deleteParams($self->{_userId});
my $rs = $self->session->db->read("select sessionId from userSession where userId=?",[$self->{_userId}]);
my $rs = $db->read("select sessionId from userSession where userId=?",[$self->{_userId}]);
while (my ($id) = $rs->array) {
$self->session->db->write("delete from userSessionScratch where sessionId=?",[$id]);
$db->write("delete from userSessionScratch where sessionId=?",[$id]);
}
$self->session->db->write("delete from userSession where userId=?",[$self->{_userId}]);
$self->session->db->write("delete from userProfileData where userId=?",[$self->{_userId}]);
$self->session->db->write("delete from users where userId=?",[$self->{_userId}]);
$db->write("delete from userSession where userId=?",[$self->{_userId}]);
$db->write("delete from userProfileData where userId=?",[$self->{_userId}]);
$db->write("delete from users where userId=?",[$self->{_userId}]);
}
#-------------------------------------------------------------------
@ -213,10 +246,57 @@ Deconstructor.
sub DESTROY {
my $self = shift;
if (exists $self->{_friendsGroup}) {
$self->{_friendsGroup}->DESTROY;
}
undef $self;
}
#-------------------------------------------------------------------
=head2 friends ( )
Returns the WebGUI::Group for this user's Friend's Group.
=cut
sub friends {
my $self = shift;
if ($self->{_user}{"friendsGroup"} eq "") {
my $myFriends = WebGUI::Group->new($self->session, "new");
$myFriends->name($self->username." Friends");
$myFriends->description("Friends of user ".$self->userId);
$myFriends->expireOffset(60*60*24*365*60);
$myFriends->showInForms(0);
$myFriends->isEditable(0);
$myFriends->deleteUsers(['3']);
$self->uncache;
$self->{_user}{"friendsGroup"} = $myFriends->getId;
$self->{_user}{"lastUpdated"} = $self->session->datetime->time();
$self->session->db->write("update users set friendsGroup=?, lastUpdated=? where userId=?",
[$myFriends->getId, $self->session->datetime->time(), $self->userId]);
return $myFriends;
}
elsif (exists $self->{_friendsGroup}) {
return $self->{_friendsGroup};
}
return WebGUI::Group->new($self->session, $self->{_user}{"friendsGroup"});
}
#-------------------------------------------------------------------
=head2 getFirstName ( )
Returns first name, or alias, or username depeneding upon what exists.
=cut
sub getFirstName {
my $self = shift;
return $self->profileField('firstName') || $self->profileField('alias') || $self->username;
}
#-------------------------------------------------------------------
=head2 getGroups ( [ withoutExpired ] )
@ -252,6 +332,23 @@ sub getGroups {
}
}
#-------------------------------------------------------------------
=head2 getWholeName ( )
Attempts to build the user's whole name from profile fields, and ultimately their alias and username if all else
fails.
=cut
sub getWholeName {
my $self = shift;
if ($self->profileField('firstName') and $self->profileField('lastName')) {
return join ' ', $self->profileField('firstName'), $self->profileField('lastName');
}
return $self->profileField("alias") || $self->username;
}
#-------------------------------------------------------------------
# This method is depricated and is provided only for reverse compatibility. See WebGUI::Auth instead.
sub identifier {
@ -314,6 +411,22 @@ sub isInGroup {
}
#-------------------------------------------------------------------
=head2 isOnline ()
Returns a boolean indicating whether this user is logged in and actively viewing pages in the site.
=cut
sub isOnline {
my $self = shift;
my ($flag) = $self->session->db->quickArray('select count(*) from userSession where userId=? and lastPageView=?',
[$self->userId, time() - 60*10]);
return $flag;
}
#-------------------------------------------------------------------
=head2 karma ( [ amount, source, description ] )

View file

@ -40,6 +40,7 @@ This package provides miscellaneous but useful utilities to the WebGUI programme
use WebGUI::Utility;
$string = commify($integer);
$size = formatBytes($integer);
$boolean = isBetween($value, $first, $second);
$boolean = isIn($value, @array);
$boolean = isInSubnet($ip, \@subnets);
makeArrayCommaSafe(\@array);
@ -48,6 +49,7 @@ This package provides miscellaneous but useful utilities to the WebGUI programme
$string = makeTabSafe($string);
$integer = randint($low,$high);
$hashRef = randomizeHash(\%hash);
$rounded = round($number, $digits);
%hash = sortHash(%hash);
%hash = sortHashDescending(%hash);

View file

@ -297,15 +297,21 @@ sub new {
my $main = $session->db->getRow("WorkflowActivity","activityId", $activityId);
return undef unless $main->{activityId};
$class = $main->{className};
my $cmd = "use ".$class;
eval ($cmd);
if ($@) {
$session->errorHandler->error("Couldn't compile workflow activity package: ".$class.". Root cause: ".$@);
return undef;
}
(my $module = "$class.pm") =~ s{'|::}{/}g;
unless (eval { require $module; 1 }) {
$session->errorHandler->error("Couldn't compile workflow activity package: ".$class.". Root cause: ".$@);
return undef;
}
my $sub = $session->db->buildHashRef("select name,value from WorkflowActivityData where activityId=?",[$activityId]);
my %data = (%{$main}, %{$sub});
bless {_session=>$session, _id=>$activityId, _data=>\%data}, $class;
for my $definition (reverse @{$class->definition($session)}) {
for my $property (keys %{$definition->{properties}}) {
if(!defined $data{$property} || $data{$property} eq '' && $definition->{properties}{$property}{defaultValue}) {
$data{$property} = $definition->{properties}{$property}{defaultValue};
}
}
}
bless {_session=>$session, _id=>$activityId, _data=>\%data}, $class;
}
#-------------------------------------------------------------------

View file

@ -77,14 +77,14 @@ sub execute {
my $archiveDate = $epoch - $cs->get("archiveAfter");
my $sql = "select asset.assetId, assetData.revisionDate from Post left join asset on asset.assetId=Post.assetId
left join assetData on Post.assetId=assetData.assetId and Post.revisionDate=assetData.revisionDate
where Post.dateUpdated<? and assetData.status='approved' and asset.state='published'
where Post.revisionDate<? and assetData.status='approved' and asset.state='published'
and Post.threadId=Post.assetId and asset.lineage like ?";
my $b = $self->session->db->read($sql,[$archiveDate, $cs->get("lineage").'%']);
while (my ($id, $version) = $b->array) {
my $thread = WebGUI::Asset->new($self->session, $id, "WebGUI::Asset::Post::Thread", $version);
my $archiveIt = 1;
foreach my $post (@{$thread->getPosts}) {
$archiveIt = 0 if (defined $post && $post->get("dateUpdated") > $archiveDate);
$archiveIt = 0 if (defined $post && $post->get("revisionDate") > $archiveDate);
}
$thread->archive if ($archiveIt);
}

View file

@ -0,0 +1,103 @@
package WebGUI::Workflow::Activity::DenyUnansweredFriends;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 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 base 'WebGUI::Workflow::Activity';
use WebGUI::DateTime;
use DateTime::Duration;
use WebGUI::Friends;
=head1 NAME
Package WebGUI::Workflow::Activity::DenyUnansweredFriends
=head1 DESCRIPTION
This activity denies unanswered "Add a friend" requests after a set period of time.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Friends");
push(@{$definition}, {
name => $i18n->get("deny unanswered friends"),
properties => {
timeout => {
fieldType => "interval",
label => $i18n->get("timeout"),
defaultValue => 0,
hoverHelp => $i18n->get("timeout help"),
},
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( [ object ] )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $start = time();
my $session = $self->session;
my $now = WebGUI::DateTime->new($session, $start);
my $outdated = DateTime::Duration->new(seconds => $self->get("timeout"));
my $pending = WebGUI::Friends->getAllPendingAddRequests($session);
while (my $invite = $pending->hashRef) {
my $sentOn = WebGUI::DateTime->new($session, $invite->{dateSent});
if (DateTime::Duration->compare($now - $sentOn, $outdated) == 1) {
WebGUI::Friends->new($session, WebGUI::User->new($session, $invite->{friendId}))->rejectAddRequest($invite->{inviteId});
}
if (time() - $start > 55) {
$pending->finish;
return $self->WAITING;
}
}
return $self->COMPLETE;
}
1;

View file

@ -115,8 +115,8 @@ sub addPost {
content=>$content,
ownerUserId=>$user->userId,
username=>$user->profileField("alias") || $user->username,
originalEmail=>join("",@{$message->{rawMessage}})
});
originalEmail=>join("",@{$message->{rawMessage}}),
});
if (scalar(@attachments)) {
my $storage = $post->getStorageLocation;
foreach my $file (@attachments) {
@ -176,14 +176,14 @@ sub execute {
return $self->COMPLETE unless (defined $mail);
my $i18n = WebGUI::International->new($self->session, "Asset_Collaboration");
my $postGroup = $cs->get("postGroupId"); #group that's allowed to post to the CS
while (my $message = $mail->getNextMessage) {
next unless (scalar(@{$message->{parts}})); # no content, skip it
my $from = $message->{from};
$from =~ /<(\S+\@\S+)>/;
$from = $1 || $from;
$from =~ /(\S+\@\S+)/;
my $user = WebGUI::User->newByEmail($self->session, $from); #instantiate the user by email
if ($from =~ /<(\S+\@\S+)>/) {
$from = $1;
}
my $user = WebGUI::User->newByEmail($self->session, $from); #instantiate the user by email
unless (defined $user) { #if no user
unless ($postGroup eq 1 || $postGroup eq 7) { #reject mail if no registered email, unless post group is Visitors (1) or Everyone (7)
@ -209,9 +209,8 @@ sub execute {
}
my $post = undef;
if ($message->{inReplyTo}) {
$message->{inReplyTo} =~ m/cs\-([\w_-]{22})\@/;
my $id = $1;
if ($message->{inReplyTo} && $message->{inReplyTo} =~ m/cs\-([\w_-]{22})\@/) {
my $id = $1;
$post = WebGUI::Asset->newByDynamicClass($self->session, $id);
}

View file

@ -127,7 +127,7 @@ sub execute {
if($ldap) {
my $uri = $ldapLink->getURI();
my $search = $ldap->search(
base =>$ldapLink->getValue("ldapUserRDN"),
base => $uri->dn,
scope =>"sub",
filter =>$ldapLink->getValue("ldapIdentity").'='.$userObject->username
);

View file

@ -75,8 +75,15 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
# do some work here, whatever this activity is supposed to do
return $self->COMPLETE;
my $object = shift;
my $instance = shift;
# do some work here, whatever this activity is supposed to do
# Workflow is finished
return $self->COMPLETE;
# Or needs to be run again to finish processing
#return $self->WAITING;
# Or encountered an error and cannot finish
#return $self->ERROR;
}

View file

@ -0,0 +1,217 @@
package WebGUI::i18n::English::Friends;
our $I18N = {
'invitation accepted by user' => {
message => q{Your invitation has been accepted by %s.},
lastUpdated => 0,
},
'friends invitation accepted' => {
message => q{Friends Invitation Accepted},
lastUpdated => 0,
},
'friends invitation not accepted by user' => {
message => q{Your invitation has not been accepted by %s.},
lastUpdated => 0,
},
'friends invitation not accepted' => {
message => q{Friends Invitation Not Accepted},
lastUpdated => 0,
},
'invitation approval email' => {
message => q{%s has requested that you join their friend network on this site %s.
%s
Please visit the following url to accept or deny the request:
%s},
lastUpdated => 0,
},
'friends network invitation' => {
message => q{Friends Network Invitation},
lastUpdated => 0,
},
'send friend email instructions' => {
message => q{Check the friends you'd like to send a message to and then fill in the message below.},
lastUpdated => 0,
},
'confirm remove friends' => {
message => q{Are you certain you wish to remove the selected friends from your list?},
lastUpdated => 0,
},
'already a friend' => {
message => q{You can't add a friend twice.},
lastUpdated => 1186028432,
},
'add to friends list' => {
message => q{Add this person to my friends list.},
lastUpdated => 1186028432,
},
'add to friends' => {
message => q{Add to Friends},
lastUpdated => 1186030775,
},
'add to friends description' => {
message => q{Do you really want to add %s as a friend?},
lastUpdated => 1186030776,
},
'add to friends confirmation' => {
message => q{An email has been sent to %s for your request to be added to your friends network.},
lastUpdated => 1186030776,
},
'add to friends profile' => {
message => q{Return to %s's Profile},
lastUpdated => 1186030776,
},
'does not want to be a friend' => {
message => q{This user prefers not to be added as a friend.},
lastUpdated => 1186264488,
},
'manage friends template' => {
message => q{Manage Friends Template},
lastUpdated => 1186264488,
context => "setting",
},
'manage friends template help' => {
message => q{Which template would you like to use for the "See my friends." screen in the user account?},
lastUpdated => 1186264488,
context => "setting",
},
'deny unanswered friends' => {
message => q{Deny Unanswered Friends},
lastUpdated => 1186264488,
context => "workflow activity",
},
'timeout' => {
message => q{Timeout},
lastUpdated => 1186264488,
context => "workflow activity",
},
'timeout help' => {
message => q{How long should invitations to a friends network go unanswered before we automatically deny the request?},
lastUpdated => 1186264488,
context => "workflow activity",
},
'add' => {
message => q{Add},
lastUpdated => 1186264488,
},
'default friend comments' => {
message => q{%s,
I'd like you to be a part of my friends network.
Thanks,
%s},
lastUpdated => 1186277362,
},
'friend request' => {
message => q{Friend Request},
lastUpdated => 1186277362,
},
'friend request description' => {
message => q{%s has requested you be added to their friends list with the following comments:},
lastUpdated => 1186277362,
},
'invalid invite code' => {
message => q|Invalid invitation code|,
lastUpdated => 1186718713,
},
'invalid invite code message' => {
message => q|The invitation code in your URL is invalid.|,
lastUpdated => 1186718715,
},
'not the right user' => {
message => q|The invitation code you are trying to use is not for you.|,
lastUpdated => 1186718715,
},
'you have not been added' => {
message => q|You have denied %s's request.|,
lastUpdated => 1186718715,
},
'you have been added' => {
message => q|You have been added to %s's Friends List.|,
lastUpdated => 1186718715,
},
'manage friends' => {
message => q|Manage Friends or send them private messages.|,
lastUpdated => 1186975937,
},
'no friends' => {
message => q|You haven't signed up any friends.|,
lastUpdated => 1186976178,
},
'my friends' => {
message => q|My Friends|,
lastUpdated => 1186976178,
},
'name' => {
message => q|Name|,
lastUpdated => 1186976178,
},
'status' => {
message => q|Status|,
lastUpdated => 1186976178,
},
'online' => {
message => q|Online|,
lastUpdated => 1186976178,
},
'offline' => {
message => q|Offline|,
lastUpdated => 1186976178,
},
'send message' => {
message => q|Send Message|,
lastUpdated => 1186976178,
},
'remove' => {
message => q|Remove|,
lastUpdated => 1186976178,
},
'see my friends' => {
message => q|See my friends.|,
lastUpdated => 1187066104,
},
};
1;

View file

@ -3138,8 +3138,8 @@ and tracked by WebGUI.|,
},
'user function style description' => {
message => q|Defines which style to be used to style WebGUI operations (profile editing, message log, etc.) when they are available to a user.|,
lastUpdated => 1120239343,
message => q|Defines which style to be used to style WebGUI operations (profile editing, message log, etc.) when they are available to a user. Only templates which have been committed are allowed.|,
lastUpdated => 1192735786,
},
'admin console template description' => {
@ -3546,7 +3546,22 @@ LongTruncOk=1</p>
},
'allow private messages label' => {
message => q|Allow Private Messages|,
message => q|Private Message Options|,
lastUpdated => 1181019679,
},
'user profile field private message allow label' => {
message => q|Allow All|,
lastUpdated => 1181019679,
},
'user profile field private message friends only label' => {
message => q|Allow From My Friends Only|,
lastUpdated => 1181019679,
},
'user profile field private message allow none label' => {
message => q|Allow None|,
lastUpdated => 1181019679,
},
@ -3570,6 +3585,11 @@ LongTruncOk=1</p>
lastUpdated => 1181019679,
},
'private message delete text' => {
message => q|delete|,
lastUpdated => 1181019679,
},
'view inbox template' => {
message => q|Inbox Template|,
lastUpdated => 1181019679,
@ -3870,6 +3890,11 @@ LongTruncOk=1</p>
lastUpdated => 1185162267,
},
'user profile field friend availability' => {
message => q{Are you available to be added as a Friend?},
lastUpdated => 1185856549,
},
};
1;

View file

@ -179,13 +179,13 @@ our $I18N = {
},
'spectre not running error' => {
message => q|Spectre <b>is not running</b>.<br/>Unable to get workflow information.|,
message => q|Spectre <b>is not running</b>.<br />Unable to get detailed workflow information.<br />|,
context => q||,
lastUpdated => 0,
lastUpdated => 1192031332,
},
'spectre no info error' => {
message => q|Spectre <b>is running</b>, but I was not able to get workflow information.|,
message => q|Spectre <b>is running</b>, but I was not able to get detailed workflow information.<br />|,
context => q||,
lastUpdated => 0,
},