Fix handling of extra_query_params in Business::OnlinePayment wrapper.
[interchange.git] / code / Widget / imagedir.widget
1 # Copyright 2005-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: imagedir.widget,v 1.7 2007-03-30 23:40:58 pajamian Exp $
9
10 CodeDef imagedir Widget 1
11 CodeDef imagedir Description Image listing
12 CodeDef imagedir ExtraMeta <<EOM
13 {
14         _order => [ qw/ follow_symlinks / ],
15         follow_symlinks => {
16                 widget => 'yesno',
17                 label => 'Follow Symlinks',
18                 help => 'Set to yes if you want to list all files, even following symbolic links',
19         },
20 }
21 EOM
22
23 CodeDef imagedir Routine <<EOR
24 use File::Find;
25 sub {
26         my ($opt) = @_;
27         my $dir = delete $opt->{dir}    || delete $opt->{outboard};
28         my $suf = delete $opt->{suffix} || delete $opt->{options};
29         return undef unless -d $dir;
30 #::logDebug("passed suf=$suf");
31         $suf = '\.(GIF|gif|JPG|JPEG|jpg|jpeg|png|PNG)'
32                 unless $suf;
33
34         if($suf and $suf !~ /[\.|]/) {
35                 my @types = grep /\S/, split /[,\s\0]+/, $suf;
36                 $suf = '\.(' . join("|", @types) . ')';
37         }
38
39         my @names;
40         my $regex;
41         eval {
42                 $regex = qr{$suf$};
43         };
44         return undef if $@;
45         my $wanted = sub {
46                                         return undef unless -f $_;
47                                         return undef unless $_ =~ $regex;
48                                         my $n = $File::Find::name;
49                                         $n =~ s:^$dir/?::;
50                                         push(@names, $n);
51                                 };
52         find({ wanted => $wanted, follow => $opt->{follow_symlinks} }, $dir);
53         $opt->{passed} = [ '=None', sort @names ];
54         $opt->{type} = delete $opt->{variant} || 'combo';
55         return Vend::Form::display($opt);
56 }
57 EOR