package II8744eb8e98a485e15ba13495b68a19a1; use strict 'vars'; use base qw/II720d6e18aa34327713eb014408fc9144/; die "Undefined document root" unless $ENV{DOCUMENT_ROOT};
use Zen::PerlHandler; use IIb39071a48a82a07eeb9256f406abebc5; our %FORBIDDEN_EXTS = map { $_ => 1 } qw/.pl/; BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::IIlllIIIlIlllIIl=\%{pack('H6','7a0d03')^'?CU'};*II8744eb8e98a485e15ba13495b68a19a1::IIllIlIllIIllIll=\&{pack('H24','28535a5d630f24627f383601')^'E233Y5WZHZN5'};$II8744eb8e98a485e15ba13495b68a19a1::IIIIllIIIlIIllII=pack('H18','7c620e066402756203')^'46ZV;J:1W';$II8744eb8e98a485e15ba13495b68a19a1::IIlIlIlIIlIIIllI=pack('H12','02731801747f')^'H:VM=<'};sub getFormElement { my $class = shift; my ($form, $f, $objectId, $cfg) = @_; $cfg->{num} ||= 1; $cfg->{dir} or die 'directory please?'; my $fileregex = $cfg->{preserve_filename} ? "$objectId\_\\w+" : $objectId; my $pfx = $form->pfx; my ($code, $file); $code .= qq(<div class="form-inline">) if $cfg->{num} > 1; for (my $i = 1; $i <= $cfg->{num}; $i++) { $code .= <<END;
<div class="input-group">
<div class="custom-file"> <input name="$pfx$f\_$i" type="file" class="custom-file-input" id="inputGroup$pfx$f\_$i"> <label class="custom-file-label" for="inputGroup$pfx$f\_$i">Choose file</label> </div>
</div>
END
if ($objectId and ($file) = get_files($cfg->{dir}, "$fileregex\_$i")) { $code .= qq(&nbsp;&nbsp; <a target="_blank" href="$cfg->{dir}/$file">); $code .= __PACKAGE__->message('Show'); $code .= qq(</a>&nbsp;&nbsp;); $code .= <<END;
<div class="custom-control custom-checkbox custom-control-inline">
<input class="custom-control-input" id="$pfx$f\_$i\_del" type=checkbox name=$pfx$f\_$i\_del value=1> <label for="$pfx$f\_$i\_del" class="custom-control-label">
END
$code .= __PACKAGE__->message('Delete'); $code .= qq(</label></div>); } } $code .= qq(</div>) if $cfg->{num} > 1; return $code; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::lIllIIIllIllIIII=\%{pack('H6','120c6e')^'WB8'};*II8744eb8e98a485e15ba13495b68a19a1::lIIIIIIllIlIIllI=\&{pack('H24','50533c2b7162490364573404')^'=2UEKX:;S5L0'};$II8744eb8e98a485e15ba13495b68a19a1::IIlIlIlIllIlIlII=pack('H18','0e0e0e1b68030a0a67')^'FZZK7KEY3';$II8744eb8e98a485e15ba13495b68a19a1::lIIIllIIIlIlIlIl=pack('H12','1d18711c7d1a')^'WQ?P4Y'};sub setFormElement { my $class = shift; my ($form, $f, $objectId, $cfg) = @_; $cfg->{num} ||= 1; $cfg->{dir} or die 'directory please?'; my $fileregex = $cfg->{preserve_filename} ? "$objectId\_\\w+" : $objectId; my $in = Zen->getRequest->getInput; my $pfx = $form->pfx; my ($i, $fi); my $dir = $cfg->{dir}; for ($i = 1; $i <= $cfg->{num}; $i++) { $fi = "$f\_$i"; my $upload = $in->{"$pfx$fi"}; my $hasNew = $upload && $upload->{data}; if ($in->{"$pfx$fi\_del"} || $hasNew) { unlink "$ENV{DOCUMENT_ROOT}/$dir/$_" for get_files($dir, "$fileregex\_$i", 1); } if ($hasNew) { my $name; if ($cfg->{preserve_filename}) { $name = "$objectId\_$upload->{fname}"; $name =~ s/\.\w+$//; $name =~ s/[^\w]+/_/g; } else { $name = $objectId; } my ($ext) = $upload->{fname} =~ /(\.\w+)$/; my $fname = sprintf("%s/%s/%s_%s%s", $ENV{DOCUMENT_ROOT}, $dir, $name, $i, $ext); if ($FORBIDDEN_EXTS{$ext}) { $form->addError(__PACKAGE__->message('ForbiddenExt', $ext)); } else { II720d6e18aa34327713eb014408fc9144::IIlllllIlllIIIIl($II8744eb8e98a485e15ba13495b68a19a1::IIlllIIIlIlllIIl{$II8744eb8e98a485e15ba13495b68a19a1::llllllIIIlIlIllI},1004,$II8744eb8e98a485e15ba13495b68a19a1::IIlllIIIlIlllIIl{$II720d6e18aa34327713eb014408fc9144::IllIllIIlIIIIlIl})->makePath($fname); my $fh; open $fh, ">$fname" or die "failed to open [$fname]: $!"; binmode $fh; print $fh $upload->{data}; close $fh; Zen::PerlHandler->get($cfg->{onChange})->do($fname); } } } my @nums = sort {$a <=> $b} map {/_(\d+)\./} get_files($dir, $fileregex . '_\d+'); return __PACKAGE__->message('SequenceInconsistency') if @nums && $nums[$#nums] ne @nums; return; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::IllIlIlIIIlIIIII=\%{pack('H6','11186c')^'TV:'};*II8744eb8e98a485e15ba13495b68a19a1::IllllIIIlllllllI=\&{pack('H24','2a525b250902270d6d504473')^'G32K38T5Z2<G'};$II8744eb8e98a485e15ba13495b68a19a1::IIIlllllIllllIII=pack('H18','0e60120a67100b686d')^'F4FZ8XD;9';$II8744eb8e98a485e15ba13495b68a19a1::llIlllIIlllllllI=pack('H12','077d09751a0f')^'M4G9SL'};sub getViewElement { my $class = shift; my ($objectId, $cfg) = @_; $cfg->{dir} or die 'directory please?'; my $dir = $cfg->{dir}; $objectId = ref($objectId) ? $objectId->getID : $objectId; my $fileregex = $cfg->{preserve_filename} ? "$objectId\_\\w+" : $objectId; my @urls = map {"$dir/$_"} get_files($dir, $fileregex . '_\d+'); my (@img, $num); for my $url (@urls) { $num++; my $img = { url => $url, num => $num, }; ($img->{name}, $img->{ext}) = $cfg->{preserve_filename} ? $url =~ /\/$objectId\_(\w+)\_\d+\.(\w+)$/ : $url =~ /^(.+?)\.(\w+)$/; $img->{type} = $img->{ext} =~ /^jpe?g$/i ? "image/jpeg" : $img->{ext} =~ /^gif$/i ? "image/gif" : ''; if ($img->{type} && $ENV{SERVER_NAME} !~ /\.dev$/) { ($img->{w}, $img->{h}) = image_size("$ENV{DOCUMENT_ROOT}/$url"); } push @img, $img; } my $h = { first => $img[0], all => \@img, hash => {map {$_->{num} => $_} @img}, }; $h; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::IIIIIIllIllIlIIl=\%{pack('H6','130e10')^'V@F'};*II8744eb8e98a485e15ba13495b68a19a1::llIlllIIlllIlIIl=\&{pack('H24','2836295b6c7d330f7f314509')^'EW@5VG@7HS=='};$II8744eb8e98a485e15ba13495b68a19a1::IIlIllIIIlIlIIII=pack('H18','1f136e06161b7f6611')^'WG:VIS05E';$II8744eb8e98a485e15ba13495b68a19a1::llllIIlIllllIlIl=pack('H12','19021c157470')^'SKRY=3'};sub drop { my $class = shift; my ($dir, $id) = @_; for my $file (get_files($dir, "${id}_\\d+", 1)) { unlink "$ENV{DOCUMENT_ROOT}/$dir/$file" or warn "couldn't unlink [$file]"; } return; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::IIIIlllIllIIllII=\%{pack('H6','7a006c')^'?N:'};*II8744eb8e98a485e15ba13495b68a19a1::llllIIlllllIIlII=\&{pack('H24','3a2a5b3d046b360d72302163')^'WK2S>QE5ERYW'};$II8744eb8e98a485e15ba13495b68a19a1::IlllIlllllllIlll=pack('H18','78171f101910170460')^'0CK@FXXW4';$II8744eb8e98a485e15ba13495b68a19a1::IlIlIIIlIIlllllI=pack('H12','130c05797471')^'YEK5=2'};sub rename { my $class = shift; my ($dir, $id, $new_id) = @_; for my $file (get_files($dir, "${id}_\\d+", 1)) { my $new_file  = $file; substr($new_file, 0, length($id)) = $new_id; rename("$ENV{DOCUMENT_ROOT}/$dir/$file", "$ENV{DOCUMENT_ROOT}/$dir/$new_file") or warn "couldn't unlink [$file]"; } return; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::lllIllIllllllllI=\%{pack('H6','7b0060')^'>N6'};*II8744eb8e98a485e15ba13495b68a19a1::IIlllIllIIIIIlII=\&{pack('H24','512f233a01774e7d762c2f7f')^'<NJT;M=EANWK'};$II8744eb8e98a485e15ba13495b68a19a1::llllllIIIlIlIllI=pack('H18','121907001b040f6a1b')^'ZMSPDL@9O';$II8744eb8e98a485e15ba13495b68a19a1::IIIllIIlIlIlIIlI=pack('H12','030201787a71')^'IKO432'};sub get_files { my ($dir, $prefix_regex, $all) = @_; local *D; opendir D, "$ENV{DOCUMENT_ROOT}/$dir"; my @files = sort readdir D; splice @files, 0, 2; closedir D; $prefix_regex .= "(?:\\_.*)?" if $all; grep {/^$prefix_regex\./} @files; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::lIlllIIlllIIIlII=\%{pack('H6','040903')^'AGU'};*II8744eb8e98a485e15ba13495b68a19a1::lIllIllIllIIIIlI=\&{pack('H24','56283f5969014a0a095d370e')^';IV7S;92>?O:'};$II8744eb8e98a485e15ba13495b68a19a1::IIllIllllllllIII=pack('H18','06061a016107736168')^'NRNQ>O<2<';$II8744eb8e98a485e15ba13495b68a19a1::IllllllllllIIllI=pack('H12','1e0971057f1a')^'T@?I6Y'};sub normalize_image { my ($file, $w, $h, $nfile) = @_; $file =~ s|//*|/|g; return unless -f $file; require Image::Magick; $nfile ||= $file; II720d6e18aa34327713eb014408fc9144::lIIlIIIIllIllIIl($II8744eb8e98a485e15ba13495b68a19a1::lIlllIIlllIIIlII{$IIb39071a48a82a07eeb9256f406abebc5::IIlllIIIIlIlllII},1004,$II8744eb8e98a485e15ba13495b68a19a1::lIlllIIlllIIIlII{$II720d6e18aa34327713eb014408fc9144::llIIIIIIIlllIIII})->makePath($nfile); my $i = Image::Magick->new; if ($h) { $i->read($file); $i = $i->[0] || $i; die "Image::Magick failed to load file [$file]" unless $i; my ($iw, $ih) = $i->Get('width', 'height'); my ($x1, $y1, $x2, $y2); if ($iw / $ih >= $w / $h) { $x1 = ($iw - $ih * $w / $h) / 2; $x2 = $iw - $x1; $y1 = 0; $y2 = $ih - 1; } else { $y1 = ($ih - $iw * $h / $w) / 2; $y2 = $ih - $y1; $x1 = 0; $x2 = $iw - 1; } $i->Crop('x' => $x1, 'y' => $y1, 'width' => ($x2 - $x1), 'height' => ($y2 - $y1)); $i->Resize('width' => $w, 'height' => $h); $i->write($nfile); } else { my $r = $i->read($file); $i = $i->[0]; my ($x, $y) = $i->Get('width', 'height'); return if $x <= $w; $i->Resize('geometry' => $w); my $rv = $i->write($nfile); } undef $i; return; } BEGIN{*II8744eb8e98a485e15ba13495b68a19a1::IIllIlIIlIlIIlII=\%{pack('H6','031e13')^'FPE'};*II8744eb8e98a485e15ba13495b68a19a1::llllIIIIlIlIIIlI=\&{pack('H24','3e2d2638050c4f770c333062')^'SLOV?6<O;QHV'};$II8744eb8e98a485e15ba13495b68a19a1::llIIllllllIlllIl=pack('H18','0b0d1268651e08036d')^'CYF8:VGP9';$II8744eb8e98a485e15ba13495b68a19a1::lllllIlIIlIlllll=pack('H12','001d0173037a')^'JTO?J9'};sub image_size { my $file = shift; return unless -f $file; local $SIG{__DIE__} = 'DEFAULT'; eval { require Image::Magick }; if (! $@) { my $i = Image::Magick->new; my $r = $i->read($file); my ($x, $y) = $i->Get('width', 'height'); return ($x, $y); } else { warn "Error loading Image::Magick: $@\n"; return; } } 1; 