first run on new asset system

This commit is contained in:
JT Smith 2004-12-17 05:41:22 +00:00
parent f7dd3b0577
commit 382ced9ffe
27 changed files with 785 additions and 374 deletions

View file

@ -108,6 +108,18 @@ sub getEditForm {
}
#-------------------------------------------------------------------
sub getIcon {
my $self = shift;
my $small = shift;
if ($small) {
my $storage = WebGUI::Storage->new($self->get("storageId"));
return $storage->getFileIconUrl($self->get("filename"));
}
return $session{config}{extrasURL}.'/assets/file.gif';
}
#-------------------------------------------------------------------
=head2 getName
@ -151,26 +163,26 @@ Gathers data from www_edit and persists it.
sub www_editSave {
my $self = shift;
$self->SUPER::www_editSave();
my $output = $self->SUPER::www_editSave();
my $storage = WebGUI::Storage->create;
my $filename = $storage->addFileFromFormPost("file");
if (defined $filename) {
my $oldVersions;
if ($self->get($filename)) { # do file versioning
my @old = split("\n",$self->get("olderVersions"));
push(@old,$self->get{"storageId")."|".$self->get("filename"));
push(@old,$self->get("storageId")."|".$self->get("filename"));
$oldVersions = join("\n",@old);
}
$self->update({
filename=>$filename,
storageId=>$storage->getId,
fileSize=>$storage->getFileSize,
olderVersions=>$oldVersions
});
$self->setSize($storage->getFileSize($filename));
} else {
$storage->delete;
}
return "";
return $output;
}

View file

