Added Wobject Proxy wobject, and a Max Image Size setting.

This commit is contained in:
JT Smith 2002-07-07 01:06:54 +00:00
parent ec4629d886
commit 6f6a946daf
5 changed files with 187 additions and 13 deletions

View file

@ -101,6 +101,13 @@ insert into international values (36,'Product','English','Add an accessory.');
insert into international values (37,'Product','English','Add a related product.');
insert into international values (581,'WebGUI','English','Add New Value');
insert into international values (582,'WebGUI','English','Leave Blank');
insert into international values (583,'WebGUI','English','Max Image Size');
insert into settings values ('maxImageSize','100000');
insert into international values (1,'WobjectProxy','English','Wobject To Proxy');
insert into international values (2,'WobjectProxy','English','Edit Wobject Proxy');
create table WobjectProxy (wobjectId int not null primary key, proxiedWobjectId int not null);
insert into international values (3,'WobjectProxy','English','Wobject Proxy');
insert into international values (4,'WobjectProxy','English','Wobject proxying failed. Perhaps the proxied wobject has been deleted.');

View file

@ -22,10 +22,11 @@ use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Style;
use WebGUI::Template;
use WebGUI::Utility;
#-------------------------------------------------------------------
sub page {
my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra,
my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, $originalWobject, $proxyWobjectId,
$sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash);
WebGUI::Session::open($_[0],$_[1]);
if ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3)) {
@ -52,21 +53,27 @@ sub page {
if ($session{form}{wid} eq "new") {
$wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}};
} else {
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$session{form}{wid});
unless (${$wobject}{namespace} eq "") {
$extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}");
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
} else {
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".$session{form}{wid});
if (${$wobject}{namespace} eq "") {
WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or corrupt, but was requested "
."by $session{user}{username} [$session{user}{userId}].");
$wobject = ();
} else {
$extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}");
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
}
}
if ($wobject) {
if (${$wobject}{pageId} != $session{page}{pageId} && ${$wobject}{pageId} != 2) {
$wobjectOutput = WebGUI::International::get(417);
if (${$wobject}{pageId} != $session{page}{pageId}) {
($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from wobject,WobjectProxy
where wobject.wobjectId=WobjectProxy.wobjectId and wobject.pageId=".$session{page}{pageId}."
and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId});
${$wobject}{_WobjectProxy} = $proxyWobjectId;
}
unless (${$wobject}{pageId} == $session{page}{pageId} || ${$wobject}{pageId} == 2 || ${$wobject}{_WobjectProxy} ne "") {
$wobjectOutput .= WebGUI::International::get(417);
WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId}."] attempted to access wobject ["
.$session{form}{wid}."] on page '".$session{page}{title}."' [".$session{page}{pageId}."].");
} else {
@ -77,7 +84,6 @@ sub page {
$wobjectOutput = eval{$w->$cmd};
WebGUI::ErrorHandler::fatalError("Web method doesn't exist in wojbect: ${$wobject}{namespace} / $session{form}{func}.") if($@);
}
# $wobjectOutput = WebGUI::International::get(381); # bad error
}
}
if ($operationOutput ne "") {
@ -112,6 +118,17 @@ sub page {
.deleteIcon('func=delete&wid='.${$wobject}{wobjectId})
.'<br>';
}
if (${$wobject}{namespace} eq "WobjectProxy") {
$originalWobject = $wobject;
($wobject) = WebGUI::SQL->quickArray("select proxiedWobjectId from WobjectProxy where wobjectId=".${$wobject}{wobjectId});
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$wobject);
if (${$wobject}{namespace} eq "") {
$wobject = $originalWobject;
} else {
${$wobject}{templatePosition} = ${$originalWobject}{templatePosition};
${$wobject}{_WobjectProxy} = ${$originalWobject}{wobjectId};
}
}
$extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}");
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});

View file

