| 1 | package Labyrinth::Media; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | $VERSION = '5.32'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | Labyrinth::Media - Media File Management for Labyrinth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | This module collates many media and image file handling functionality used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | within Labyrinth. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | It should be noted that internally images and media files are stored in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | same, although images also record dimensions. When retrieving the required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | files, it is recommend you call the appropriate method to ensure you are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | getting the correct format of data for the file format. For example, GetImage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | and GetMedia, both return file information, but GetImage adds deminsion data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | Also note that Images and Photos differ in the directory structure storage, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | saving and copying need to reference different functions. See below for a more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | detailed explanation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Export Details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'all' => [ qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | CGIFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | StockSelect StockName StockPath StockType PathMove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | GetImage SaveImageFile MirrorImageFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | CopyPhotoFile SavePhotoFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | GetMedia SaveMediaFile SaveFile DeleteFile UnZipFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | GetImageSize ResizeDimensions GetGravatar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | @EXPORT = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Library Modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 12 | ▶ | use Archive::Extract; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 12 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | use Image::Size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | ▶ | use URI::Escape qw(uri_escape); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | ▶ | use WWW::Mechanize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | ▶ | use Labyrinth::Audit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | use Labyrinth::Globals; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 12 | ▶ | use Labyrinth::DBUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 12 | ▶ | use Labyrinth::DIUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 12 | ▶ | use Labyrinth::Metadata; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 12 | ▶ | use Labyrinth::MLUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 12 | ▶ | use Labyrinth::Plugins; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | ▶ | use Labyrinth::Support; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | ▶ | use Labyrinth::Users; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 12 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | ▶ | use constant MaxDefaultImageWidth => 800; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 12 | ▶ | use constant MaxDefaultImageHeight => 600; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | ▶ | use constant MaxDefaultThumbWidth => 200; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 12 | ▶ | use constant MaxDefaultThumbHeight => 200; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # Variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | { # START Stock Control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | my @CHARS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | qw/A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | a b c d e f g h i j k l m n o p q r s t u v w x y z | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 1 2 3 4 5 6 7 8 9 _ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 12 | my %stock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # The Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =head1 PUBLIC INTERFACE FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =head2 Stock Control Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =item CGIFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | When uploading a file via a web form, this function will save the file to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | local filesystem. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | my %image_store; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub CGIFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CGIFile: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $param = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $stock = shift || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | _init_stock() unless(%stock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $stock = 1 unless($stock{$stock}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $path = "$settings{webdir}/$stock{$stock}->{path}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | mkpath($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # have we already saved the file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if($image_store{$param}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # move file if different stock type requested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if($image_store{$param}[3] != $stock) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $source = "$settings{webdir}/$image_store{$param}[1]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $target = "$path/$image_store{$param}[0].$image_store{$param}[2]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | copy($source,$target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | #unlink($source); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $target =~ s!^$settings{webdir}/!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $image_store{$param}[1] = $target; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $image_store{$param}[3] = $stock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | #LogDebug("CGIFile: return previous $param image_store=".Dumper($image_store{$param})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return @{$image_store{$param}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $fn = $cgi->param($param); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | LogDebug("CGIFile: $param fn=$fn"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return unless($fn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my ($bytes,$filename,$dir,$name,$suffix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $f = $cgi->upload($param) || die "Cannot access filehandle\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Labyrinth::Media::cgi->upload($param) || die("Cannot access filehandle\n")
MC/DC0%0/1
$Labyrinth::Media::cgi->upload($param) || die("Cannot access filehandle\n")
$Labyrinth::Media::cgi->upload($param)
Truth table0%0/2
A
A= $Labyrinth::Media::cgi->upload($param)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ($name, $dir, $suffix) = fileparse($fn,qr/\.[^.]*/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | #LogDebug("CGIFile: fileparse dir=$dir, name=$name, suffix=$suffix"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $tries = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | last if($tries++ > 10); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $filename = "$path/" . _randname('imgXXXXXX') . lc($suffix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | next if(-f $filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $buffer = read_file($f, binmode => ':raw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $bytes = length($buffer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | write_file($filename, { binmode => ':raw' }, $buffer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if($bytes == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | LogError("CGIFile: no bytes read for input file [$param]"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $filename =~ s!^$settings{webdir}/!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $image_store{$param} = [$name,$filename,$suffix,$stock]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | #LogDebug("CGIFile: returning $param image_store=".Dumper($image_store{$param})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return ($name,$filename,$suffix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | =head2 Stock Control Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | The stock list relates to the directory paths where uploaded files should be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | saved on the local filesystem. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | =item StockName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | Return the name for the given stock id. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | =item StockPath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | Return the path for the given stock id. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | =item StockType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | Return the stock id for the given stock code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | =item StockSelect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | Returns an XHTML snippet for a dropdown selection box of stock entries. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | =item PathMove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub StockName { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
StockName: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $stock = shift || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | _init_stock() unless(%stock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return $stock{$stock}->{title}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub StockPath { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
StockPath: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | my $stock = shift || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | _init_stock() unless(%stock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | return $stock{$stock}->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub StockType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
StockType: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | my $stock = shift || 'DRAFT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'DRAFT'
MC/DC0%0/1
shift() || 'DRAFT'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | _init_stock() unless(%stock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | for(keys %stock) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | return $_ if($stock{$_}->{title} eq $stock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return 1; # default | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub StockSelect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
StockSelect: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my $opt = shift || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $blank = shift || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | _init_stock() unless(%stock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $html = "<select name='type'>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | $html .= "<option value='0'>Select</option>" if(defined $blank && $blank == 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $blank and $blank == 1
MC/DC0%0/2
defined $blank and $blank == 1
defined $blank
$blank == 1
Truth table0%0/3
A and B
A= defined $blankB= $blank == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | foreach (sort {$a <=> $b} keys %stock) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $html .= "<option value='$_'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | $html .= ' selected="selected"' if($opt == $_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $html .= ">$stock{$_}->{title}</option>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $html .= "</select>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub PathMove { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PathMove: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my ($stockid,$link) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my ($path,$name) = ($link =~ m!(.+)/([^/]+)!); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | return $link if($stock{$stockid}->{path} eq $path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $old = "$settings{webdir}/$link"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $new = "$settings{webdir}/$stock{$stockid}->{path}/$name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | rename $old, $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return "$stock{$stockid}->{path}/$name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # Private Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub _init_stock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_stock: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my @rows = $dbi->GetQuery('hash','AllImageStock'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $stock{$_->{stockid}} = $_ for(@rows); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub _randname { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_randname: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $path =~ s/X(?=X*\z)/$CHARS[ int( rand( $#CHARS ) ) ]/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | return $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } # END Stock Control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Public Image Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | =head2 Image Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | =item GetImage($imageid) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | Retrieves the image data for a given imageid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | =item SaveImageFile(%hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | Saves an uploaded image file into the specified directory structure. If not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | save directory is specified, the draft folder is used. The hash can contain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | param - the CGI parameter used to reference the upload file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | width - maximum saved width (default = 120px) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | height - maximum saved height (default = 120px) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | imageid - if overwriting already existing file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | stock - file category (used to define the save directory) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =item MirrorImageFile($source,$stock [,$xmax,$ymax] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | Mirrors a file from a URL to the local file system. If a max width and height | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | are given, will resize the image. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | =item GetImageSize($link,$size,$width,$height,$maxwidth,$maxheight) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | For a given file, returns the true width and height that will be rendered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | within the browser, given the current and default settings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =item ResizeDimensions($dimensions,$file,$maxwidth,$maxheight) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | Given the current dimensions, file and intended max height and width, will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | return the width and height values to use in a image tag to scale the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | dimensions to the require box size. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | =item GetGravatar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | Returns a Gravatar link. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 12 | ▶ | sub GetImage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetImage: not called CC=3 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $imageid = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my @rows = $dbi->GetQuery('hash','GetImageByID',$imageid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | return() unless(@rows); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my ($x,$y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if($rows[0]->{dimensions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ($x,$y) = split("x",$rows[0]->{dimensions}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ($x,$y) = imgsize($settings{webdir}.'/'.$rows[0]->{link}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return($rows[0]->{tag},$rows[0]->{link},$rows[0]->{href},$x,$y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # stock type DRAFT should always be id 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # DRAFT images are removed during reaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub MirrorImageFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
MirrorImageFile: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my ($source,$stock,$xmax,$ymax) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $stockid = StockType($stock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my $name = basename($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $file = StockPath($stockid) . '/' . $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $target = $settings{'webdir'} . '/' . $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $mechanize = WWW::Mechanize->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $mechanize->mirror( $source, $target ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if($xmax && $ymax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$xmax and $ymax
MC/DC0%0/2
$xmax and $ymax
$xmax
$ymax
Truth table0%0/3
A and B
A= $xmaxB= $ymax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $i = Labyrinth::DIUtils->new($target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $i->reduce($xmax,$ymax); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my ($size_x,$size_y) = imgsize($target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $imageid = SaveImage( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | $name, # tag (maybe keywords) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | $file, # filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | $stockid, # stock type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | $size_x . 'x' . $size_y | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | return ($imageid,$file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub SaveImageFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveImageFile: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $param = $hash{param}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | my $xmax = $hash{width} || $settings{maxdefaultimagewidth} || MaxDefaultImageWidth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'width'} || $Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
$hash{"width"} or $Labyrinth::Media::settings{"maxdefaultimagewidth"}
MC/DC0%0/2
$hash{'width'} || $Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
$hash{"width"}
$Labyrinth::Media::settings{"maxdefaultimagewidth"}
Truth table0%0/3
A or B
A= $hash{"width"}B= $Labyrinth::Media::settings{"maxdefaultimagewidth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | my $ymax = $hash{height} || $settings{maxdefaultimageheight} || MaxDefaultImageHeight; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'height'} || $Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
$hash{"height"} or $Labyrinth::Media::settings{"maxdefaultimageheight"}
MC/DC0%0/2
$hash{'height'} || $Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
$hash{"height"}
$Labyrinth::Media::settings{"maxdefaultimageheight"}
Truth table0%0/3
A or B
A= $hash{"height"}B= $Labyrinth::Media::settings{"maxdefaultimageheight"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my $imageid = $hash{imageid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $stock = StockType($hash{stock}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | return unless($param && $cgiparams{$param}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$param and $Labyrinth::Media::cgiparams{$param}
MC/DC0%0/2
$param and $Labyrinth::Media::cgiparams{$param}
$param
$Labyrinth::Media::cgiparams{$param}
Truth table0%0/3
A and B
A= $paramB= $Labyrinth::Media::cgiparams{$param}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my ($name,$filename) = CGIFile($param,$stock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | return 1 unless($name); # blank if anything goes wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | LogDebug("reducing '$settings{webdir}/$filename' to $xmax x $ymax"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $i = Labyrinth::DIUtils->new("$settings{webdir}/$filename"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $i->reduce($xmax,$ymax); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | LogDebug("error reducing '$settings{webdir}/$filename': $@") if($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my ($size_x,$size_y) = imgsize("$settings{webdir}/$filename"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | $imageid = SaveImage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | $imageid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | $name, # tag (maybe keywords) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | $filename, # filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $stock, # stock type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $hash{href}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $size_x . 'x' . $size_y | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return ($imageid,$filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub GetImageSize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetImageSize: not called CC=28 SCAR=67.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my ($link,$size,$width,$height,$maxwidth,$maxheight) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | $maxwidth ||= $settings{maxdefaultimagewidth} || MaxDefaultImageWidth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$maxwidth ||= $Labyrinth::Media::settings{"maxdefaultimagewidth"} || 800
$Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
MC/DC0%0/2
$maxwidth ||= $Labyrinth::Media::settings{"maxdefaultimagewidth"} || 800
$maxwidth
$Labyrinth::Media::settings{'maxdefaultimagewidth'}
Truth table0%0/3
A ||= B
A= $maxwidthB= $Labyrinth::Media::settings{'maxdefaultimagewidth'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | $maxheight ||= $settings{maxdefaultimageheight} || MaxDefaultImageHeight; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$maxheight ||= $Labyrinth::Media::settings{"maxdefaultimageheight"} || 600
$Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
MC/DC0%0/2
$maxheight ||= $Labyrinth::Media::settings{"maxdefaultimageheight"} || 600
$maxheight
$Labyrinth::Media::settings{'maxdefaultimageheight'}
Truth table0%0/3
A ||= B
A= $maxheightB= $Labyrinth::Media::settings{'maxdefaultimageheight'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my ($w,$h) = $size ? split('x',$size) : (0,0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | ($w,$h) = imgsize("$settings{webdir}/$link") unless($w || $h); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w or $h
MC/DC0%0/2
$w or $h
$w
$h
Truth table0%0/3
A or B
A= $wB= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | ($width,$height) = ($w,$h) unless($width || $height); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$width or $height
MC/DC0%0/2
$width or $height
$width
$height
Truth table0%0/3
A or B
A= $widthB= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # long winded to avoid uninitialised variable errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | if(defined $width && defined $height && $width > $height && $width > $maxwidth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/9
defined $width and defined $height and $width > $height and $width > $maxwidth
defined $width and defined $height and $width > $height
defined $width and defined $height
MC/DC0%0/4
defined $width and defined $height and $width > $height and $width > $maxwidth
defined $width
defined $height
$width > $height
$width > $maxwidth
Truth table0%0/5
A and B and C and D
A= defined $widthB= defined $heightC= $width > $heightD= $width > $maxwidth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $width = $maxwidth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $height = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | ▶ | } elsif(defined $width && defined $height && $width < $height && $height > $maxheight) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
defined $width and defined $height and $width < $height and $height > $maxheight
defined $width and defined $height and $width < $height
defined $width and defined $height
MC/DC0%0/4
defined $width and defined $height and $width < $height and $height > $maxheight
defined $width
defined $height
$width < $height
$height > $maxheight
Truth table0%0/5
A and B and C and D
A= defined $widthB= defined $heightC= $width < $heightD= $height > $maxheight
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $height = $maxheight; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $width = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ▶ | } elsif(defined $width && $width > $maxwidth) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $width and $width > $maxwidth
MC/DC0%0/2
defined $width and $width > $maxwidth
defined $width
$width > $maxwidth
Truth table0%0/3
A and B
A= defined $widthB= $width > $maxwidth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $width = $maxwidth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $height = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | ▶ | } elsif(defined $height && $height > $maxheight) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $height and $height > $maxheight
MC/DC0%0/2
defined $height and $height > $maxheight
defined $height
$height > $maxheight
Truth table0%0/3
A and B
A= defined $heightB= $height > $maxheight
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $height = $maxheight; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $width = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if($width && $height) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$width and $height
MC/DC0%0/2
$width and $height
$width
$height
Truth table0%0/3
A and B
A= $widthB= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | ▶ | } elsif( $width && !$height) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$width and not $height
MC/DC0%0/2
$width and not $height
$width
not $height
Truth table0%0/3
A and not(B)
A= $widthB= not $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $height = int($h * ($width / $w)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | ▶ | } elsif(!$width && $height) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $width and $height
MC/DC0%0/2
not $width and $height
not $width
$height
Truth table0%0/3
not(A) and B
A= not $widthB= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $width = int($w * ($height / $h)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | #LogDebug("dimensions: x.($w,$h) / ($width,$height) / ($settings{webdir}/$link)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return ($width,$height); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub ResizeDimensions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ResizeDimensions: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my ($dimensions,$file,$maxwidth,$maxheight) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $toobig = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my ($x,$y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if($tvars{data}->{dimensions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ($x,$y) = split("x",$tvars{data}->{dimensions}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | ($x,$y) = imgsize($file) if(-f $file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | return unless($x && $y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$x and $y
MC/DC0%0/2
$x and $y
$x
$y
Truth table0%0/3
A and B
A= $xB= $y
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | return ($x,$y,$toobig) unless($maxwidth && $maxheight); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$maxwidth and $maxheight
MC/DC0%0/2
$maxwidth and $maxheight
$maxwidth
$maxheight
Truth table0%0/3
A and B
A= $maxwidthB= $maxheight
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | return ($x,$y,$toobig) if($x <= $maxwidth && $y <= $maxheight); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$x <= $maxwidth and $y <= $maxheight
MC/DC0%0/2
$x <= $maxwidth and $y <= $maxheight
$x <= $maxwidth
$y <= $maxheight
Truth table0%0/3
A and B
A= $x <= $maxwidthB= $y <= $maxheight
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $toobig = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | my $xr = $maxwidth ? $maxwidth / $x : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | my $yr = $maxheight ? $maxheight / $y : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if($xr <= $yr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $x *= $xr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $y *= $xr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $x *= $yr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $y *= $yr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | return (int($x),int($y),$toobig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | sub GetGravatar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetGravatar: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my ($id,$email) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $nophoto = uri_escape($settings{nophoto}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | return $nophoto unless($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | my $user = GetUser($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | return $nophoto unless($user); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | 'http://www.gravatar.com/avatar.php?' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | .'gravatar_id='.md5_hex($email) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | .'&default='.$nophoto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | .'&size=80'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | =head2 Image Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | =item CopyPhotoFile() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | Copy an existing stored image, both on the filesystem and in the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | =item SavePhotoFile() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | Save a photo uploaded via a web form to the local filesystem and to the photo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | gallery database table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | sub CopyPhotoFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CopyPhotoFile: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my $photo = $hash{photo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | my $xmax = $hash{width} || $settings{maxdefaultimagewidth} || MaxDefaultImageWidth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'width'} || $Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
$hash{"width"} or $Labyrinth::Media::settings{"maxdefaultimagewidth"}
MC/DC0%0/2
$hash{'width'} || $Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
$hash{"width"}
$Labyrinth::Media::settings{"maxdefaultimagewidth"}
Truth table0%0/3
A or B
A= $hash{"width"}B= $Labyrinth::Media::settings{"maxdefaultimagewidth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | my $ymax = $hash{height} || $settings{maxdefaultimageheight} || MaxDefaultImageHeight; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'height'} || $Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
$hash{"height"} or $Labyrinth::Media::settings{"maxdefaultimageheight"}
MC/DC0%0/2
$hash{'height'} || $Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
$hash{"height"}
$Labyrinth::Media::settings{"maxdefaultimageheight"}
Truth table0%0/3
A or B
A= $hash{"height"}B= $Labyrinth::Media::settings{"maxdefaultimageheight"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $stock = StockType($hash{stock}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | return unless($photo); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my @rs = $dbi->GetQuery('hash','GetPhotoDetail',$photo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $name = basename($rs[0]->{image}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | return 1 unless($name); # blank if anything goes wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my $source = "$settings{webdir}/photos/$rs[0]->{image}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my $target = "$settings{webdir}/images/draft/$name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | copy($source,$target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $i = Labyrinth::DIUtils->new($target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $i->reduce($xmax,$ymax); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my ($size_x,$size_y) = imgsize($target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $target =~ s!$settings{webdir}/!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | my $imageid = SaveImage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | $name, # tag (maybe keywords) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | $target, # filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | $stock, # stock type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | $hash{href}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $size_x . 'x' . $size_y | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return ($imageid,$target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | sub SavePhotoFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SavePhotoFile: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | my $param = $hash{param} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'param'} || (return)
MC/DC0%0/1
$hash{'param'} || (return)
$hash{'param'}
Truth table0%0/2
A
A= $hash{'param'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | my $path = $hash{path} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'path'} || (return)
MC/DC0%0/1
$hash{'path'} || (return)
$hash{'path'}
Truth table0%0/2
A
A= $hash{'path'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | my $page = $hash{page} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'page'} || (return)
MC/DC0%0/1
$hash{'page'} || (return)
$hash{'page'}
Truth table0%0/2
A
A= $hash{'page'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | my $iwidth = $hash{iwidth} || $settings{maxdefaultimagewidth} || MaxDefaultImageWidth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'iwidth'} || $Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
$hash{"iwidth"} or $Labyrinth::Media::settings{"maxdefaultimagewidth"}
MC/DC0%0/2
$hash{'iwidth'} || $Labyrinth::Media::settings{'maxdefaultimagewidth'} || 800
$hash{"iwidth"}
$Labyrinth::Media::settings{"maxdefaultimagewidth"}
Truth table0%0/3
A or B
A= $hash{"iwidth"}B= $Labyrinth::Media::settings{"maxdefaultimagewidth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | my $iheight = $hash{iheight} || $settings{maxdefaultimageheight} || MaxDefaultImageHeight; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'iheight'} || $Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
$hash{"iheight"} or $Labyrinth::Media::settings{"maxdefaultimageheight"}
MC/DC0%0/2
$hash{'iheight'} || $Labyrinth::Media::settings{'maxdefaultimageheight'} || 600
$hash{"iheight"}
$Labyrinth::Media::settings{"maxdefaultimageheight"}
Truth table0%0/3
A or B
A= $hash{"iheight"}B= $Labyrinth::Media::settings{"maxdefaultimageheight"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | my $twidth = $hash{twidth} || $settings{maxdefaultthumbwidth} || MaxDefaultThumbWidth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'twidth'} || $Labyrinth::Media::settings{'maxdefaultthumbwidth'} || 200
$hash{"twidth"} or $Labyrinth::Media::settings{"maxdefaultthumbwidth"}
MC/DC0%0/2
$hash{'twidth'} || $Labyrinth::Media::settings{'maxdefaultthumbwidth'} || 200
$hash{"twidth"}
$Labyrinth::Media::settings{"maxdefaultthumbwidth"}
Truth table0%0/3
A or B
A= $hash{"twidth"}B= $Labyrinth::Media::settings{"maxdefaultthumbwidth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | my $theight = $hash{theight} || $settings{maxdefaultthumbheight} || MaxDefaultThumbHeight; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$hash{'theight'} || $Labyrinth::Media::settings{'maxdefaultthumbheight'} || 200
$hash{"theight"} or $Labyrinth::Media::settings{"maxdefaultthumbheight"}
MC/DC0%0/2
$hash{'theight'} || $Labyrinth::Media::settings{'maxdefaultthumbheight'} || 200
$hash{"theight"}
$Labyrinth::Media::settings{"maxdefaultthumbheight"}
Truth table0%0/3
A or B
A= $hash{"theight"}B= $Labyrinth::Media::settings{"maxdefaultthumbheight"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | my $order = $hash{order} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'order'} || 1
MC/DC0%0/1
$hash{'order'} || 1
$hash{'order'}
Truth table0%0/2
A
A= $hash{'order'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $tag = $hash{tag}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | my $stock = StockType($hash{stock}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | return unless($cgiparams{$param}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my ($name,$filename,$extn) = CGIFile($param,$stock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | return 1 unless($name); # blank if anything goes wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | $tag = $name unless(defined $tag); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | my $file = lc($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | $file =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my $source = "$settings{webdir}/$filename"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my $target = "$settings{webdir}/$path/$file$extn"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | copy($source,$target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | $source = "$settings{webdir}/$path/$file$extn"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $target = "$settings{webdir}/$path/$file-thumb$extn"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | copy($source,$target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | LogDebug("reducing '$source' to $iwidth x $iheight"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $i = Labyrinth::DIUtils->new($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $i->reduce($iwidth,$iheight); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | LogDebug("reducing '$target' to $twidth x $theight"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my $t = Labyrinth::DIUtils->new($target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $t->reduce($twidth,$theight); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my ($size_x,$size_y) = imgsize($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $source =~ s!$settings{webdir}/(photos/)?!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $target =~ s!$settings{webdir}/(photos/)?!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $photoid = $dbi->IDQuery('SavePhoto',$page,$target,$source,$size_x.'x'.$size_y,$tag,$order); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | MetaSave($photoid,['Photo'],split(/[ ,]+/,$name)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | return ($photoid,$name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | =head2 Media Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | =item GetMedia($imageid) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | Retrieves the media data for a given imageid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | =item SaveMediaFile(%hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | Saves an uploaded media file into the specified directory structure. If no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | save directory is specified, the draft folder is used. The hash can contain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | param - the CGI parameter used to reference the upload file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | imageid - if overwriting already existing file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | stock - file category (used to define the save directory) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | sub GetMedia { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetMedia: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my $imageid = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | my @rows = $dbi->GetQuery('hash','GetImageByID',$imageid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | return() unless(@rows); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | return($rows[0]->{tag},$rows[0]->{link},$rows[0]->{href}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # stock type DRAFT should always be id 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # DRAFT images are removed during reaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | sub SaveMediaFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveMediaFile: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | my $param = $hash{param}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | my $imageid = $hash{imageid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | my $stock = StockType($hash{stock}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | return unless($param && $cgiparams{$param}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$param and $Labyrinth::Media::cgiparams{$param}
MC/DC0%0/2
$param and $Labyrinth::Media::cgiparams{$param}
$param
$Labyrinth::Media::cgiparams{$param}
Truth table0%0/3
A and B
A= $paramB= $Labyrinth::Media::cgiparams{$param}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | my ($name,$filename) = CGIFile($param,$stock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | return 1 unless($name); # blank if anything goes wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | $imageid = SaveImage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | $imageid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | $name, # tag (maybe keywords) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | $filename, # filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | $stock, # stock type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | $hash{href}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | '' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | return ($imageid,$filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | =item SaveFile(%hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | Saves an uploaded media file into the specified directory structure. If no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | save directory is specified, the draft folder is used. The hash can contain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | param - the CGI parameter used to reference the upload file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | stock - file category (used to define the save directory) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | Note that this upload function assumes that the file is to be stored in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | appropriate directory with a link being return. No imageid or further reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | is held within the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | ▶ | sub SaveFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveFile: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | my $param = $hash{param}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my $stock = StockType($hash{stock}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | return unless($param && $cgiparams{$param}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$param and $Labyrinth::Media::cgiparams{$param}
MC/DC0%0/2
$param and $Labyrinth::Media::cgiparams{$param}
$param
$Labyrinth::Media::cgiparams{$param}
Truth table0%0/3
A and B
A= $paramB= $Labyrinth::Media::cgiparams{$param}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | my ($name,$filename) = CGIFile($param,$stock,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | return unless($name); # undef if anything goes wrong | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | return $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | =item DeleteFile(%hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | Deletes a previously uploaded media file from disk. No attempt is made to check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | whether file is used within the database, other checks should be used prior to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | calling this function if this is required. The hash can contain the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | file - file to be deleted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | sub DeleteFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my $file = $hash{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | unlink $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | =head1 ADMIN INTERFACE FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | =item ImageCheck | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | Used by Images::Delete to verify whether a particular module uses a particular | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | image referenced in the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | sub ImageCheck { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ImageCheck: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my $imageid = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | foreach my $plugin (get_plugins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | return 1 if( $plugin->ImageCheck($imageid) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | =head1 LOCAL INTERNAL FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | =item SaveImage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | Writes image data to the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | sub SaveImage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveImage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | my ($imageid,@fields) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | if($imageid) { $dbi->DoQuery('SaveImage',@fields,$imageid); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | else { $imageid = $dbi->IDQuery('AddImage',@fields); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | return $imageid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | =item UnZipFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | Un wraps an archive file and stores it in an appropriate directory. For a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | single file archive, the path to the file is returned. For collecions of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | files, an 'index.html' is searched for and the path to it returned if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | found. In all other instances the either the path to the first HTML file or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | first other file is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | sub UnZipFile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
UnZipFile: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | return unless($file =~ /(.*)\.(zip|tar|tar\.gz|tgz)$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | my $path = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | return unless($path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # extract in to path directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # note ONLY ONE extraction allowed, in case zip of death uploaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | my $ae = Archive::Extract->new( archive => "$settings{webdir}/$file" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | my $ok = $ae->extract( to => "$settings{webdir}/$path" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | unless($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | LogError("UnZip failure: file=[$file], path=[$path], error: ".$ae->error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | rmtree("$settings{webdir}/$path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | unlink("$settings{webdir}/$file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | my @files = map {my $x = $_; $x =~ s!$settings{webdir}/!!; $x} File::Find::Rule->file()->name('*')->in("$settings{webdir}/$path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | ▶ | unless(@files > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | LogError("UnZip failure: file=[$file], path=[$path], error: No files in archive."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | rmtree("$settings{webdir}/$path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | unlink("$settings{webdir}/$file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # return file if count == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | return $files[0] if(@files == 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # return index.html if found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | my @html = grep {/^index.html?$/} @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | return $html[0] if(@html); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # return first html file if found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | @html = grep {/\.html?$/} @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | return $html[0] if(@html); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | # return first file found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | return $files[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||