Skip to content
This repository
tag: REL_5_7_6
Fetching contributors…

Cannot retrieve contributors at this time

file 57 lines (53 sloc) 1.632 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
# Copyright 2005-2007 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: imagedir.widget,v 1.7 2007-03-30 23:40:58 pajamian Exp $

CodeDef imagedir Widget 1
CodeDef imagedir Description Image listing
CodeDef imagedir ExtraMeta <<EOM
{
_order => [ qw/ follow_symlinks / ],
follow_symlinks => {
widget => 'yesno',
label => 'Follow Symlinks',
help => 'Set to yes if you want to list all files, even following symbolic links',
},
}
EOM

CodeDef imagedir Routine <<EOR
use File::Find;
sub {
my ($opt) = @_;
my $dir = delete $opt->{dir} || delete $opt->{outboard};
my $suf = delete $opt->{suffix} || delete $opt->{options};
return undef unless -d $dir;
#::logDebug("passed suf=$suf");
$suf = '\.(GIF|gif|JPG|JPEG|jpg|jpeg|png|PNG)'
unless $suf;

if($suf and $suf !~ /[\.|]/) {
my @types = grep /\S/, split /[,\s\0]+/, $suf;
$suf = '\.(' . join("|", @types) . ')';
}

my @names;
my $regex;
eval {
$regex = qr{$suf$};
};
return undef if $@;
my $wanted = sub {
return undef unless -f $_;
return undef unless $_ =~ $regex;
my $n = $File::Find::name;
$n =~ s:^$dir/?::;
push(@names, $n);
};
find({ wanted => $wanted, follow => $opt->{follow_symlinks} }, $dir);
$opt->{passed} = [ '=None', sort @names ];
$opt->{type} = delete $opt->{variant} || 'combo';
return Vend::Form::display($opt);
}
EOR
Something went wrong with that request. Please try again.