Skip to content

Commit

Permalink
Expand table editor / imagehelper features for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjensen committed Apr 28, 2016
1 parent 4554728 commit c40ea9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
38 changes: 25 additions & 13 deletions 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
Expand All @@ -21,16 +19,21 @@ 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+//;
$imagebase =~ s:[\s/]*$:/:;
}

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 = {
Expand All @@ -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>&nbsp;<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>&nbsp;<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

Expand Down
10 changes: 6 additions & 4 deletions 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@perusion.net>
#
# This program was originally based on Vend 0.2 and 0.3
Expand All @@ -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;
Expand Down Expand Up @@ -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) . ':';
Expand Down

0 comments on commit c40ea9c

Please sign in to comment.