@ -98,16 +98,16 @@ sub generateThumbnail {
}
if ($self->getValue("filename") && $hasImageMagick) {
my $storage = WebGUI::Storage->new($self->get("storageId"));
$image = Image::Magick->new;
$error = $image->Read($storage->getPath($storage->get("filename")));
my $image = Image::Magick->new;
my $error = $image->Read($storage->getPath($storage->get("filename")));
if ($error) {
$self->_addError("Couldn't read image for thumnail creation: ".$error);
return 0;
}
($x, $y) = $image->Get('width','height');
$n = $self->get("thumbnailSize");
my ($x, $y) = $image->Get('width','height');
my $n = $self->get("thumbnailSize");
if ($x > $n || $y > $n) {
$r = $x>$y ? $x / $n : $y / $n;
my $r = $x>$y ? $x / $n : $y / $n;
$image->Scale(width=>($x/$r),height=>($y/$r));
}
if (isIn($storage->getFileExtension($self->get("filename")), qw(tif tiff bmp))) {
@ -152,6 +152,15 @@ sub getEditForm {
}
#-------------------------------------------------------------------
sub getIcon {
my $self = shift;
my $small = shift;
return $session{config}{extrasURL}.'/assets/image.gif' unless ($small);
$self->SUPER::getIcon(1);
}
#-------------------------------------------------------------------
=head2 getName

View file

@ -92,6 +92,15 @@ sub getEditForm {
}
#-------------------------------------------------------------------
sub getIcon {
my $self = shift;
my $small = shift;
return $session{config}{extrasURL}.'/assets/small/redirect.gif' if ($small);
return $session{config}{extrasURL}.'/assets/redirect.gif';
}
#-------------------------------------------------------------------
=head2 getUiLevel ()

View file

@ -18,6 +18,7 @@ use CGI::Util qw(rearrange);
use DBI;
use strict qw(subs vars);
use Tie::IxHash;
use WebGUI::Asset;
use WebGUI::AdminConsole;
use WebGUI::DateTime;
use WebGUI::FormProcessor;
@ -32,6 +33,7 @@ use WebGUI::Node;
use WebGUI::Page;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::Style;
use WebGUI::SQL;
use WebGUI::TabForm;
use WebGUI::Template;
@ -40,9 +42,11 @@ use WebGUI::Utility;
use WebGUI::MetaData;
use WebGUI::Wobject::WobjectProxy;
our @ISA = qw(WebGUI::Asset);
=head1 NAME
Package WebGUI::Wobject
Package WebGUI::Asset::Wobject
=head1 DESCRIPTION
@ -83,7 +87,19 @@ sub definition {
cacheTimeoutVisitor=>{
fieldType=>'interval',
defaultValue=>600
}
},
templateId=>{
fieldType=>'template',
defaultValue=>undef
},
styleTemplateId=>{
fieldType=>'template',
defaultValue=>undef
},
printableStyleTemplateId=>{
fieldType=>'template',
defaultValue=>undef
}
}
});
return $class->SUPER::definition($definition);
@ -115,7 +131,7 @@ A comparison expression to be used when checking whether the action should be al
sub confirm {
return WebGUI::Privilege::vitalComponent() if ($_[4]);
my $noURL = $_[3] || WebGUI::URL::page();
my $noURL = $_[3] || $_[0]->getUrl;
my $output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= $_[1].'<p>';
$output .= '<div align="center"><a href="'.$_[2].'">'.WebGUI::International::get(44).'</a>';
@ -174,24 +190,24 @@ sub getEditForm {
$tabform->getTab("layout")->template(
-name=>"styleTemplateId",
-label=>WebGUI::International::get(1073),
-value=>($page{styleId} || 2),
-value=>$self->getValue("styleTemplateId"),
-namespace=>'style',
-afterEdit=>'op=editPage&amp;npp='.$session{form}{npp}
);
$tabform->getTab("layout")->template(
-name=>"printableStyleTemplateId",
-label=>WebGUI::International::get(1079),
-value=>($page{printableStyleId} || 3),
-value=>$self->getValue("printableStyleTemplateId"),
-namespace=>'style',
-afterEdit=>'op=editPage&amp;npp='.$session{form}{npp}
);
if ($childCount) {
# if ($childCount) {
$tabform->getTab("layout")->yesNo(
-name=>"recurseStyle",
-subtext=>' &nbsp; '.WebGUI::International::get(106),
-uiLevel=>9
);
}
# }
$tabform->getTab("properties")->HTMLArea(
-name=>"description",
-label=>WebGUI::International::get(85),
@ -209,6 +225,7 @@ sub getEditForm {
-value=>$self->getValue("cacheTimeoutVisitor"),
-uiLevel=>8
);
return $tabform;
}
@ -237,7 +254,20 @@ Logs the view of the wobject to the passive profiling mechanism.
sub logView {
my $self = shift;
WebGUI::PassiveProfiling::add($self->get("assetId"));
if ($session{setting}{passiveProfilingEnabled}) {
WebGUI::PassiveProfiling::add($self->get("assetId"));
# not sure what this will do in the new model
# WebGUI::PassiveProfiling::addPage(); # add wobjects on asset to passive profile log
}
# disabled for the time being because it's dangerous
# if ($session{form}{op} eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new") {
# WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer,
# assetId, assetTitle, wobjectId, wobjectFunction) values (".time().",".quote($session{user}{userId})
# .",".quote($session{user}{username}).",
# ".quote($session{env}{REMOTE_ADDR}).", ".quote($session{env}{HTTP_USER_AGENT}).",
# ".quote($session{env}{HTTP_REFERER}).", ".quote($session{asset}{assetId}).",
# ".quote($session{asset}{title}).", ".quote($session{form}{wid}).", ".quote($session{form}{func}).")");
# }
return;
}
@ -261,16 +291,10 @@ sub processMacros {
#-------------------------------------------------------------------
=head2 processTemplate ( templateId, vars [ , namespace ] )
=head2 processTemplate ( vars, namespace [ , templateId ] )
Returns the content generated from this template.
B<NOTE:> Only for use in wobjects that support templates.
=head3 templateId
An id referring to a particular template in the templates table.
=head3 hashRef
A hash reference containing variables and loops to pass to the template engine.
@ -279,27 +303,41 @@ A hash reference containing variables and loops to pass to the template engine.
A namespace to use for the template. Defaults to the wobject's namespace.
=head3 templateId
An id referring to a particular template in the templates table. Defaults to $self->get("templateId").
=cut
sub processTemplate {
my $self = shift;
my $templateId = shift;
my $var = shift;
my $namespace = shift || $self->get("namespace");
if ($self->{_useMetaData}) {
my $meta = WebGUI::MetaData::getMetaDataFields($self->get("wobjectId"));
foreach my $field (keys %$meta) {
$var->{$meta->{$field}{fieldName}} = $meta->{$field}{value};
}
my $namespace = shift;
my $templateId = shift || $self->get("templateId");
my $meta = WebGUI::MetaData::getMetaDataFields($self->get("wobjectId"));
foreach my $field (keys %$meta) {
$var->{$meta->{$field}{fieldName}} = $meta->{$field}{value};
}
my $wobjectToolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43))
.editIcon('func=edit',$self->get("url"))
.moveUpIcon('func=promote',$self->get("url"))
.moveDownIcon('func=demote',$self->get("url"))
# .moveTopIcon('func=moveTop&wid='.${$wobject}{wobjectId})
# .moveBottomIcon('func=moveBottom&wid='.${$wobject}{wobjectId})
.cutIcon('func=cut',$self->get("url"))
.copyIcon('func=copy',$self->get("url"));
# if (${$wobject}{namespace} ne "WobjectProxy" && isIn("WobjectProxy",@{$session{config}{wobjects}})) {
# $wobjectToolbar .= shortcutIcon('func=createShortcut');
#}
$var->{'controls'} = $wobjectToolbar;
my %vars = (
%{$self->{_property}},
%{$self->{_properties}},
%{$var}
);
if (defined $self->get("_WobjectProxy")) {
$vars{isShortcut} = 1;
my ($originalPageURL) = WebGUI::SQL->quickArray("select urlizedTitle from page where pageId=".quote($self->get("pageId")),WebGUI::SQL->getSlave);
$vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$self->get("wobjectId"));
my ($originalPageURL) = WebGUI::SQL->quickArray("select url from asset where assetId=".quote($self->getId),WebGUI::SQL->getSlave);
$vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$self->getId);
}
return WebGUI::Template::process($templateId,$namespace, \%vars);
}
@ -320,6 +358,14 @@ sub purge {
#-------------------------------------------------------------------
sub view {
my $self = shift;
return "No view has been created for this wobject.";
}
#-------------------------------------------------------------------
=head2 www_createShortcut ( )
@ -360,12 +406,47 @@ B<NOTE:> This method should only need to be extended if you need to do some spec
sub www_editSave {
my $self = shift;
$self->SUPER::www_editSave();
my $output = $self->SUPER::www_editSave();
WebGUI::MetaData::metaDataSave($self->getId);
return "";
return $output;
}
#-------------------------------------------------------------------
sub www_view {
my $self = shift;
$self->logView();
return WebGUI::Privilege::noAccess() unless $self->canView;
my $cache;
my $output;
my $useCache = (
$session{form}{op} eq "" &&
(
( $self->get("cacheTimeout") > 10 && $session{user}{userId} !=1) ||
( $self->get("cacheTimeoutVisitor") > 10 && $session{user}{userId} == 1)
) &&
not $session{var}{adminOn}
);
# if ($useCache) {
# $cache = WebGUI::Cache->new("asset_".$self->getId."_".$session{user}{userId});
# $output = $cache->get;
# }
unless ($output) {
$output = $self->view;
my $ttl;
if ($session{user}{userId} == 1) {
$ttl = $self->get("cacheTimeoutVisitor");
} else {
$ttl = $self->get("cacheTimeout");
}
# $cache->set($output, $ttl) if ($useCache && !WebGUI::HTTP::isRedirect());
}
return WebGUI::Style::process($output,$self->get("styleTemplateId"));
}
1;

View file

@ -22,8 +22,7 @@ use WebGUI::International;
use WebGUI::Paginator;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::URL;
use WebGUI::Wobject;
use WebGUI::Asset::Wobject;
our @ISA = qw(WebGUI::Asset::Wobject);
@ -61,21 +60,21 @@ sub getEditForm {
my $tabform = $self->SUPER::getEditForm();
$tabform->getTab("properties")->text(
-name=>"linkTitle",
-label=>WebGUI::International::get(7,$self->get("namespace")),
-label=>WebGUI::International::get(7,"Article"),
-value=>$self->getValue("linkTitle"),
-uiLevel=>3
);
$tabform->getTab("properties")->url(
-name=>"linkURL",
-label=>WebGUI::International::get(8,$self->get("namespace")),
-label=>WebGUI::International::get(8,"Article"),
-value=>$self->getValue("linkURL"),
-uiLevel=>3
);
$tabform->getTab("layout")->yesNo(
-name=>"convertCarriageReturns",
-label=>WebGUI::International::get(10,$_[0]->get("namespace")),
-value=>$_[0]->getValue("convertCarriageReturns"),
-subtext=>' &nbsp; <span style="font-size: 8pt;">'.WebGUI::International::get(11,$_[0]->get("namespace")).'</span>',
-label=>WebGUI::International::get(10,"Article"),
-value=>$self->getValue("convertCarriageReturns"),
-subtext=>' &nbsp; <span style="font-size: 8pt;">'.WebGUI::International::get(11,"Article").'</span>',
-uiLevel=>5,
-defaultValue=>0
);
@ -83,6 +82,15 @@ sub getEditForm {
}
#-------------------------------------------------------------------
sub getIcon {
my $self = shift;
my $small = shift;
return $session{config}{extrasURL}.'/assets/small/article.gif' if ($small);
return $session{config}{extrasURL}.'/assets/article.gif';
}
#-------------------------------------------------------------------
sub getName {
return WebGUI::International::get(1,"Article");
@ -90,31 +98,8 @@ sub getName {
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;
return WebGUI::Privilege::insufficient() unless $self->canEdit;
$self->getAdminConsole->setHelp("article add/edit");
return $self->getAdminConsole->render($self->getEditForm,WebGUI::International::get("12","Article"));
}
#-------------------------------------------------------------------
sub www_editSave {
my ($image, $attachment, %property);
$_[0]->SUPER::www_editSave() if ($_[0]->get("wobjectId") eq "new");
$image = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$image->save("image");
$attachment = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$attachment->save("attachment");
$property{image} = $image->getFilename if ($image->getFilename ne "");
$property{attachment} = $attachment->getFilename if ($attachment->getFilename ne "");
return $_[0]->SUPER::www_editSave(\%property);
}
#-------------------------------------------------------------------
sub www_view {
sub view {
my $self = shift;
$self->logView() if ($session{setting}{passiveProfilingEnabled});
my ($file, %var);
if ($self->get("image") ne "") {
$file = WebGUI::Attachment->new($self->get("image"),$self->get("wobjectId"));
@ -125,7 +110,7 @@ sub www_view {
if ($self->get("convertCarriageReturns")) {
$var{description} =~ s/\n/\<br\>\n/g;
}
$var{"new.template"} = WebGUI::URL::page("wid=".$self->get("wobjectId")."&func=view")."&overrideTemplateId=";
$var{"new.template"} = $self->getUrl("wid=".$self->get("wobjectId")."&func=view")."&overrideTemplateId=";
$var{"description.full"} = $var{description};
$var{"description.full"} =~ s/\^\-\;//g;
$var{"description.first.100words"} = $var{"description.full"};
@ -150,7 +135,7 @@ sub www_view {
$var{"description.first.2sentences"} =~ s/^((.*?\.){2}).*/$1/s;
$var{"description.first.sentence"} = $var{"description.first.2sentences"};
$var{"description.first.sentence"} =~ s/^(.*?\.).*/$1/s;
my $p = WebGUI::Paginator->new(WebGUI::URL::page("wid=".$self->get("wobjectId")."&func=view"),1);
my $p = WebGUI::Paginator->new($self->getUrl("wid=".$self->get("wobjectId")."&func=view"),1);
if ($session{form}{makePrintable} || $var{description} eq "") {
$var{description} =~ s/\^\-\;//g;
$p->setDataByArrayRef([$var{description}]);
@ -167,7 +152,7 @@ sub www_view {
$var{"attachment.url"} = $file->getURL;
$var{"attachment.name"} = $file->getFilename;
}
my $callback = WebGUI::URL::page("func=view&amp;wid=".$self->get("wobjectId"));
my $callback = $self->getUrl("func=view&amp;wid=".$self->get("wobjectId"));
if ($self->get("allowDiscussion")) {
my $forum = WebGUI::Forum->new($self->get("forumId"));
$var{"replies.count"} = ($forum->get("replies") + $forum->get("threads"));
@ -188,10 +173,20 @@ sub www_view {
forumId=>$self->get("forumId")
});
} else {
return $self->processTemplate($templateId,\%var);
return $self->processTemplate(\%var, "Article", $templateId);
}
}
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;
return WebGUI::Privilege::insufficient() unless $self->canEdit;
$self->getAdminConsole->setHelp("article add/edit");
return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get("12","Article"));
}
1;