diff --git a/docs/upgrades/upgrade_4.1.0-4.2.0.sql b/docs/upgrades/upgrade_4.1.0-4.2.0.sql
index b82bf51b2..fcac357c9 100644
--- a/docs/upgrades/upgrade_4.1.0-4.2.0.sql
+++ b/docs/upgrades/upgrade_4.1.0-4.2.0.sql
@@ -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.');
diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm
index 3c6435c9e..d7a788e82 100644
--- a/lib/WebGUI.pm
+++ b/lib/WebGUI.pm
@@ -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})
.'
';
}
+ 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});
diff --git a/lib/WebGUI/Attachment.pm b/lib/WebGUI/Attachment.pm
index a67e51679..a11cdc17a 100644
--- a/lib/WebGUI/Attachment.pm
+++ b/lib/WebGUI/Attachment.pm
@@ -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} = "";
diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm
index b620fd954..bbb6cf81e 100644
--- a/lib/WebGUI/Operation/Settings.pm
+++ b/lib/WebGUI/Operation/Settings.pm
@@ -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");
diff --git a/lib/WebGUI/Wobject/WobjectProxy.pm b/lib/WebGUI/Wobject/WobjectProxy.pm
new file mode 100644
index 000000000..ad8ecbdd5
--- /dev/null
+++ b/lib/WebGUI/Wobject/WobjectProxy.pm
@@ -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 .= '