[interchange] Expand table editor / imagehelper features for file uploads
Jon Jensen
interchange-cvs at icdevgroup.org
Fri Apr 29 03:03:19 UTC 2016
commit c40ea9cb796114450931d73602f9bc62dc80df9d
Author: Jon Jensen <jon at endpoint.com>
Date: Thu Mar 31 23:25:13 2016 -0600
Expand table editor / imagehelper features for file uploads
code/Widget/imagehelper.widget | 38 +++++++++++++++++++++++++-------------
lib/Vend/Table/Editor.pm | 10 ++++++----
2 files changed, 31 insertions(+), 17 deletions(-)
---
diff --git a/code/Widget/imagehelper.widget b/code/Widget/imagehelper.widget
index 5364f05..79f6035 100644
--- a/code/Widget/imagehelper.widget
+++ b/code/Widget/imagehelper.widget
@@ -1,11 +1,9 @@
-# Copyright 2005-2007 Interchange Development Group and others
+# Copyright 2005-2016 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
-#
-# $Id: imagehelper.widget,v 1.6 2007-03-30 23:40:58 pajamian Exp $
CodeDef imagehelper Widget 1
CodeDef imagehelper Description Image upload
@@ -21,6 +19,7 @@ sub {
my $imagebase = $opt->{image_base} || $opt->{prepend};
Vend::Interpolate::vars_and_comments(\$path);
+ $path =~ s/^\s+//;
Vend::Interpolate::vars_and_comments(\$imagebase);
if ($imagebase ||= '') {
$imagebase =~ s/^\s+//;
@@ -28,9 +27,13 @@ sub {
}
my $of_widget;
+ my $orig_path = $path;
if($path =~ s!/\*(?:\.([^/]+))?$!!) {
my $spec = $1;
- my @files = UI::Primitive::list_images($path, $spec);
+ my @files = grep {length} UI::Primitive::list_images($path, $spec);
+ unless (@files) {
+ @files = grep {length} UI::Primitive::list_glob($orig_path, $opt->{image_path});
+ }
unshift(@files, "=(none)");
my $passed = join ",", map { s/,/,/g; $_} @files;
my $opt = {
@@ -43,16 +46,25 @@ sub {
undef, undef, $opt, { 'mv_data_file_oldfile' => $val } );
}
else {
- $of_widget = qq{<INPUT TYPE=hidden NAME=mv_data_file_oldfile VALUE="$val">};
+ $of_widget = qq{<input type="hidden" name="mv_data_file_oldfile" value="$val"$Vend::Xtrailer>};
+ }
+
+ my $clean_path = $path;
+ $clean_path =~ s![\*/]+$!!;
+ $size = qq{ size="$size"} if $size > 0;
+
+ # Ensure that the form is using multipart/form-data
+ $::Scratch->{mv_force_file_upload} = 1;
+ push @Vend::TmpScratch, 'mv_force_file_upload';
+
+ if ($val) {
+ qq{<a href="$imagebase$clean_path/$val">$val</a> <input type="hidden" name="mv_data_file_field" value="$name"$Vend::Xtrailer><input type="hidden" name="mv_data_file_name_from" value="$name_from"$Vend::Xtrailer>
+<input type="hidden" name="mv_data_file_path" value="$clean_path"$Vend::Xtrailer>$of_widget<input type="file" name="$name" value="$val"$Vend::Xtrailer>};
+ }
+ else {
+ qq{<input type="hidden" name="mv_data_file_field" value="$name"$Vend::Xtrailer><input type="hidden" name="mv_data_file_name_from" value="$name_from"$Vend::Xtrailer>
+<input type="hidden" name="mv_data_file_path" value="$clean_path"$Vend::Xtrailer>$of_widget<input type="file" name="$name"$size$Vend::Xtrailer>};
}
- $size = qq{ SIZE="$size"} if $size > 0;
- if ($val) {
- qq{<A HREF="$imagebase$path/$val">$val</A> <INPUT TYPE=hidden NAME=mv_data_file_field VALUE="$name"><INPUT TYPE=hidden NAME=mv_data_file_name_from VALUE="$name_from">
-<INPUT TYPE=hidden NAME=mv_data_file_path VALUE="$path">$of_widget<INPUT TYPE=file NAME="$name" VALUE="$val">};
- } else {
- qq{<INPUT TYPE=hidden NAME=mv_data_file_field VALUE="$name"><INPUT TYPE=hidden NAME=mv_data_file_name_from VALUE="$name_from">
-<INPUT TYPE=hidden NAME=mv_data_file_path VALUE="$path">$of_widget<INPUT TYPE=file NAME="$name"$size>};
- }
}
EOR
diff --git a/lib/Vend/Table/Editor.pm b/lib/Vend/Table/Editor.pm
index 78b6c23..141eed3 100644
--- a/lib/Vend/Table/Editor.pm
+++ b/lib/Vend/Table/Editor.pm
@@ -1,8 +1,6 @@
# Vend::Table::Editor - Swiss-army-knife table editor for Interchange
#
-# $Id: Editor.pm,v 1.93 2009-03-20 18:59:35 mheins Exp $
-#
-# Copyright (C) 2002-2008 Interchange Development Group
+# Copyright (C) 2002-2016 Interchange Development Group
# Copyright (C) 2002 Mike Heins <mike at perusion.net>
#
# This program was originally based on Vend 0.2 and 0.3
@@ -26,7 +24,7 @@
package Vend::Table::Editor;
use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.93 $, 10);
+$VERSION = '1.94';
use Vend::Util;
use Vend::Interpolate;
@@ -4139,6 +4137,10 @@ EOF
$rowcount++;
}
+ if (delete $::Scratch->{mv_force_file_upload} and $outhash{FORM_BEGIN} !~ /form-data/) {
+ $outhash{FORM_BEGIN} =~ s#># enctype="multipart/form-data">#;
+ }
+
$::Scratch->{mv_data_enable} = '';
if($opt->{auto_secure}) {
$::Scratch->{mv_data_enable} .= "$table:" . join(",", @data_enable) . ':';
More information about the interchange-cvs
mailing list