@ -86,6 +86,24 @@ sub _createThumbnail {
}
#-------------------------------------------------------------------
sub _resizeImage {
my ($image, $error, $x, $y, $r, $n);
if ($hasImageMagick && isIn($_[0]->getType, qw(jpg jpeg gif png))) {
$image = Image::Magick->new;
$error = $image->Read($_[0]->getPath);
WebGUI::ErrorHandler::warn("Couldn't read image for resizing: ".$error) if $error;
($x, $y) = $image->Get('width','height');
$n = $_[1] || $session{setting}{maxImageSize};
if ($x > $n || $y > $n) {
$r = $x>$y ? $x / $n : $y / $n;
$image->Scale(width=>($x/$r),height=>($y/$r));
$error = $image->Write($_[0]->getPath);
WebGUI::ErrorHandler::warning("Couldn't resize image: ".$error) if $error;
}
}
}
#-------------------------------------------------------------------
=head2 box ( )
@ -396,7 +414,7 @@ sub rename {
#-------------------------------------------------------------------
=head2 save ( formVariableName [, thumbnailSize ] )
=head2 save ( formVariableName [, thumbnailSize, imageSize ] )
Grabs an attachment from a form POST and saves it to a node. It
then returns the filename of the attachment.
@ -410,10 +428,17 @@ sub rename {
If an image is being uploaded a thumbnail will be generated
automatically. By default, WebGUI will create a thumbnail of the
size specified in the attachment settings. You can override that
size specified in the file settings. You can override that
size by specifying one here. Size is measured in pixels of the
longest side.
=item imageSize
If a web image (gif, png, jpg, jpeg) is being uploaded it will be
resized if it is larger than this value. By default images are
resized to stay within the contraints of the Max Image Size
setting in the file settings.
=cut
sub save {
@ -440,6 +465,7 @@ sub save {
}
close($file);
_createThumbnail($_[0],$_[2]);
_resizeImage($_[0],$_[3]);
} else {
WebGUI::ErrorHandler::warn("Couldn't open file ".$_[0]->getPath." for writing due to error: ".$!);
$_[0]->{_filename} = "";

View file

@ -170,6 +170,7 @@ sub www_editFileSettings {
$f->hidden("op","editFileSettingsSave");
$f->text("lib",WebGUI::International::get(129),$session{setting}{lib});
$f->integer("maxAttachmentSize",WebGUI::International::get(130),$session{setting}{maxAttachmentSize});
$f->integer("maxImageSize",WebGUI::International::get(583),$session{setting}{maxImageSize});
$f->integer("thumbnailSize",WebGUI::International::get(406),$session{setting}{thumbnailSize});
$f->text("attachmentDirectoryWeb",WebGUI::International::get(131),$session{setting}{attachmentDirectoryWeb});
$f->text("attachmentDirectoryLocal",WebGUI::International::get(132),$session{setting}{attachmentDirectoryLocal});
@ -185,6 +186,7 @@ sub www_editFileSettings {
sub www_editFileSettingsSave {
if (WebGUI::Privilege::isInGroup(3)) {
_saveSetting("lib");
_saveSetting("maxImageSize");
_saveSetting("maxAttachmentSize");
_saveSetting("thumbnailSize");
_saveSetting("attachmentDirectoryWeb");

View file

@ -0,0 +1,122 @@
package WebGUI::Wobject::WobjectProxy;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# 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 Tie::CPHash;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Wobject;
our @ISA = qw(WebGUI::Wobject);
our $namespace = "WobjectProxy";
our $name = WebGUI::International::get(3,$namespace);
#-------------------------------------------------------------------
sub duplicate {
my ($w);
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::WobjectProxy->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
proxiedWobjectId=>$_[0]->get("proxiedWobjectId")
});
}
#-------------------------------------------------------------------
sub new {
my ($self, $class, $property);
$class = shift;
$property = shift;
$self = WebGUI::Wobject->new($property);
bless $self, $class;
}
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],[qw(proxiedWobjectId)]);
}
#-------------------------------------------------------------------
sub www_copy {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->duplicate;
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($output, $f, $endDate, $templatePosition,%wobjects, %page, %wobject, $a, $b);
tie %wobject, 'Tie::CPHash';
tie %page, 'Tie::CPHash';
tie %wobjects, 'Tie::IxHash';
if (WebGUI::Privilege::canEditPage()) {
$output = helpIcon(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(2,$namespace).'</h1>';
$templatePosition = $_[0]->get("templatePosition") || '0';
$endDate = $_[0]->get("endDate") || (time()+315360000);
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$f->hidden("namespace",$_[0]->get("namespace")) if ($_[0]->get("wobjectId") eq "new");
$f->hidden("func","editSave");
$f->readOnly($_[0]->get("wobjectId"),WebGUI::International::get(499));
$f->hidden("title",$namespace);
$f->hidden("displayTitle",0);
$f->hidden("processMacros",0);
$f->select("templatePosition",WebGUI::Template::getPositions($session{page}{templateId}),WebGUI::International::get(363),[$templatePosition]);
$f->date("startDate",WebGUI::International::get(497),$_[0]->get("startDate"));
$f->date("endDate",WebGUI::International::get(498),$endDate);
$a = WebGUI::SQL->read("select pageId,menuTitle from page where pageId<2 or pageId>25 order by title");
while (%page = $a->hash) {
$b = WebGUI::SQL->read("select wobjectId,title from wobject where pageId=".$page{pageId}." and namespace<>'WobjectProxy' order by sequenceNumber");
while (%wobject = $b->hash) {
$wobjects{$wobject{wobjectId}} = $page{menuTitle}." / ".$wobject{title}." (".$wobject{wobjectId}.")";
}
$b->finish;
}
$a->finish;
$f->select("proxiedWobjectId",\%wobjects,WebGUI::International::get(1,$namespace),[$_[0]->get("proxiedWobjectId")]);
$f->submit;
$output .= $f->print;
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSave {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->SUPER::www_editSave();
$_[0]->set({
proxiedWobjectId=>$session{form}{proxiedWobjectId}
});
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_view {
return WebGUI::International::get(4,$namespace);
}
1;