#!/usr/bin/perl -w # # Photoalbum generator # # Designed by Flex. # Written by Flex from FleXoft. # (flex@fleischmann.hu) # # v1.25, 2005.07.12. Budapest, FleXoft # Bfx: in the sub extras ($$) when '()' was in the pattern # # v1.24, 2005.06.27. Budapest, FleXoft # Add: PICTEXT feature # # v1.23, 2005.06.20. Budapest, FleXoft # Chg: NOPIC behaviour # # v1.22, 2005.05.28. Budapest, FleXoft # Bfx: around MAXCOL # # v1.21, 2005.03.21. Budapest, FleXoft # Chg: EXIF tuning # # v1.20, 2005.03.18. Budapest, FleXoft # Add: start implementing EXIF support # # v1.17, 2005.03.06. Budapest, FleXoft # Bfx: around the NOLINK and NOPIC options # # v1.16, 2005.03.04. Budapest, FleXoft # Add: -w option to specify the table width (the default is: 100%) # Add: -e option for not to create latest .htm(l) and .jpg # # v1.15, 2005.03.02. Budapest, FleXoft # Add: -1 -l option # Add: NOPIC option # # v1.14, 2005.02.27. Budapest, FleXoft # Chg: minor codechange on the engine to fix the -i option flexibility... # # v1.13, 2005.01.07. Budapest, FleXoft # Add: geometry correction see "!" option of convert # Add: NOLINK option from slide and body # # v1.12, 2005.01.06. Budapest, FleXoft # Add: NOLINK option from the pic file # Add: improve the html comments # # v1.11, 2004.12.20. Budapest, FleXoft # Add: MAXCOL overwriting feature from the album file body_theme # # v1.10, 2004.12.09. Budapest, FleXoft # Chg: minor codebrush again # Chg: the overwriting order # # v1.09, 2004.12.09. Budapest, FleXoft # Chg: major changes on r_change_string ($$$). It returns the counter. # Add: file: option in the overwriting string # # v1.08, 2004.12.08. Budapest, FleXoft # Chg: minor codebrush again # Chg: major changes on the album body generation # Del: -b # # v1.07, 2004.12.05. Budapest, FleXoft # Bfx: get_right () \r bug # Add: -i # Add: -S # # v1.06, 2004.11.xx. Budapest, FleXoft # Add: album theme option # Add: theme directory option # Chg: minor codebrush # Add: use basename module instead of regexp to separate the path, filename and extension # # v1.05, 2004.05.17. Budapest, FleXoft # Add: overwrite feature in "files and album.txt" files # # v1.04, 2004.04.18. Budapest, FleXoft # Add: Progress bar # # v1.03, 2004.04.14. Budapest, FleXoft # Add: stamp () # # v1.02, 2004.04.09. Budapest, FleXoft # Add: Spent time feature # Add: album.txt # # v1.01, 2004.04.08. Budapest, FleXoft # Add: r_change_string ($$$) # I like it more than the simple change_string (##@) # Chg: codebrush # # v1.00, 2004.04.06. Budapest, FleXoft # Rls: first release # # Documentation: # -------------- # # # TODO: # ----- # Text cut feature # {{DATE}} # CGI mode # rss & atom feeds # # ========================================================================= # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # # ************************************************************************* # # XXXXXXX XXX XXX XXX XXX X # XX X XX XX XX XX XX XX # XX X XX XXXXX XXX XXXX XX XXXXX # XXXX XX XX X X XX XX XXXXX XX # XX X XX XXXXXXX XXX XX XX XX XX # XX XX XX XX XX XX XX XX XX XX # XXXX XXXX XXXXX XXX XXX XXXX XXXX XXX # # ************************************************************************* use strict; my $starttime = time; use Getopt::Std; use Sys::Hostname; use File::Basename; #use IO::File; &getopts ("bqdvhf:c:s:t:gT:A:a:S:i:1:l:w:e"); our $opt_q; #our $opt_d; our $opt_v; our $opt_h; our $opt_f; our $opt_c; our $opt_s; our $opt_t; our $opt_g; our $opt_T; our $opt_a; our $opt_A; our $opt_S; our $opt_i; our $opt_1; our $opt_l; our $opt_w; our $opt_e; # require ".pm"; ############################################################################################################################# # SETTINGS ############################################################################################################################# my $CONVERT = "convert"; my $IDENTIFY = "identify"; # for EXIF information # not yet implemented #my $JHEAD = "jhead"; # default filename my $FILENAME = "files"; my $ALBUMFILE = "album.txt"; # Themes my $THEME = "HTM"; my $THEMEDIRECTORY = "../templates"; if ( defined ($opt_T) ) { $THEMEDIRECTORY = $opt_T; } # HTML output my $HTML = "htm"; my $INDEX = "index.$HTML"; my $LATEST = "latest"; my $FIRST = $INDEX; my $LAST = $INDEX; # Thumbnail my $THUMB = "thumb"; my $LANDSCAPEGEOMETRY = "120x80"; my $PORTRAITGEOMETRY = "80x120"; my $XGEOMETRY = "120x120"; # Maximum column number my $MAXCOL = 5; # Space between slides my $SLIDESPACE = 2; # Table width my $WIDTH = "100%"; # system... my $username = $ENV{"USER"}; #my $hostname = "alma".$ENV{"HOSTNAME"}; my $hostname = hostname; ################ # Version Info ################ # # based on Jux's code # open my $MYSELF, "<$0" or die; my ($VERSION, $SUBVERSION); while (<$MYSELF>) { if ( /^# v(\d+)\.(\d{2})/ ) { ($VERSION, $SUBVERSION) = ($1, $2); last; } die "No version info found in $0" unless /^#/; } close $MYSELF or die; my $PROGNAME = $0; $PROGNAME =~ s{.*(/|\\)}{}; if ( ! defined ($opt_q) ) { print "$PROGNAME v$VERSION.$SUBVERSION\n"; } ############################################################################################################################# # MAIN ############################################################################################################################# # !!!Disable output buffering for progress bar!!! $|++; if ( defined ($opt_v) ) { exit; } if ( defined ($opt_h) ) { print "\nHelp:\n"; print " -q\tToggle quiet mode.\n"; # print " -d\tToggle debug messages.\n"; print " -v\tShow only version information.\n"; print " -f\tSpecify the picture files description filename [default: $FILENAME]\n"; print " -c\tMax column number [default: $MAXCOL]\n"; print " -s\tSpace between slides in pixel [default: $SLIDESPACE]\n"; print " -w\tTable width [default: $WIDTH]\n"; print " -t\tSpecify the album title.\n"; print " -g\tForce thumbnail generation even exist.\n"; print " -T\tSpecify the template directory.\n"; print " -A\tSpecify the album theme name.\n"; print " -a\tSpecify the album filename [default: $ALBUMFILE]\n"; print " -S\tSpecify the shortcut theme name.\n"; print " -i\tSpecify the output filename [default: $INDEX]\n"; print " -1\tSpecify the first page link [default: $FIRST]\n"; print " -l\tSpecify the last page link [default: $LAST]\n"; print " -e\tDon't create latest files.\n"; print " -h\tShow usage. This is.\n\n"; exit; } if ( defined ($opt_f) ) { $FILENAME = $opt_f; } if ( defined ($opt_c) ) { $MAXCOL = $opt_c; } if ( defined ($opt_s) ) { $SLIDESPACE = $opt_s; } if ( defined ($opt_w) ) { $WIDTH = $opt_w; } if ( defined ($opt_1) ) { $FIRST = $opt_1; } if ( defined ($opt_l) ) { $LAST = $opt_l; } my @file = &open_file ("$FILENAME"); my @nolink; # to collect the NOLINK option my @nopic; # and the NOPIC option my @pictextfile; # and the PICTEXT option my @geometry; # and the GEOMETRY option # ALBUM TITLE my $TITLE = ""; if ( defined ($opt_t) ) { $TITLE = $opt_t; } else { $TITLE = &get_right ('title\s*:', @file); } if ( ! defined ($opt_q) ) { print "Album title: \"$TITLE\"\n"; } # ALBUM TEXT if ( defined ($opt_a) ) { $ALBUMFILE = $opt_a; } my %album_theme_extras; my $TEXT = ""; if ( -e "$ALBUMFILE" ) { my @file = &open_file ("$ALBUMFILE"); &extras ("fakestring, ".&get_right ('overwrite\s*:', @file), \%album_theme_extras); $TEXT = join("", &remark_remover (@file)); if ( ! defined ($opt_q) ) { print "Found albumfile: [$ALBUMFILE].\n"; } } # INDEX file if ( defined ($opt_i) ) { $INDEX = $opt_i; } my %file_extras; &extras ("fakestring, ".&get_right ('overwrite\s*:', @file), \%file_extras); @file = &remark_remover (@file); ####################### # Generate HTML album ####################### ############################### # PreGenerate the shortcutbar ######################################################################################### ############################### &pb_init ($#file); my $shortcutbar = ""; #my @filename; { my $shortcuttheme =""; if ( defined ($opt_S) ) { $shortcuttheme = "_$opt_S"; } if ( ! defined ($opt_q) ) { print "PreGenerating the shortcutbar based on [$THEMEDIRECTORY/SHORTCUT$shortcuttheme.$THEME].\n"; } my @shortcuthtmltmp = &remark_remover (&open_file ("$THEMEDIRECTORY/SHORTCUT$shortcuttheme.$THEME")); my $i = 0; for ( @file ) { chomp; (my $picturepath, my $body_theme, my $slide_theme) = split /\|/; $picturepath = "0" if ( ! defined $picturepath || $picturepath eq "" ); $body_theme = "0" if ( ! defined $body_theme || $body_theme eq "" ); $slide_theme = "0" if ( ! defined $slide_theme || $slide_theme eq "" ); (my $filename, my $path) = fileparse($picturepath, '\.\w\w\w'); # overwriting feature; get the extras my %body_theme_extras; $body_theme = &extras ($body_theme, \%body_theme_extras); my %slide_theme_extras; $slide_theme = &extras ($slide_theme, \%slide_theme_extras); # set the default values $nolink[$i] = "NO"; $nopic[$i] = "NO"; $pictextfile[$i] = "$path$filename.txt"; $geometry[$i] = ""; # is there any extra option... # NOPIC $nopic[$i] = "YES" if ( uc($body_theme_extras{"NOPIC"}) eq "YES" || uc($slide_theme_extras{"NOPIC"}) eq "YES" ); # NOLINK from... $nolink[$i] = "YES" if ( uc($body_theme_extras{"NOLINK"}) eq "YES" || uc($slide_theme_extras{"NOLINK"}) eq "YES" ); # PICTEXT from... $pictextfile[$i] = $body_theme_extras{"PICTEXT"} if ( defined $body_theme_extras{"PICTEXT"} ); $pictextfile[$i] = $slide_theme_extras{"PICTEXT"} if ( defined $slide_theme_extras{"PICTEXT"} ); # GEOMETRY from... $geometry[$i] = $slide_theme_extras{"GEOMETRY"} if ( defined $slide_theme_extras{"GEOMETRY"} ); # GET PIC and TITLE and filename with NOLINK option my $title = ""; if ( -e $pictextfile[$i] ) { my @file = &open_file ($pictextfile[$i]); $title = &get_right ('title\s*:', @file); # overwrite if option exists... # my $tmpfilename = &get_right ("filename:", @file); # $filename[$i] = $tmpfilename if ( $tmpfilename ne "" ); # overwrite if option exists... $nopic[$i] = "YES" if ( uc(&get_right ('nopic\s*:', @file)) eq "YES" ); $nolink[$i] = "YES" if ( uc(&get_right ('nolink\s*:', @file)) eq "YES" ); } if ( $nopic[$i] ne "YES" && ! -e "$picturepath" ) { die "$picturepath doesn't exist!"; } my @shortcut = @shortcuthtmltmp; if ( $nolink[$i] eq "YES" ) { &r_change_string ("", "", \@shortcut); &r_change_string ("", "", \@shortcut); &r_change_string ("{{NUMBER}}", ($i+1), \@shortcut); } else { &r_change_string ("{{LINK}}", "$filename.$HTML", \@shortcut); &r_change_string ("{{NUMBER}}", ($i+1), \@shortcut); &r_change_string ("{{ALT}}", "$title", \@shortcut); } $shortcutbar .= join("", @shortcut); if ( ! defined ($opt_q) ) { print &pb_bar($i++)."\r"; } } } ################ # ALBUM HEADER ######################################################################################################## ################ &pb_init ($#file); my $albumtheme =""; if ( defined ($opt_A) ) { $albumtheme = $opt_A; } if ( ! defined ($opt_q) ) { print "Generating the album header based on [$THEMEDIRECTORY/ALBUM_HEADER_$albumtheme.$THEME].\n"; } my @htmltmp = &open_file ("$THEMEDIRECTORY/ALBUM_HEADER_$albumtheme.$THEME"); # Add comment &append_file ("$INDEX", "\n\n\n"); # overwriting album theme HTML with extras &r_html_overwriting (\@htmltmp, \%file_extras, "HTML overwriting in the album theme header G:"); &r_html_overwriting (\@htmltmp, \%album_theme_extras, "HTML overwriting in the album theme header:"); # {{SHORTCUTBAR}} &r_change_string ("{{SHORTCUTBAR}}", "$shortcutbar", \@htmltmp); # {{TITTLE}} &r_change_string ("{{TITLE}}", "$TITLE", \@htmltmp); # {{TEXT}} &r_change_string ("{{TEXT}}", "$TEXT", \@htmltmp); &write_file ("$INDEX", @htmltmp); if ( ! defined ($opt_q) ) { print "Creating HTML pages for ".($#file+1)." image(s).\n"; } #for ( @file ) { for ( my $i = 0, my $linecounter = 1, my $colcounter = 1; $i <= $#file; $i++, $colcounter++ ) { chomp($file[$i]); (my $picturepath, my $body_theme, my $slide_theme, my $background_theme, my $frame_theme) = split (/\|/, $file[$i]); $picturepath = "0" if ( ! defined $picturepath || $picturepath eq "" ); $body_theme = "0" if ( ! defined $body_theme || $body_theme eq "" ); $slide_theme = "0" if ( ! defined $slide_theme || $slide_theme eq "" ); $background_theme = "0" if ( ! defined $background_theme || $background_theme eq "" ); $frame_theme = "0" if ( ! defined $frame_theme || $frame_theme eq ""); (my $filename, my $path) = fileparse($picturepath, '\.\w\w\w'); # overwriting feature; get the extras my %body_theme_extras; $body_theme = &extras ($body_theme, \%body_theme_extras); my %slide_theme_extras; $slide_theme = &extras ($slide_theme, \%slide_theme_extras); my %background_theme_extras; $background_theme = &extras ($background_theme, \%background_theme_extras); my %frame_theme_extras; $frame_theme = &extras ($frame_theme, \%frame_theme_extras); # GET PIC TITLE, LINK, TEXT and EXIF my $title = ""; my $link = ""; my $text = ""; my @exif; if ( -e $pictextfile[$i] ) { if ($pictextfile[$i] ne "$path$filename.txt" ) { print " The text file name of this picture has changed from [$path$filename.txt] to [$pictextfile[$i]].\n" if ( ! defined ($opt_q) ); } my @file = &open_file ($pictextfile[$i]); $title = &get_right ('title\s*:', @file); $link = &get_right ('link\s*:', @file); # read the EXIF lines for (@file) { chomp; if ( m/#\s*EXIF\s+(.*?)(:\s*.*)$/i ) { my $exif_left = $1; my $exif_right = $2; $exif_left =~ s/ /\ /g; $exif_right =~ s/ /\ /g; $exif_right =~ s/\\/\\\\/g; $exif_right =~ s/(\d\d\d\d):(\d\d):(\d\d)/$1.$2.$3/; $exif_right =~ s/\r$//; $exif_right = ": n/a" if ( $exif_right =~ m/:\s*$/ ); push (@exif, "".$exif_left."".$exif_right."
"); } } $text = join("", &remark_remover (@file)); } # GET PIC SIZE (my $width = "n/a", my $height = "n/a", my $size = "n/a"); if ( $nopic[$i] ne "YES" ) { open (PIPE, "$IDENTIFY $picturepath |") or die "Error running $IDENTIFY: $!"; while () { if ( ($width, $height, $size) = ($_ =~ /JPEG (\d+)x(\d+)\ \w+ (\d+.).*b/) ) { } } close(PIPE); } # PREVIOUS and NEXT generator with Nolink option # GET PREVIOS PICTURE my $previous = ""; my $previousthumbnail = ""; if ( $i == 0 ) { $previous = "$FIRST"; } else { if ( $nolink[$i-1] eq "YES" ) { my $ii = $i-2; for ( ; $ii >= 0; $ii-- ) { last if ( $nolink[$ii] ne "YES" ); } if ( $ii >= 0 ) { $previous = $file[$ii]; } else { $previous = "$FIRST"; } } else { $previous = $file[$i-1]; } if ( "$previous" ne "$FIRST" ) { ($previous) = split (/\|/, $previous); ($previous, $previousthumbnail) = fileparse($previous, '\.\w\w\w'); $previousthumbnail .= "$previous\_$THUMB.jpg"; $previous .= ".$HTML"; } } # GET NEXT PICTURE my $next = ""; my $nextthumbnail = ""; if ( $i == $#file ) { $next = "$LAST"; } else { if ( $nolink[$i+1] eq "YES" ) { my $ii = $i+2; for ( ; $ii <= $#file; $ii++ ) { last if ( $nolink[$ii] ne "YES" ); } if ( $ii <= $#file ) { $next = $file[$ii]; } else { $next = "$LAST"; } } else { $next = $file[$i+1]; } if ( "$next" ne "$LAST" ) { ($next) = split (/\|/, $next); ($next, $nextthumbnail) = fileparse($next, '\.\w\w\w'); $nextthumbnail .= "$next\_$THUMB.jpg"; $next .= ".$HTML"; } } if ( ! defined ($opt_q) ) { print "==[".($i+1)."/".($#file+1)."]==[$picturepath]==[$width*$height]==[$size]==[$title]==========================\n"; } # if ( -e $pictextfile[$i] && $pictextfile[$i] ne "$path$filename.txt" ) { print " The text file name of this picture has changed from [$path$filename.txt] to [$pictextfile[$i]].\n" if ( ! defined ($opt_q) ); } # load maxcol every loop my $maxcol = $MAXCOL; if ( defined $body_theme_extras{"MAXCOL"} && $body_theme_extras{"MAXCOL"} >= 1 ) { $maxcol = $body_theme_extras{"MAXCOL"}; if ( ! defined ($opt_q) ) { print " MAXCOL [$MAXCOL\=\>$maxcol] variable overwriting in the album body.\n"; } } # Confuse the cat! my @htmltmp; # Picture page generation ############################################################################################ if ( $nolink[$i] ne "YES" ) { my @picturehtmltmp; ################## # PICTURE HEADER #################################################################################################### ################## @htmltmp = &open_file ("$THEMEDIRECTORY/PICTURE_HEADER_$background_theme.$THEME"); # Add comment push (@htmltmp, "\n\n\n"); # overwriting background HTML with extras &r_html_overwriting (\@htmltmp, \%file_extras, " HTML overwriting background theme headrer G:"); &r_html_overwriting (\@htmltmp, \%background_theme_extras, " HTML overwriting background theme headrer:"); ################ # PICTURE BODY ###################################################################################################### ################ @picturehtmltmp = &open_file ("$THEMEDIRECTORY/PICTURE_FRAME_$frame_theme.$THEME"); # Add comment push (@picturehtmltmp, "\n\n\n"); # overwriting background HTML with extras &r_html_overwriting (\@picturehtmltmp, \%file_extras, " HTML overwriting frametheme G:"); &r_html_overwriting (\@picturehtmltmp, \%frame_theme_extras, " HTML overwriting frametheme:"); push (@htmltmp, @picturehtmltmp); ################## # PICTURE FOOTER #################################################################################################### ################## @picturehtmltmp = &open_file ("$THEMEDIRECTORY/PICTURE_FOOTER_$background_theme.$THEME"); # Add comment push (@picturehtmltmp, "\n\n\n"); # overwriting background HTML with extras &r_html_overwriting (\@picturehtmltmp, \%file_extras, " HTML overwriting background theme footer G:"); &r_html_overwriting (\@picturehtmltmp, \%background_theme_extras, " HTML overwriting background theme footer:"); push (@htmltmp, @picturehtmltmp); # {{TITLE}} &r_change_string ("{{TITLE}}", "$title", \@htmltmp); # {{SHORTCUTBAR}} &r_change_string ("{{SHORTCUTBAR}}", "$shortcutbar", \@htmltmp); # {{PREV}} &r_change_string ("{{PREV}}", "$previous", \@htmltmp); # {{PREVTHUMBNAIL}} &r_change_string ("{{PREVTHUMBNAIL}}", "$previousthumbnail", \@htmltmp); # {{PIC}} &r_change_string ("{{PIC}}", "$picturepath", \@htmltmp); # {{THUMBNAIL}} &r_change_string ("{{THUMBNAIL}}", "$path$filename\_$THUMB.jpg", \@htmltmp); # {{ALT}} &r_change_string ("{{ALT}}", "$title", \@htmltmp); # {{TEXT}} &r_change_string ("{{TEXT}}", "$text", \@htmltmp); # {{EXIF}} &r_change_string ("{{EXIF}}", join("", @exif), \@htmltmp); # {{NEXT}} &r_change_string ("{{NEXT}}", "$next", \@htmltmp); # {{NEXTTHUMBNAIL}} &r_change_string ("{{NEXTTHUMBNAIL}}", "$nextthumbnail", \@htmltmp); # {{ORIGINALPICTURELINK}} if ( ! $link eq "" ) { &r_change_string ("{{ORIGINALPICTURELINK}}", "$link", \@htmltmp); } else { &r_change_string ("{{ORIGINALPICTURELINK}}", "$picturepath", \@htmltmp); } &write_file ("$filename.$HTML", @htmltmp); &append_file ("$filename.$HTML", &stamp); if ( $previous eq "$FIRST" && ! defined ($opt_e) ) { # &write_file ("$LATEST.$HTML", @htmltmp); # &append_file ("$LATEST.$HTML", &stamp); unlink( "$LATEST.$HTML" ) if ( -e "$LATEST.$HTML" ); link( "$filename.$HTML", "$LATEST.$HTML"); } } # End of Picture page generation ####################################################################################### ############## # ALBUM BODY ########################################################################################################## ############## if ( $nopic[$i] ne "YES" ) { my $rate = $width / $height; my $geometry; if ( $rate >= 0.85 && $rate <= 1.15 ) { ############# # X ############# $geometry = $XGEOMETRY; $geometry .= "!" if ( $rate > 0.90 && $rate < 1.1 ); } elsif ( $rate > 1.1 ) { ############# # LANDSCAPE ############# $geometry = $LANDSCAPEGEOMETRY; $geometry .= "!" if ( $rate > 1.3 && $rate < 1.7 ); } else { ############ # PORTRAIT ############ $geometry = $PORTRAITGEOMETRY; $geometry .= "!" if ( $rate > 0.46 && $rate < 0.86 ); } if ( $geometry[$i] ne "" ) { print " Thumbnail geometry overwriting [$geometry] with [$geometry[$i]].\n" if ( ! defined ($opt_q) ); $geometry = $geometry[$i]; } if ( ! -e "$path$filename\_$THUMB.jpg" || defined ($opt_g) ) { if ( ! defined ($opt_q) ) { print &pb_bar($i)."\r"; } open (PIPE, "$CONVERT -geometry $geometry $picturepath $path$filename\_$THUMB.jpg |") or die "Error running $CONVERT: $!"; close(PIPE); } else { if ( ! defined ($opt_q) ) { print " Thumbnail [$path$filename\_$THUMB.jpg] already exists so no need to regenarate! Use -g if so...\n"; } } if ( "$previous" eq "$FIRST" && ! defined ($opt_e) ) { unlink( "$LATEST\_$THUMB.jpg" ) if ( -e "$LATEST\_$THUMB.jpg" ); link( "$path$filename\_$THUMB.jpg", "$LATEST\_$THUMB.jpg"); } @htmltmp = &open_file ("$THEMEDIRECTORY/SLIDE_$slide_theme.$THEME"); # {{LINK}} part 1 if ( $nolink[$i] eq "YES" ) { &r_change_string ("", "", \@htmltmp); &r_change_string ("", "", \@htmltmp); } # overwriting slide HTML with extras &r_html_overwriting (\@htmltmp, \%file_extras, " HTML overwriting in the slide theme G:"); &r_html_overwriting (\@htmltmp, \%slide_theme_extras, " HTML overwriting in the slide theme:"); # {{LINK}} part 2 if ( $nolink[$i] ne "YES" ) { &r_change_string ("{{LINK}}", "$filename.$HTML", \@htmltmp); } # {{TITLE}} &r_change_string ("{{TITLE}}", "$title", \@htmltmp); # {{TEXT}} &r_change_string ("{{TEXT}}", "$text", \@htmltmp); # {{NUMBER}} &r_change_string ("{{NUMBER}}", ($i+1), \@htmltmp); # {{PIC}} &r_change_string ("{{PIC}}", "$path$filename.jpg", \@htmltmp); # {{THUMBNAIL}} &r_change_string ("{{THUMBNAIL}}", "$path$filename\_$THUMB.jpg", \@htmltmp); # {{ALT}} &r_change_string ("{{ALT}}", "$title", \@htmltmp); # {{FILENAME}} &r_change_string ("{{FILENAME}}", "$filename", \@htmltmp); } if ( ! defined ($opt_q) ) { print "Generating the album body based on [$THEMEDIRECTORY/ALBUM_BODY_$body_theme.$THEME].\n"; } # ... if ( $colcounter == 1 ) { &append_file ("$INDEX", "\n\n\n"); &append_file ("$INDEX", '
'."\n\n"); } my @bodyhtml = &open_file ("$THEMEDIRECTORY/ALBUM_BODY_$body_theme.$THEME"); # Add comments &append_file ("$INDEX", "\n\n\n"); &append_file ("$INDEX", "\n\n\n"); # {{LINK}} part 1 if ( $nolink[$i] eq "YES" ) { &r_change_string ("", "", \@bodyhtml); &r_change_string ("", "", \@bodyhtml); } # overwriting body theme HTML with extras &r_html_overwriting (\@bodyhtml, \%file_extras, "HTML overwriting in in the album body theme G:"); &r_html_overwriting (\@bodyhtml, \%body_theme_extras, "HTML overwriting in the album body theme:"); # {{LINK}} part 2 if ( $nolink[$i] ne "YES" ) { &r_change_string ("{{LINK}}", "$filename.$HTML", \@bodyhtml); } # {{SLIDE}} if ( $nopic[$i] eq "YES" ) { &r_change_string ("{{SLIDE}}", "", \@bodyhtml); } else { &r_change_string ("{{SLIDE}}", join("", @htmltmp), \@bodyhtml); } # {{TITLE}} &r_change_string ("{{TITLE}}", "$title", \@bodyhtml); # {{TEXT}} &r_change_string ("{{TEXT}}", "$text", \@bodyhtml); # {{NUMBER}} &r_change_string ("{{NUMBER}}", ($i+1), \@bodyhtml); # {{PIC}} &r_change_string ("{{PIC}}", "$path$filename.jpg", \@bodyhtml); # {{THUMBNAIL}} &r_change_string ("{{THUMBNAIL}}", "$path$filename\_$THUMB.jpg", \@bodyhtml); # {{ALT}} &r_change_string ("{{ALT}}", "$title", \@bodyhtml); # {{FILENAME}} &r_change_string ("{{FILENAME}}", "$filename", \@bodyhtml); &append_file ("$INDEX", @bodyhtml); #...
if ( $colcounter == $maxcol || $i == $#file || $maxcol == 1 ) { &append_file ("$INDEX", "\n\n"); &append_file ("$INDEX", "\n\n\n"); $colcounter = 0; $linecounter++; } if ( ! defined ($opt_q) ) { print &pb_bar($i)."\r"; } } ## End of for ## ################ # ALBUM FOOTER ######################################################################################################## ################ if ( ! defined ($opt_q) ) { print "Generating the album footer based on [$THEMEDIRECTORY/ALBUM_FOOTER_$albumtheme.$THEME].\n"; } @htmltmp = &open_file ("$THEMEDIRECTORY/ALBUM_FOOTER_$albumtheme.$THEME"); # Add comment &append_file ("$INDEX", "\n\n\n"); # overwriting album theme HTML with extras &r_html_overwriting (\@htmltmp, \%file_extras, "HTML overwriting in the album theme footer G:"); &r_html_overwriting (\@htmltmp, \%album_theme_extras, "HTML overwriting in the album theme footer:"); # {{TITTLE}} &r_change_string ("{{TITLE}}", "$TITLE" , \@htmltmp); # {{TEXT}} &r_change_string ("{{TEXT}}", "$TEXT" , \@htmltmp); &append_file ("$INDEX", @htmltmp); &append_file ("$INDEX", &stamp); if ( ! defined ($opt_q) ) { print sprintf("Spent time: ".&time_format (time - $starttime)."\n"); } exit 0; ######################################################################################################################## # SUBs ######################################################################################################################## ############### # Open a file ############### sub open_file ($) { my $filename = $_[0]; open (DATAFILE, $filename) || die ("$! | \"$filename\""); my @file = ; close DATAFILE; return @file; } ################ # Write a file ################ sub write_file ($@) { my $filename = "./".shift; open (DATAFILE, ">$filename") || die ("$! | $filename"); print DATAFILE @_; close DATAFILE; } #################### # Append to a file #################### sub append_file ($@) { my $filename = "./".shift; open (DATAFILE, ">>$filename") || die ("$! | $filename"); print DATAFILE @_; close DATAFILE; } ############################# # Change string in an array ############################# sub change_string ($$@) { my $mit = shift; my $mire = shift; for (my $i = 0; $i <= $#_; $i++) { $_[$i] =~ s/$mit/$mire/; } return @_; } ################################################# # Change string in an array passed by reference ################################################# sub r_change_string ($$$) { # s/$_[0]/$_[1]/g for ( @{$_[2]} ); my $counter = 0; for ( @{$_[2]} ) { while ( s/$_[0]/$_[1]/g ) { ++$counter; } } return $counter; } ############################### # Change hash strings in HTML ############################### sub r_html_overwriting ($$$) { my $hol = shift; my $mire = shift; my $szoveg = shift; my $counter = 0; my $start = 0; foreach my $key (keys %$mire) { $start = 1; if ( $mire->{$key} =~ /absolutefile:\s*(.*)$/i ) { $counter=&r_change_string ("$key", join("", &open_file ("$1")), $hol); } elsif ( $mire->{$key} =~ /file:\s*(.*)$/i ) { $counter=&r_change_string ("$key", join("", &open_file ("$THEMEDIRECTORY/$1")), $hol); } else { $counter=&r_change_string ("$key", "$mire->{$key}", $hol); } if ( ! defined ($opt_q) && $start ) { print "$szoveg [$key] with [$mire->{$key}]!!! M# [$counter].\n" if ( $counter ); } } } ################################ # Remove remarks from an array ################################ sub remark_remover (@) { my @return; for (@_) { if ( ! /^#|^\s.*/ ) { push (@return, $_); } } return @return; } ################################################## # Get the right side if the pattern from an array ################################################## sub get_right ($@) { my $pattern = shift; my $return = ""; for (@_) { if ( /$pattern\s+(.*)$/i ) { $return = $1; last; } } chomp($return); $return =~ s/\r$//; return $return; } ########################################## # Put the overwriting strings to the hash ########################################## sub extras ($$) { my $extras = $_[0]; my $return = $_[0]; my $r_hash = $_[1]; if ( $extras =~ /(.+)\[\s*(.+)\s*\]/g ) { $return=$1; my $extra=$2; if ( ! $extra eq "" ) { for ( split(/\s*,\s*/, $extra) ) { (my $mit, my $mire) = split(/=>/, $_); # change '(' and ')' to '\(' and '\(' $mit =~ s/\(/\\(/g; $mit =~ s/\)/\\)/g; # trim $mit =~ s/^\s*(.*?)\s*$/$1/; $mire =~ s/^\s*(.*?)\s*$/$1/; $r_hash->{$mit} = $mire; } } } return $return; } ############################ # Return the formatted time ############################ sub time_format ($) { my $time = $_[0]; my $sec = $time % 60; my $min = ($time / 60) % 60; my $hour = ($time / 3600) % 24; return sprintf("%02d:%02d:%02d", $hour, $min, $sec); } ####################### # Return stamp string ####################### sub stamp () { my $return = ""; $return .= "\n\n"; return $return; } ############################################################################################################################# # Progress Bar ############################################################################################################################# my $PB_STARTTIME; my $PB_MAX = 1; sub pb_init ($) { $PB_MAX = $_[0]; $PB_STARTTIME = time; } sub pb_show ($) { print &pb_bar($_[0]); } sub pb_bar ($) { my $current = $_[0]; # 0 1 2 3 # 1234567890123456789012345678901234567890 my $bar = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; my $barlength = length ($bar); my $footer = ""; if ( $PB_MAX == 0 ) { $PB_MAX = 1; }; my $length = int($current * $barlength / $PB_MAX); if ( $current == 0 ) { $footer = "ETA: --:--:--" } elsif ( $current == $PB_MAX ) { $footer = "END: ".&time_format (time - $PB_STARTTIME); } else { $footer = "ETA: ".&time_format (&time_estimated ($current)); } return sprintf("|%.*s%*s| %s", $length, "$bar", $barlength - $length, "", "$footer"); } sub time_estimated ($) { my $current = $_[0]; my $elapsed = time - $PB_STARTTIME; return ($PB_MAX * $elapsed / $current) - $elapsed; } __END__ =head1 NAME B - description =head1 SYNOPSIS Coming soon...