Toader/Render/Gallery.pm

filter: Statementstmt 93.9% 31 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 95.4% 42 / 44 CC 1 SCAR 0.3
CC
1
Cov
94%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Toader/Render/supportedObjects.pm ↑ Summary
1 package Toader::Render::Gallery;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Toader::Render::General;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Toader::Templates;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Date::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Toader::pathHelper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Path qw(make_path mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 0 ▶use GD::Thumbnail;
Subroutine BEGIN: called CC=1 SCAR=2.6
14  
15 =head1 NAME
16  
17 Toader::Render::Gallery - This renders a Toader::Gallery object.
18  
19 =head1 VERSION
20  
21 Version 0.1.0
22  
23 =cut
24  
25 our $VERSION = '0.1.0';
26  
27 =head1 SYNOPSIS
28  
29 =head1 METHODS
30  
31 =head2 new
32  
33 This initiates the object.
34  
35 =head3 args hash ref
36  
37 =head4 obj
38  
39 This is the L<Toader::Gallery> object to render.
40  
41 =head4 toader
42  
43 This is the L<Toader> object to use.
44  
45 my $foo=Toader::Render::Gallery->new(\%args);
46 if($foo->error){
47 warn('error: '.$foo->error.":".$foo->errorString);
48 }
49  
50 =cut
51  
52 sub new{
53 my %args;
54 if(defined($_[1])){
55 %args= %{$_[1]};
56 };
57  
58 my $self={
59 error=>undef,
60 errorString=>'',
61 perror=>undef,
62 toDir=>'../',
63 errorExtra=>{
64 flags=>{
65 1=>'noObj',
66 2=>'noToaderObj',
67 3=>'objPerror',
68 4=>'toaderPerror',
69 5=>'noDirSet',
70 6=>'pathhelperInitErroered',
71 7=>'realative2rootErrored',
72 9=>'notUnderSrcPath',
73 10=>'dirStartsWithPeriod',
74 11=>'srcPathDoesNotExist',
75 12=>'outputDirDoesNotExist',
76 13=>'srcDirOpenFailed',
77 14=>'smallThumbFileOpenFailed',
78 15=>'smallThumbPathCreationFailed',
79 16=>'largeThumbPathCreationFailed',
80 17=>'generalInitErrored',
81 18=>'renderTemplateErrored',
82 19=>'pathCreationFailed',
83 20=>'pathCleanupFailed',
84 },
85 },
86 };
87 bless $self;
88  
89 if ( defined( $args{toDir} ) ){
90 $self->{toDir}=$args{toDir};
91 }
92  
93 #make sure we have a Toader::Gallery object.
94 if ( ! defined( $args{obj} ) ){
95 $self->{perror}=1;
96 $self->{error}=1;
97 $self->{errorString}='Nothing defined for the Toader::Gallery object';
98 $self->warn;
99 return $self;
100 }
101 if ( ref( $args{obj} ) ne 'Toader::Gallery' ){
102 $self->{perror}=1;
103 $self->{error}=1;
104 $self->{errorString}='The specified object is not a Toader::Gallery object, but a "'.
105 ref( $args{obj} ).'"';
106 $self->warn;
107 return $self;
108 }
109 $self->{obj}=$args{obj};
110  
111 #make sure the object does not have a permanent error set
112 if( ! $self->{obj}->errorblank ){
113 $self->{perror}=1;
114 $self->{error}=3;
115 $self->{errorString}='The Toader::Gallery object has a permanent error set';
116 $self->warn;
117 return $self;
118 }
119  
120 #make sure a Toader object is given
121 if ( ! defined( $args{toader} ) ){
122 $self->{perror}=1;
123 $self->{error}=2;
124 $self->{errorString}='Nothing defined for the Toader object';
125 $self->warn;
126 return $self;
127 }
128 if ( ref( $args{toader} ) ne 'Toader' ){
129 $self->{perror}=1;
130 $self->{error}=2;
131 $self->{errorString}='The specified object is not a Toader object, but a "'.
132 ref( $args{toader} ).'"';
133 $self->warn;
134 return $self;
135 }
136 $self->{toader}=$args{toader};
137  
138 #make sure the object does not have a permanent error set
139 if( ! $self->{toader}->errorblank ){
140 $self->{perror}=1;
141 $self->{error}=4;
142 $self->{errorString}='The Toader object has a permanent error set';
143 $self->warn;
144 return $self;
145 }
146  
147 #make sure a directory is set
148 if( ! defined( $self->{obj}->dirGet ) ){
149 $self->{perror}=1;
150 $self->{error}=5;
151 $self->{errorString}='The Toader::Gallery object does not have a directory set';
152 $self->warn;
153 return $self;
154 }
155 $self->{dir}=$self->{obj}->dirGet;
156  
157 #initialize this here for simplicity
158 $self->{t}=Toader::Templates->new({ dir=>$self->{obj}->dirGet });
159  
160 #initialize the general object here for simplicity
161 $self->{g}=Toader::Render::General->new(
162 {
163 toader=>$self->{toader},
164 self=>\$self,
165 obj=>$self->{obj},
166 fullURL=>1,
167 url=>$self->{obj}->outputURLget,
168 }
169 );
170 if ( $self->{g}->error ){
171 $self->{perror}=1;
172 $self->{error}=17;
173 $self->{errorString}='Failed to initialize Toader::Render::General';
174 $self->warn;
175 return undef;
176 }
177  
178 #initialize the Toader::pathHelper
179 $self->{ph}=Toader::pathHelper->new( $self->{dir} );
180 if ( $self->{ph}->error ){
181 $self->{perror}=1;
182 $self->{error}=6;
183 $self->{errorString}='Failed to initiate pathHelper. error="'.
184 $self->{ph}->error.'" errorString="'.$self->{ph}->errorString.'"';
185 $self->warn;
186 return $self;
187 }
188  
189 #gets the r2r for the object
190 $self->{r2r}=$self->{ph}->relative2root( $self->{dir} );
191 if ( $self->{ph}->error ){
192 $self->{perror}=1;
193 $self->{error}=7;
194 $self->{errorString}='pathHelper failed to find the relative2root path for "'.
195 $self->{odir}.'"';
196 $self->warn;
197 return $self;
198 }
199  
200 return $self;
201 }
202  
203 =head2 render
204  
205 This is just here for compatibiltiy reasons. It returns true.
206  
207 =cut
208  
209 sub render{
210 my $self=$_[0];
211
212 if ( ! $self->errorblank ){
213 return undef;
214 }
215  
216 my $updateIndexes=$self->{obj}->renderUpdateIndexesGet;
217 my $updateScaled=$self->{obj}->renderUpdateScaledGet;
218 my $updateDetails=$self->{obj}->renderUpdateDetailsGet;
219  
220 if ( $updateIndexes ){
221 $self->updateIndex;
222 if ( $self->error ){
223 $self->warnString('Failed to update indexes');
224 return undef;
225 }
226 }
227  
228 if ( $updateScaled ){
229 $self->updateScaled;
230 if ( $self->error ){
231 $self->warnString('Failed to update scaled images');
232 return undef;
233 }
234 }
235  
236 if ( $updateDetails ){
237 $self->updateDetails;
238 if ( $self->error ){
239 $self->warnString('Failed to update details');
240 return undef;
241 }
242 }
243  
244 return 1;
245 }
246  
247 =head2 updateDetails
248  
249 =cut
250  
251 sub updateDetails{
252 my $self=$_[0];
253  
254 #make sure we are error clean
255 if ( ! $self->errorblank ){
256 return undef;
257 }
258
259 #gets the various paths
260 my $srcPath=$self->{obj}->srcPathGet;
261 my $outputPath=$self->{obj}->outputPathGet;
262
263 #make sure it does not have multiple //
264 $srcPath=$srcPath.'/';
265 $srcPath=~s/\/*\//\//g;
266  
267 #gets the relative path from the source directory
268 my $regexp='^'.quotemeta( $srcPath );
269  
270 #make sure the source directory exists
271 if ( ! -d $srcPath ){
272 $self->{error}=11;
273 $self->{errorString}='The source directory,"'.$srcPath.'", does not exist';
274 $self->warn;
275 return undef;
276 }
277 #make sure the output directory exists
278 if ( ! -d $outputPath ){
279 $self->{error}=12;
280 $self->{errorString}='The output directory,"'.$outputPath.'", does not exist';
281 $self->warn;
282 return undef;
283 }
284  
285 #finds the images and directories
286 my %found;
287 find(sub{
288 #makes sure that it is not a hiddten item
289 if (
290 ( $File::Find::name !~ /\/\./ ) &&
291 ( -f $File::Find::name ) &&
292 (
293 ( $File::Find::name =~ /jpg$/i ) ||
294 ( $File::Find::name =~ /jpeg$/i ) ||
295 ( $File::Find::name =~ /png$/i ) ||
296 ( $File::Find::name =~ /gif$/i )
297 )
298 ){
299
300 if ( ! defined( $found{$File::Find::dir} ) ){
301 $found{$File::Find::dir}={};
302  
303 $found{$File::Find::dir}{'images'}=[];
304  
305 $found{$File::Find::dir}{'gdir'}=$File::Find::dir;
306 $found{$File::Find::dir}{'gdir'}=~s/$regexp//;
307
308 $found{$File::Find::dir}{'outputDir'}=$outputPath.'/.toader-gallery/html/'.$found{$File::Find::dir}{'gdir'};
309  
310 $found{$File::Find::dir}{'outputDir'}=~s/\/\/*/\//g;
311  
312 }
313  
314 push( @{ $found{$File::Find::dir}{'images'} }, $_ );
315  
316 };
317 }
318 , $srcPath);
319 my @dirs=keys( %found );
320  
321 #make sure all the directories exist
322 my $int=0;
323 while( defined( $dirs[$int] ) ){
324 if ( ! -e $found{ $dirs[$int] }{'outputDir'} ){
325 if ( ! mkpath( $found{ $dirs[$int] }{'outputDir'} )
326 ){
327 $self->{error}=19;
328 $self->{errorString}='Failed to create the output directory "'.
329 $found{ $dirs[$int] }{'outputDir'}.'"';
330 $self->warn;
331 return undef;
332 }
333 }
334
335 $int++;
336 }
337  
338 #process each image listed in the directory
339 $int=0;
340 while( defined( $dirs[$int] ) ){
341 my $gdir=$found{ $dirs[$int] }{'gdir'};
342  
343 #process each image
344 my $imageInt=0;
345 my $image;
346 while( defined( $found{ $dirs[$int] }{'images'}[$imageInt] ) ){
347  
348 $image=$found{ $dirs[$int] }{'images'}[$imageInt];
349  
350 my $content=$self->{g}->galleryImageLarge( undef, $gdir, $image );
351 if ( $self->{g}->error ){
352 $self->{error}=21;
353 $self->{errorString}='Failed to render the HTML for a description of "'.$gdir.'/'.$image.'"';
354 $self->warn;
355 return undef;
356 }
357  
358 $self->{g}->locationSubSet( $self->{g}->galleryLocationbar( $gdir, $image ) );
359
360 my $rendered=$self->{t}->fill_in(
361 'pageGallery',
362 {
363 obj=>\$self->{obj},
364 c=>\$self->{toader}->getConfig,
365 self=>\$self,
366 toader=>\$self->{toader},
367 g=>\$self->{g},
368 dir=>$self->{r2r},
369 gdir=>$gdir,
370 image=>$image,
371 content=>$content,
372 }
373 );
374 if ( $self->{t}->error ){
375 $self->{error}=18;
376 $self->{errorString}='Failed to fill in the template. error="'.
377 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
378 $self->warn;
379 return undef;
380 }
381
382 my $detailFile=$outputPath.'/.toader-gallery/html/'.$gdir.'/'.$image.'.html';
383
384 my $fh;
385 if ( ! open( $fh, '>', $detailFile ) ){
386 $self->{error}=19;
387 $self->{errorString}='Failed to open "'.$detailFile.'" for writing';
388 $self->warn;
389 return undef;
390 }
391 print $fh $rendered;
392 close $fh;
393  
394 $imageInt++;
395 }
396
397 $int++;
398 }
399  
400 return 1;
401 }
402  
403 =head2 updateIndexes
404  
405 This updates the index.html file for a gallery directory.
406  
407 Two arguments are taken. The first and required is the directory
408 act upon. The second and optional is if it should be recursive or
409 not, which defaults to false.
410  
411 =cut
412  
413 sub updateIndexes{
414 my $self=$_[0];
415 my $dir=$_[1];
416 my $recursive=$_[2];
417  
418 #make sure we are error clean
419 if ( ! $self->errorblank ){
420 return undef;
421 }
422  
423 #gets the various paths
424 my $srcPath=$self->{obj}->srcPathGet;
425 my $outputPath=$self->{obj}->outputPathGet;
426
427 #default to the source directory if none is specified
428 if ( ! defined( $dir ) ){
429 $dir=$srcPath;
430 }
431  
432 #make sure the directory is not hidden any place in the path
433 if ( $dir =~ /\/\./ ){
434 $self->{eror}=10;
435 $self->{errorString}='The specified directory,"'.$dir.'", contains a directory that starts with a period';
436 $self->warn;
437 return undef;
438 }
439
440 #make sure all end in / and don't have any multiple //
441 $dir=$dir.'/';
442 $dir=~s/\/*\//\//g;
443 $srcPath=$srcPath.'/';
444 $srcPath=~s/\/*\//\//g;
445  
446 #make sure that the directory is under/is the source directory
447 my $regexp='^'.quotemeta( $srcPath );
448 if ( $dir !~ /$regexp/ ){
449 $self->{error}=9;
450 $self->{errorString}='"'.$dir.'" is not under "'.$srcPath.'"';
451 $self->warn;
452 return undef;
453 }
454  
455 #gets the relative path from the source directory
456 my $relative=$dir;
457 $relative=~s/$regexp//g;
458  
459 #make sure the source directory exists
460 if ( ! -d $dir ){
461 $self->{error}=11;
462 $self->{errorString}='The source directory,"'.$dir.'", does not exist';
463 $self->warn;
464 return undef;
465 }
466 #make sure the output directory exists
467 if ( ! -d $outputPath ){
468 $self->{error}=12;
469 $self->{errorString}='The output directory,"'.$outputPath.'", does not exist';
470 $self->warn;
471 return undef;
472 }
473
474 #opens the directory and reads everything not starting with a period
475 my $dh;
476 if ( ! opendir( $dh, $dir ) ){
477 $self->{error}=13;
478 $self->{errorString}='Failed to open the source directory';
479 $self->warn;
480 return undef;
481 }
482 my @dirList=grep( !/^\./, readdir($dh) );
483 closedir( $dh );
484  
485 @dirList=sort( @dirList );
486  
487 #process each item in listed in the directory
488 my $int=0;
489 my @smallDivs;
490 my @dirDivs;
491 while( defined( $dirList[$int] ) ){
492 my $path=$dir.$dirList[$int];
493  
494 #if it is a directory, process it if we are doing it recursively
495 if ( -d $path &&
496 $recursive
497 ){
498 $self->updateIndexes( $path, 1 );
499  
500 my $link=$self->{g}->galleryLink( undef, $relative.'/'.$dirList[$int], $dirList[$int].'/');
501
502 my $rendered=$self->{t}->fill_in(
503 'galleryDir',
504 {
505 obj=>\$self->{obj},
506 c=>\$self->{toader}->getConfig,
507 self=>\$self,
508 toader=>\$self->{toader},
509 g=>\$self->{g},
510 dir=>$self->{r2r},
511 gdir=>$relative.'/'.$dirList[$int],
512 link=>$link,
513 }
514 );
515 if ( $self->{t}->error ){
516 $self->{error}=18;
517 $self->{errorString}='Failed to fill in the template. error="'.
518 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
519 $self->warn;
520 return undef;
521 }
522
523 push( @dirDivs, $rendered );
524 }
525 #scale it if it is a image
526 if (
527 ( -f $path ) &&
528 (
529 ( $path =~ /[Jj][Pp][Gg]$/ ) ||
530 ( $path =~ /[Jj][Pp][Ee][Gg]$/ ) ||
531 ( $path =~ /[Pp][Nn][Gg]$/ ) ||
532 ( $path =~ /[Gg][Ii][Ff]$/ )
533 )
534 ){
535
536 my $rendered=$self->{t}->fill_in(
537 'gallerySmallImage',
538 {
539 obj=>\$self->{obj},
540 c=>\$self->{toader}->getConfig,
541 self=>\$self,
542 toader=>\$self->{toader},
543 g=>\$self->{g},
544 dir=>$self->{r2r},
545 gdir=>$relative,
546 image=>$dirList[$int],
547 }
548 );
549 if ( $self->{t}->error ){
550 $self->{error}=18;
551 $self->{errorString}='Failed to fill in the template. error="'.
552 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
553 $self->warn;
554 return undef;
555 }
556 push( @smallDivs, $rendered );
557 }
558
559 $int++;
560 }
561  
562 my $begin=$self->{t}->fill_in(
563 'gallerySmallImageBegin',
564 {
565 obj=>\$self->{obj},
566 c=>\$self->{toader}->getConfig,
567 self=>\$self,
568 toader=>\$self->{toader},
569 g=>\$self->{g},
570 dir=>$self->{r2r},
571 gdir=>$relative,
572 }
573 );
574 if ( $self->{t}->error ){
575 $self->{error}=18;
576 $self->{errorString}='Failed to fill in the template. error="'.
577 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
578 $self->warn;
579 return undef;
580 }
581  
582 my $join=$self->{t}->fill_in(
583 'gallerySmallImageJoin',
584 {
585 obj=>\$self->{obj},
586 c=>\$self->{toader}->getConfig,
587 self=>\$self,
588 toader=>\$self->{toader},
589 g=>\$self->{g},
590 dir=>$self->{r2r},
591 gdir=>$relative,
592 }
593 );
594 if ( $self->{t}->error ){
595 $self->{error}=18;
596 $self->{errorString}='Failed to fill in the template. error="'.
597 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
598 $self->warn;
599 return undef;
600 }
601  
602 my $end=$self->{t}->fill_in(
603 'gallerySmallImageEnd',
604 {
605 obj=>\$self->{obj},
606 c=>\$self->{toader}->getConfig,
607 self=>\$self,
608 toader=>\$self->{toader},
609 g=>\$self->{g},
610 dir=>$self->{r2r},
611 gdir=>$relative,
612 }
613 );
614 if ( $self->{t}->error ){
615 $self->{error}=18;
616 $self->{errorString}='Failed to fill in the template. error="'.
617 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
618 $self->warn;
619 return undef;
620 }
621  
622
623 my $content=$begin.join( $join, @dirDivs ).$join.join( $join, @smallDivs ).$end;
624  
625 $self->{g}->locationSubSet( $self->{g}->galleryLocationbar( $relative ) );
626  
627 my $page=$self->{t}->fill_in(
628 'pageGallery',
629 {
630 obj=>\$self->{obj},
631 c=>\$self->{toader}->getConfig,
632 self=>\$self,
633 toader=>\$self->{toader},
634 g=>\$self->{g},
635 dir=>$self->{r2r},
636 gdir=>$relative,
637 content=>$content,
638 }
639 );
640 if ( $self->{t}->error ){
641 $self->{error}=18;
642 $self->{errorString}='Failed to fill in the template. error="'.
643 $self->{t}->error.'" errorString="'.$self->{t}->errorString.'"';
644 $self->warn;
645 return undef;
646 }
647  
648 my $indexDir=$outputPath.'/.toader-gallery/html/'.$relative;
649 my $indexFile=$indexDir.'/index.html';
650 my $indexFile2=$outputPath.'/index.html';
651  
652 if ( ! -d $indexDir ){
653 if ( ! mkpath( $indexDir ) ){
654 $self->{error}=19;
655 $self->{errorString}='Failed to create the path, "'.$indexDir.'", for the index.html file';
656 $self->warn;
657 return undef;
658 }
659 }
660
661 my $fh;
662 if ( ! open( $fh, '>', $indexFile ) ){
663 $self->{error}=19;
664 $self->{errorString}='Failed to open "'.$indexFile.'" for writing';
665 $self->warn;
666 return undef;
667 }
668 print $fh $page;
669 close $fh;
670  
671 $fh=undef;
672 if ( ! open( $fh, '>', $indexFile2 ) ){
673 $self->{error}=19;
674 $self->{errorString}='Failed to open "'.$indexFile2.'" for writing';
675 $self->warn;
676 return undef;
677 }
678 print $fh $page;
679 close $fh;
680  
681 return 1;
682 }
683  
684 =head2 updateScaled
685  
686 This updates scaled images. If a scaled image is found to
687 already exist, it does not rerocess it.
688  
689 Two arguments are taken. The first and required is the directory
690 act upon. The second and optional is if it should be recursive or
691 not, which defaults to false.
692  
693 =cut
694  
695 sub updateScaled{
696 my $self=$_[0];
697 my $dir=$_[1];
698 my $recursive=$_[2];
699  
700 #make sure we are error clean
701 if ( ! $self->errorblank ){
702 return undef;
703 }
704
705 #gets the various paths
706 my $srcPath=$self->{obj}->srcPathGet;
707 my $outputPath=$self->{obj}->outputPathGet;
708 my $smallRes=$self->{obj}->resolutionSmallGet;
709 my $largeRes=$self->{obj}->resolutionLargeGet;
710  
711 #default to the source directory if none is specified
712 if ( ! defined( $dir ) ){
713 $dir=$srcPath;
714 }
715  
716 #make sure the directory is not hidden any place in the path
717 if ( $dir =~ /\/\./ ){
718 $self->{eror}=10;
719 $self->{errorString}='The specified directory,"'.$dir.'", contains a directory that starts with a period';
720 $self->warn;
721 return undef;
722 }
723  
724 #make sure all end in / and don't have any multiple //
725 $dir=$dir.'/';
726 $dir=~s/\/*\//\//g;
727 $srcPath=$srcPath.'/';
728 $srcPath=~s/\/*\//\//g;
729  
730 #make sure that the directory is under/is the source directory
731 my $regexp='^'.quotemeta( $srcPath );
732 if ( $dir !~ /$regexp/ ){
733 $self->{error}=9;
734 $self->{errorString}='"'.$dir.'" is not under "'.$srcPath.'"';
735 $self->warn;
736 return undef;
737 }
738  
739 #gets the relative path from the source directory
740 my $relative=$dir;
741 $relative=~s/$regexp//g;
742  
743 #make sure the source directory exists
744 if ( ! -d $dir ){
745 $self->{error}=11;
746 $self->{errorString}='The source directory,"'.$dir.'", does not exist';
747 $self->warn;
748 return undef;
749 }
750  
751 #make sure the output directory exists
752 if ( ! -d $outputPath ){
753 $self->{error}=12;
754 $self->{errorString}='The output directory,"'.$outputPath.'", does not exist';
755 $self->warn;
756 return undef;
757 }
758  
759 #opens the directory and reads everything not starting with a period
760 my $dh;
761 if ( ! opendir( $dh, $dir ) ){
762 $self->{error}=13;
763 $self->{errorString}='Failed to open the source directory';
764 $self->warn;
765 return undef;
766 }
767 my @dirList=grep( !/^\./, readdir($dh) );
768 closedir( $dh );
769  
770 #process each item in listed in the directory
771 my $int=0;
772 while( defined( $dirList[$int] ) ){
773 my $path=$dir.$dirList[$int];
774
775 #if it is a directory, process it if we are doing it recursively
776 if ( -d $path &&
777 $recursive
778 ){
779 $self->updateScaled( $path, 1 );
780 }
781 #scale it if it is a image
782 if ( -f $path ){
783 if (
784 ( $path =~ /[Jj][Pp][Gg]$/ ) ||
785 ( $path =~ /[Jj][Pp][Ee][Gg]$/ ) ||
786 ( $path =~ /[Pp][Nn][Gg]$/ ) ||
787 ( $path =~ /[Gg][Ii][Ff]$/ )
788 ){
789 my $newpathSmall=$outputPath.'/.toader-gallery/small/'.$relative;
790 my $newpathLarge=$outputPath.'/.toader-gallery/large/'.$relative;
791 my $smallFile=$newpathSmall.'/'.$dirList[$int];
792 my $largeFile=$newpathLarge.'/'.$dirList[$int];
793
794 #the thumbnailing object
795 my $thumb = GD::Thumbnail->new;
796
797 if ( ! -d $newpathSmall ){
798 if ( ! mkpath( $newpathSmall ) ){
799 $self->{error}=15;
800 $self->{errorString}='Failed to create the path for the small thumbnails';
801 $self->warn;
802 return undef;
803 }
804 }
805
806 if ( ! -d $newpathLarge ){
807 if ( ! mkpath( $newpathLarge ) ){
808 $self->{error}=16;
809 $self->{errorString}='Failed to create the path for the large thumbnails';
810 $self->warn;
811 return undef;
812 }
813 }
814
815 #creates the small thumbnail
816 my $smallImage;
817 #GD::Thumbnail will bail out if it does not like something... so eval it to prevent that...
818 my $toeval='$smallImage=$thumb->create($dir."/".$dirList[$int], $smallRes);';
819 eval( $toeval );
820 if ( defined( $smallImage ) ){
821 my $fh;
822 if ( ! open( $fh, '>', $smallFile ) ){
823 $self->{error}=14;
824 $self->{errorString}='Failed to open "'.$smallFile.'" for writing';
825 $self->warn;
826 return undef;
827 }
828 print $fh $smallImage;
829 close $fh;
830 }else{
831 $self->warnString('Failed to create the small thumbnail for "'.$path.'"');
832 }
833
834 #creates the large thumbnail
835 my $largeImage;
836 #GD::Thumbnail will bail out if it does not like something... so eval it to prevent that...
837 $toeval='$largeImage=$thumb->create($dir."/".$dirList[$int], $largeRes);';
838 eval( $toeval );
839 if (defined( $largeImage )){
840 my $fh;
841 if ( ! open( $fh, '>', $largeFile ) ){
842 $self->{error}=14;
843 $self->{errorString}='Failed to open "'.$smallFile.'" for writing';
844 $self->warn;
845 return undef;
846 }
847 print $fh $largeImage;
848 close $fh;
849 }else{
850 $self->warnString('Failed to create the large thumbnail for "'.$path.'"');
851 }
852
853 }
854
855 }
856
857
858 $int++;
859 }
860  
861 }
862  
863 =head1 ERROR CODES
864  
865 =head2 1, noObj
866  
867 No L<Toader::Gallery> object specified.
868  
869 =head2 2, noToaderObj
870  
871 No L<Toader> object specified.
872  
873 =head2 3, objPerror
874  
875 The L<Toader::Gallery> object has a permanent error set.
876  
877 =head2 4, toaderPerror
878  
879 The L<Toader> object has a permanent error set.
880  
881 =head2 5, noDirSet
882  
883 The L<Toader::Gallery> object does not have a directory set
884  
885 =head2 6, pathhalperInitErrored
886  
887 Failed to initialize a Toader::pathHelper.
888  
889 =head2 7, realative2rootErrored
890  
891 Failed to get relative to root.
892  
893 =head2 9, notUnderSrcPath
894  
895 The specified directory does not appear to be under the source path.
896  
897 =head2 10, dirStartsWithPeriod
898  
899 The specified directory contains a directory that starts with a period.
900  
901 =head2 11, srcPathDoesNotExit
902  
903 The source directory does not exist.
904  
905 =head2 12, outputDirDoesNotExist
906  
907 The output directory does not exist.
908  
909 =head2 13, srcDirOpenFailed
910  
911 Could not open the source directory.
912  
913 =head2 14, smallThumbFileOpenFailed
914  
915 Failed to open the small thumbnail file.
916  
917 =head2 15, smallThumbPathCreationFailed
918  
919 Failed to create the new path for the small thumbnails.
920  
921 =head2 16, largeThumbPathCreationFailed
922  
923 Failed to create the new path for the large thumbnails.
924  
925 =head2 17, generalInitErrored
926  
927 Failed to initialize L<Toader::Render::General>.
928  
929 =head2 18, renderTemplateErrored
930  
931 Failed to render a template.
932  
933 =head2 19, pathCreationFailed
934  
935 Failed to create the new path for the index.html.
936  
937 =head2 20, pathCleanupFailed
938  
939 Path cleanup failed.
940  
941 =head1 AUTHOR
942  
943 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
944  
945 =head1 BUGS
946  
947 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
948 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be
949 notified, and then you'll automatically be notified of progress on your bug as I make
950 changes.
951  
952 =head1 SUPPORT
953  
954 You can find documentation for this module with the perldoc command.
955  
956 perldoc Toader::Render::AutoDoc
957  
958 You can also look for information at:
959  
960 =over 4
961  
962 =item * RT: CPAN's request tracker
963  
964 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
965  
966 =item * AnnoCPAN: Annotated CPAN documentation
967  
968 L<http://annocpan.org/dist/Toader>
969  
970 =item * CPAN Ratings
971  
972 L<http://cpanratings.perl.org/d/Toader>
973  
974 =item * Search CPAN
975  
976 L<http://search.cpan.org/dist/Toader/>
977  
978 =back
979  
980  
981 =head1 ACKNOWLEDGEMENTS
982  
983  
984 =head1 LICENSE AND COPYRIGHT
985  
986 Copyright 2012. Zane C. Bowers-Hadley.
987  
988 This program is free software; you can redistribute it and/or modify it
989 under the terms of either: the GNU General Public License as published
990 by the Free Software Foundation; or the Artistic License.
991  
992 See http://dev.perl.org/licenses/ for more information.
993  
994  
995 =cut
996  
997 1; # End of Toader::Render::AutoDoc
« Toader/Render/supportedObjects.pm ↑ Summary