#!/usr/bin/perl ########################################### # emAlbum.cgi v2.1 # #=========================================# # emAlbum v2.1 # # Standard Edition # #-----------------------------------------# # First Created: 2/17/03 # # Last Updated: 8/13/03 # #-----------------------------------------# # Written by: Eric Martin # # http://www.emalbum.com # #-----------------------------------------# # Copyright (c) 2003 emAlbum.com # # All Rights Reserved # ########################################### ############################################################################## # Copyright and Licensing Information # #============================================================================# # A copy of the License Agreement was included in this download as # # license.html. A copy can also be found on http://www.emalbum.com/. # # # # By installing this software, you agree to its terms. All Copyright and # # Licensing information must remain intact. Please contact us with any # # questions at support@emalbum.com. # ############################################################################## #---------------------------- DO NOT EDIT ------------------------------# # All setting are made in the settings.cfg file # use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; if ($^O =~ /win/i) { $slash = "\\"; } else { $slash = "/"; } $cgi_path = $ENV{'PATH_TRANSLATED'} || $ENV{'SCRIPT_FILENAME'}; $cgi_path =~ s/emAlbum.cgi//; # Open config file my $config_file = $cgi_path."emAlbum".$slash."settings.cfg"; require "$config_file"; # Open language file my $language_file = $cgi_path."emAlbum".$slash."language".$slash.$language; require "$language_file"; # Verify template file exists my $template_path = $cgi_path."emAlbum".$slash."templates".$slash.$template.".html"; unless (-e $template_path) { &error("100|$template_path"); } # Determine necessary variables $image_url .= "/$template"; if ($cgi_index == 1) { $cgi_url = $url; } else { $cgi_url .= "/emAlbum.cgi"; } $main_link = $album_url; $main_link =~ s/.*\///g; $main_link = ucfirst($main_link); # Parse query string and assign values if (($ENV{'REQUEST_METHOD'} eq 'GET') && ($ENV{'QUERY_STRING'} ne "")) { @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $emAlbum{$name} = $value; } } else { $emAlbum{'cmd'} = "default"; } # Home page link variable if ($home == 1) { $home_link = qq~$home_text $text{'8'} ~; } else { $home_link = ""; } # Determine action to take if (($emAlbum{'cmd'} eq "default") || ($emAlbum{'cmd'} eq "show_sub")) { &show_folders; } elsif (($emAlbum{'cmd'} eq "show_image")) { &show_image; } elsif (($emAlbum{'cmd'} eq "show_thumbs")) { &show_thumbs; } elsif (($emAlbum{'cmd'} eq "slide_show")) { &slide_show; } else { # Display main page if action cannot be determined $emAlbum{'cmd'} = "default"; &show_folders; } sub show_folders { # Set needed variables $now = time; $total_albums = 0; if ($emAlbum{'cmd'} eq "show_sub") { $album_path = "$album_path$slash$emAlbum{'path'}"; } # Open directory and read it's contents opendir(TMP,"$album_path") || &error("102|$album_path"); my @contents = grep !/\./ && !/^_/, sort readdir(TMP); closedir(TMP); my $folder_count = @contents; if ($folder_count == 0) { &error("103|$album_path"); } # Set values if not present unless ($emAlbum{'tn'}) { $emAlbum{'tn'} = $use_thumbs; } foreach $sub_folder (@contents) { chomp $sub_folder; $contains_sub = 0; $folder_path = "$album_path$slash$sub_folder"; # Use updated function routine if ($use_update == 1) { ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($folder_path); $offset = $update_range * 86400; $earliest = $now - $offset; if (($mtime|$ctime) >= $earliest) { $updated = 1; } else { $updated = 0; } } else { $updated = 0; } # Actions to take based on cmd if ($emAlbum{'cmd'} eq "show_sub") { $image_folder_path = "$album_path$slash$sub_folder"; &img_cnt; $sub_details = "$emAlbum{'path'}$slash$sub_folder|$contains_sub|$folder_count|$image_count|$updated"; push (@main,$sub_details); $curr_folder = $emAlbum{'path'}; $curr_folder =~ s/_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $curr_folder $text{'8'}~; $totals_text = "$text{'11'} $folder_count $text{'13'} $text{'12'} $total_image_count"; } else { &subchk; $details = "$sub_folder|$contains_sub|$count|$image_count|$updated"; push (@main,$details); $emAlbumNavigation = qq~$home_link$main_link $text{'8'}~; $totals_text = "$text{'11'} $total_albums $text{'13'} $text{'12'} $total_image_count"; } } @contents = (); $album_count = 0; $alb_cnt = @main; $album_rows = $alb_cnt / 2; $emAlbumMain = qq~ ~; # Guts of the album page until ($album_count >= $alb_cnt) { $next_album = $album_count + 1; $current = @main[$album_count]; $next = @main[$next_album]; # Current image routine if ($current ne "") { ($current_fldr,$current_contains_sub,$current_folder_count,$current_image_count,$current_updated) = split(/\|/,$current); chomp $current_image_count; if ($current_fldr =~ /\//) { ($current_main_folder,$current_folder) = split(/\//,$current_fldr); } elsif ($current_fldr =~ /\\/) { ($current_main_folder,$current_folder) = split(/\\/,$current_fldr); } else { $current_folder = $current_fldr; } if ($emAlbum{'cmd'} eq "show_sub") { $current_path = "$emAlbum{'path'}$slash$current_folder"; } else { $current_path = $current_folder; } if ($current_updated == 1) { $suffix = "_new"; $current_alt = "$text{'18'}"; } else { $suffix = ""; $current_alt = ""; } $current_folder_name = $current_folder; $current_folder_name =~ s/\_/ /g; if ($current_contains_sub == 1) { $current_info = "$text{'2'} $current_folder_count"; $current_image = qq~$current_alt~; $current_link = qq~$current_folder_name~; } else { $current_info = "$text{'3'} $current_image_count"; if ($current_image_count == 0) { $current_image = qq~$current_alt~; $current_link = qq~$current_folder_name~; } else { if ($emAlbum{'tn'} == 0) { $current_image = qq~$current_alt~; $current_link = qq~$current_folder_name~; } else { $current_image = qq~$current_alt~; $current_link = qq~$current_folder_name~; } } } } else { $current_info = ""; $current_link = ""; $current_image = ""; } # Next image routine if ($next ne "") { ($next_fldr,$next_contains_sub,$next_folder_count,$next_image_count,$next_updated) = split(/\|/,$next); chomp $next_image_count; if ($next_fldr =~ /\//) { ($next_main_folder,$next_folder) = split(/\//,$next_fldr); } elsif ($next_fldr =~ /\\/) { ($next_main_folder,$next_folder) = split(/\\/,$next_fldr); } else { $next_folder = $next_fldr; } if ($emAlbum{'cmd'} eq "show_sub") { $next_path = "$emAlbum{'path'}$slash$next_folder"; } else { $next_path = $next_folder; } if ($next_updated == 1) { $suffix = "_new"; $next_alt = "$text{'18'}"; } else { $suffix = ""; $next_alt = ""; } $next_folder_name = $next_folder; $next_folder_name =~ s/\_/ /g; if ($next_contains_sub == 1) { $next_info = "$text{'2'} $next_folder_count"; $next_image = qq~$next_alt~; $next_link = qq~$next_folder_name~; } else { $next_info = "$text{'3'} $next_image_count"; if ($next_image_count == 0) { $next_image = qq~$next_alt~; $next_link = qq~$next_folder_name~; } else { if ($emAlbum{'tn'} == 0) { $next_image = qq~$next_alt~; $next_link = qq~$next_folder_name~; } else { $next_image = qq~$next_alt~; $next_link = qq~$next_folder_name~; } } } } else { $next_info = ""; $next_link = ""; $next_image = ""; } # Set folder link information $emAlbumMain .= qq~
$current_image $current_link
$current_info
 
$next_image $next_link
$next_info
 
~; $album_count = $album_count + 2; } # Set specific header information $emAlbumHeader = qq~ $totals_text ~; # Set specific footer information $emAlbumFooter = qq~   ~; # Finish up and display page &html; } sub subchk { # Open the directory and count the valid sub-folders opendir(TMP,"$folder_path") || &error("104|$folder_path"); my @sub_contents = grep !/\./ && !/^_/, sort readdir(TMP); #do not name folders w/ a '.' closedir(TMP); $count = @sub_contents; # If there are sub-folders set needed variables and continue if ($count != 0) { $contains_sub = 1; $image_count = 0; $total_albums += $count; foreach $line (@sub_contents) { chomp $line; $image_folder_path = "$folder_path$slash$line"; &img_cnt; } } else { $total_albums++; $image_folder_path = $folder_path; &img_cnt; } } sub img_cnt { # Open the image directory and count the valid images opendir(IMG,"$image_folder_path") || &error("105|$image_folder_path"); my @valid_images = grep /\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$/i, sort readdir(IMG); closedir(IMG); $image_count = @valid_images; $total_image_count += $image_count; @valid_images = (); } sub show_image { my $image_path = "$album_path$slash$emAlbum{'path'}"; # Open the image directory and get the selected image opendir(SHI,"$image_path") || &error("107|$image_path"); my @images = grep /\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$/i, sort readdir(SHI); closedir(SHI); my $display_number = $emAlbum{'img'} + 1; unless ($emAlbum{'img'}) { $emAlbum{'img'} = 0; $display_number = 1; } unless ($emAlbum{'tn'}) { $emAlbum{'tn'} = $use_thumbs; } my $display_image = @images[$emAlbum{'img'}]; my $image_src = qq~$text{'1'}~; my $display_name = $display_image; my $total_images = @images; if ($total_images == 0 ) { &error("108|$total_images"); } $thumb_link = ""; if ($emAlbum{'tn'} == 1) { $thumb_link = qq~$cgi_url?cmd=show_thumbs&path=$emAlbum{'path'}&tn=$emAlbum{'tn'}~; } if ($caption == 0) { $display_name = ""; } elsif ($caption == 2) { $display_name =~ s/\_/ /g; $display_name =~ s/\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$//i; } if ($emAlbum{'path'} =~ /\//) { ($main_folder,$folder) = split(/\//,$emAlbum{'path'}); $folder_name = $folder; $folder_name =~ s/\_/ /g; $main_folder_name = $main_folder; $main_folder_name =~ s/\_/ /g; if ($emAlbum{'tn'} == 1) { $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } else { $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } } elsif ($emAlbum{'path'} =~ /\\/) { ($main_folder,$folder) = split(/\\/,$emAlbum{'path'}); $folder_name = $folder; $folder_name =~ s/\_/ /g; $main_folder_name = $main_folder; $main_folder_name =~ s/\_/ /g; if ($emAlbum{'tn'} == 1) { $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } else{ $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } } else { $folder = $emAlbum{'path'}; $folder_name = $folder; $folder_name =~ s/\_/ /g; if ($emAlbum{'tn'} == 1) { $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $folder_name $text{'8'}~; } else { $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $folder_name $text{'8'}~; } } my $image_link = "$text{'16'} "; if ($total_images == 1) { $image_link .= qq~ [$display_number] ~; } elsif (($total_images > 1) && ($total_images < 9)) { my $image_count = 0; if ($emAlbum{'img'} != 0) { my $prev_image = $emAlbum{'img'} - 1; $image_link .= qq~$text{'9'} ~; } else { $image_link .= qq~ ~; } until ($image_count == $total_images) { my $display_number = $image_count + 1; if ($image_count == $emAlbum{'img'}) { $image_link .= qq~[$display_number] ~; } else { $image_link .= qq~$display_number ~; } $image_count++; } my $display_number = $emAlbum{'img'} + 1; if ($display_number == $total_images) { $image_link .= qq~~; } else { $image_link .= qq~$text{'10'}~; } } elsif ($total_images >= 9) { my $end_image = $emAlbum{'img'} + 3; my $beg_image = $emAlbum{'img'} - 1; my $start = $total_images - 4; my $display_number = $emAlbum{'img'} + 1; if ($emAlbum{'img'} == 0) { my $display_number = $emAlbum{'img'} + 1; $image_link .= qq~ [$display_number] ~; $image_count = 2; until ($image_count > 3) { my $next_image = $image_count - 1; $image_link .= qq~$image_count ~; $image_count++; } my $last_image = $total_images - 1; $image_link .= qq~... $total_images ~; my $next_image = $emAlbum{'img'} + 1; $image_link .= qq~$text{'10'}~; } elsif (($emAlbum{'img'} > 0) && ($emAlbum{'img'} < 4)) { my $prev_image = $emAlbum{'img'} - 1; $image_link .= qq~$text{'9'} ~; $image_link .= qq~1 ~; $image_count = 2; until ($image_count > $end_image) { $display_number = $emAlbum{'img'} + 1; if ($display_number == $image_count) { $image_link .= qq~[$display_number] ~; } else { my $next_image = $image_count - 1; $image_link .= qq~$image_count ~; } $image_count++; } my $last_image = $total_images - 1; $image_link .= qq~... $total_images ~; my $next_image = $emAlbum{'img'} + 1; $image_link .= qq~$text{'10'}~; } elsif (($emAlbum{'img'} >= 4) && ($emAlbum{'img'} < $start)) { my $prev_image = $emAlbum{'img'} - 1; $image_link .= qq~$text{'9'} ~; $image_link .= qq~1 ... ~; $image_count = $beg_image; until ($image_count > $end_image) { my $display_number = $emAlbum{'img'} + 1; if ($display_number == $image_count) { $image_link .= qq~[$display_number] ~; } else { my $next_image = $image_count -1; $image_link .= qq~$image_count ~; } $image_count++; } my $last_image = $total_images - 1; $image_link .= qq~... $total_images ~; my $next_image = $emAlbum{'img'} + 1; $image_link .= qq~$text{'10'}~; } elsif (($emAlbum{'img'} >= $start) && ($emAlbum{'img'} < $total_images)) { my $prev_image = $emAlbum{'img'} - 1; $image_link .= qq~$text{'9'} ~; $image_link .= qq~1 ... ~; $image_count = $beg_image; until ($image_count == $total_images) { my $display_number = $emAlbum{'img'} + 1; if ($display_number == $image_count) { $image_link .= qq~[$display_number] ~; } else { my $next_image = $image_count - 1; $image_link .= qq~$image_count ~; } $image_count++; } my $display_number = $emAlbum{'img'} + 1; if ($display_number == $total_images) { $image_link .= qq~[$display_number] ~; } else { my $next_image = $total_images - 1; $image_link .= qq~$total_images ~; my $next_image = $emAlbum{'img'} + 1; $image_link .= qq~$text{'10'}~; } } elsif ($display_number == $total_images) { my $prev_image = $emAlbum{'img'} - 1; $image_link .= qq~$text{'9'} ~; $image_link .= qq~1 ... ~; $image_count = $total_images - 2; until ($image_count == $total_images) { my $next_image = $emAlbum{'img'} + 1; $image_link .= qq~$image_count ~; $image_count++; } $image_link .= qq~[$emAlbum{'img'}] ~; } } if (($use_thumbs == 0) && ($drop == 1)) { $drop_code = qq~ ~; $tdh = 5; } else { $tdh = 10; } $emAlbumMain = qq~
$drop_code
$image_src
$display_name
~; if ($slide_show == 1) { $slide_link = qq~$text{'32'}~; $slide_link .= qq~ ~; $slide_link .= qq~$text{'31'}~; } else { $slide_link = ""; } $emAlbumHeader = qq~ $text{'14'} $display_number $text{'15'} $total_images $image_link $slide_link ~; $emAlbumFooter = qq~   ~; &html; } sub show_thumbs { # Check for variables, set if not declared unless ($emAlbum{'img'}) { $emAlbum{'img'} = 0; } unless ($emAlbum{'page'}) { $emAlbum{'page'} = 1; } $image_number = $emAlbum{'img'}; # Open image directory and put all valid images into an array my $thumb_image_path = "$album_path$slash$emAlbum{'path'}"; opendir(IPH,$thumb_image_path) || &error("109|$thumb_image_path"); my @images = grep /\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$/i, sort readdir(IPH); closedir(IPH); # Split the path if necessary if ($emAlbum{'path'} =~ /\//) { ($main_folder,$folder) = split(/\//,$emAlbum{'path'}); $folder_name = $folder; $folder_name =~ s/\_/ /g; $main_folder_name = $main_folder; $main_folder_name =~ s/\_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } elsif ($emAlbum{'path'} =~ /\\/) { ($main_folder,$folder) = split(/\\/,$emAlbum{'path'}); $folder_name = $folder; $folder_name =~ s/\_/ /g; $main_folder_name = $main_folder; $main_folder_name =~ s/\_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } else { $folder = $emAlbum{'path'}; $folder_name = $folder; $folder_name =~ s/\_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $folder_name $text{'8'}~; } unless ($emAlbum{'tn'}) { $emAlbum{'tn'} = $use_thumbs; } # Determine necessary variables my $total_images = @images; my $per_page = $per_row * $max_rows; my $pages_needed = $total_images / $per_page; # Round up if ($pages_needed =~ /\./) { $pages_needed =~ s/\..*//; $pages_needed++; } # Determine variables dependent on page if ($emAlbum{'page'} != 1) { $page_total = $total_images - $image_number; if ($page_total < $per_row) { $per_row = $page_total; } $rows = ($page_total) / $per_row; } else { $page_total = $total_images; if ($total_images < $per_row) { $per_row = $total_images; } $rows = ($total_images - $image_number) / $per_row; } # Round up if ($rows =~ /\./) { $rows =~ s/\..*//; $rows++; } # Row settings if ($per_row == 1) { $width1 = "100%"; } elsif ($per_row == 2) { $width1 = "49%"; $width2 = "*"; } elsif ($per_row == 3) { $width1 = "33%"; $width2 = "33%"; $width3 = "*"; } elsif ($per_row == 4) { $width1 = "24%"; $width2 = "25%"; $width3 = "25%"; $width4 = "*"; } elsif ($per_row == 5) { $width1 = "19%"; $width2 = "20%"; $width3 = "20%"; $width4 = "20%"; $width5 = "*"; } elsif ($per_row == 6) { $width1 = "16%"; $width2 = "17%"; $width3 = "17%"; $width4 = "17%"; $width5 = "17%"; $width6 = "*"; } my $show_row_count = 0; my $show_image_count = 0; my $max_count = 1; my $column_span = ($per_row * 2) - 1; my $last = $total_images - 1; if (($rows < $max_rows) && ($emAlbum{'page'} == 1)) { $max_rows = $rows; $pages_needed = 1; } elsif (($rows < $max_rows) && ($emAlbum{'page'} != 1)) { $max_rows = $rows; } my $page_link = "$text{'4'} "; if ($pages_needed == 1) { $page_link .= qq~ [$emAlbum{'page'}] ~; } elsif (($pages_needed > 1) && ($pages_needed < 9)) { $page_count = 1; if ($emAlbum{'page'} != 1) { $prev_page = $emAlbum{'page'} - 1; $prev_page_image = ($emAlbum{'page'} - 2) * $per_page; $page_link .= qq~$text{'9'} ~; } else { $page_link .= qq~ ~; } until ($page_count == $pages_needed) { if ($page_count == $emAlbum{'page'}) { $page_link .= qq~[$page_count] ~; } else { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$page_count ~; } $page_count++; } if ($emAlbum{'page'} == $pages_needed) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$pages_needed ~; $next_page = $emAlbum{'page'} + 1; $next_page_image = ($emAlbum{'page'}) * $per_page; $page_link .= qq~$text{'10'}~; } } elsif ($pages_needed >= 9) { $end_page = $emAlbum{'page'} + 2; $beg_page = $emAlbum{'page'} - 2; $start = $pages_needed - 4; if ($emAlbum{'page'} == 1) { $page_link .= qq~ [$emAlbum{'page'}] ~; $page_count = 2; until ($page_count > 3) { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$page_count ~; $page_count++; } $next_page_image = ($pages_needed - 1) * $per_page; $page_link .= qq~... $pages_needed ~; $next_page = $emAlbum{'page'} + 1; $next_page_image = ($emAlbum{'page'}) * $per_page; $page_link .= qq~$text{'10'}~; } elsif (($emAlbum{'page'} > 1) && ($emAlbum{'page'} < 5)) { $prev_page = $emAlbum{'page'} - 1; $prev_page_image = ($emAlbum{'page'} - 2) * $per_page; $page_link .= qq~$text{'9'} ~; $page_link .= qq~1 ~; $page_count = 2; until ($page_count > $end_page) { if ($emAlbum{'page'} == $page_count) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$page_count ~; } $page_count++; } if ($emAlbum{'page'} == $pages_needed) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($pages_needed - 1) * $per_page; $page_link .= qq~... $pages_needed ~; $next_page = $emAlbum{'page'} + 1; $next_page_image = ($emAlbum{'page'}) * $per_page; $page_link .= qq~$text{'10'}~; } } elsif (($emAlbum{'page'} >= 5) && ($emAlbum{'page'} <= $start)) { $prev_page = $emAlbum{'page'} - 1; $prev_page_image = ($emAlbum{'page'} - 2) * $per_page; $page_link .= qq~$text{'9'} ~; $page_link .= qq~1 ... ~; $page_count = $beg_page; until ($page_count > $end_page) { if ($emAlbum{'page'} == $page_count) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$page_count ~; } $page_count++; } if ($emAlbum{'page'} == $pages_needed) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($pages_needed - 1) * $per_page; $page_link .= qq~... $pages_needed ~; $next_page = $emAlbum{'page'} + 1; $next_page_image = ($emAlbum{'page'}) * $per_page; $page_link .= qq~$text{'10'}~; } } elsif (($emAlbum{'page'} > $start) && ($emAlbum{'page'} < $pages_needed)) { $prev_page = $emAlbum{'page'} - 1; $prev_page_image = ($emAlbum{'page'} - 2) * $per_page; $page_link .= qq~$text{'9'} ~; $page_link .= qq~1 ... ~; $page_count = $beg_page; until ($page_count == $pages_needed) { if ($emAlbum{'page'} == $page_count) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$page_count ~; } $page_count++; } if ($emAlbum{'page'} == $pages_needed) { $page_link .= qq~[$emAlbum{'page'}] ~; } else { $next_page_image = ($pages_needed - 1) * $per_page; $page_link .= qq~$pages_needed ~; $next_page = $emAlbum{'page'} + 1; $next_page_image = ($emAlbum{'page'}) * $per_page; $page_link .= qq~$text{'10'}~; } } elsif ($emAlbum{'page'} == $pages_needed) { $prev_page = $emAlbum{'page'} - 1; $prev_page_image = ($emAlbum{'page'} - 2) * $per_page; $page_link .= qq~$text{'9'} ~; $page_link .= qq~1 ... ~; $page_count = $pages_needed - 2; until ($page_count == $pages_needed) { $next_page_image = ($page_count - 1) * $per_page; $page_link .= qq~$page_count ~; $page_count++; } $page_link .= qq~[$emAlbum{'page'}] ~; } } $emAlbumMain = qq~ ~; $emAlbumHeader = qq~ $text{'6'} $emAlbum{'page'} $text{'7'} $pages_needed $page_link $text{'5'} $total_images ~; until ($show_row_count == $max_rows) { $per_cnt = 1; until ($show_image_count == $per_row) { $image = @images[$image_number]; if ($image =~ /(tiff|tif)$/i) { $filetype_link = "$image_url/tifffile.gif"; } elsif ($image =~ /(jpg|jpeg|jpe)$/i) { $filetype_link = "$image_url/jpegfile.gif"; } elsif ($image =~ /bmp$/i) { $filetype_link = "$image_url/bmpfile.gif"; } elsif ($image =~ /gif$/i) { $filetype_link = "$image_url/giffile.gif"; } elsif ($image =~ /png$/i) { $filetype_link = "$image_url/pngfile.gif"; } if ($thumb_extension ne "" ) { $image =~ s/(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$/$thumb_extension/i; } if ($thumbs_place == 0) { $test_thumb = "$thumbs_path$slash$prefix$image"; unless (-e $test_thumb) { $thumb_image_url = $filetype_link; } else { $thumb_image_url = "$thumbs_url/$prefix$image"; } } else { $test_thumb = "$thumbs_path$slash$emAlbum{'path'}$slash$prefix$image"; unless (-e $test_thumb) { $thumb_image_url = $filetype_link; } else { $thumb_image_url = "$thumbs_url$slash$emAlbum{'path'}$slash$prefix$image"; } } my $imageURL = qq~$text{'0'}~; if ($image_number >= $total_images) { $imageURL = "  "; } else { if ($per_row == 1) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 2) && ($per_cnt == 1)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 2) && ($per_cnt == 2)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 3) && ($per_cnt == 1)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 3) && ($per_cnt == 2)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 3) && ($per_cnt == 3)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 4) && ($per_cnt == 1)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 4) && ($per_cnt == 2)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 4) && ($per_cnt == 3)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 4) && ($per_cnt == 4)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 5) && ($per_cnt == 1)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 5) && ($per_cnt == 2)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 5) && ($per_cnt == 3)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 5) && ($per_cnt == 4)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 5) && ($per_cnt == 5)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 6) && ($per_cnt == 1)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 6) && ($per_cnt == 2)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 6) && ($per_cnt == 3)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 6) && ($per_cnt == 4)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 6) && ($per_cnt == 5)) { $emAlbumMain .= qq~ ~; } elsif (($per_row == 6) && ($per_cnt == 6)) { $emAlbumMain .= qq~ ~; } $emAlbumMain .= qq~ ~; if ($thumb_caption == 1) { $image_name = $image; if ($caption == 0) { $image_name = ""; } elsif ($caption == 2) { $image_name =~ s/\_/ /g; $image_name =~ s/\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$//i; } $emAlbumMain .= qq~ ~; } else { $emAlbumMain .= qq~ ~; } $emAlbumMain .= qq~
$imageURL
$image_name
~; if ((($per_cnt < $per_row) && ($emAlbum{'page'} != $last)) || (($per_cnt < $per_row) && ($emAlbum{'page'} == $last))) { $emAlbumMain .= qq~ ~; } $per_cnt++; } $show_image_count++; $image_number++; } $emAlbumMain .= qq~ ~; if ($max_count < $max_rows) { $emAlbumMain .= qq~ ~; } $show_image_count = 0; $show_row_count++; $max_count++; } $emAlbumMain .= qq~ ~; $emAlbumFooter = qq~   ~; # Finish up and display page &html; } sub slide_show { my $ss_image_path = "$album_path$slash$emAlbum{'path'}"; # Open the image directory and get the selected image opendir(SLI,"$ss_image_path") || &error("111|$ss_image_path"); my @slide_images = grep /\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$/i, sort readdir(SLI); #do not name images w/ a '.' closedir(SLI); my $display_number = $emAlbum{'img'} + 1; unless ($emAlbum{'img'}) { $emAlbum{'img'} = 0; $display_number = 1; } my $next_image = $emAlbum{'img'} + 1; my $display_image = @slide_images[$emAlbum{'img'}]; my $image_src = qq~$text{'1'}~; my $display_name = $display_image; my $total_images = @slide_images; if ($caption == 0) { $display_name = ""; } elsif ($caption == 2) { $display_name =~ s/\_/ /g; $display_name =~ s/\.(jpg|jpeg|jpe|bmp|gif|png|tiff|tif)$//i; } if ($emAlbum{'path'} =~ /\//) { ($main_folder,$folder) = split(/\//,$emAlbum{'path'}); $folder_name = $folder; $folder_name =~ s/\_/ /g; $main_folder_name = $main_folder; $main_folder_name =~ s/\_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } elsif ($emAlbum{'path'} =~ /\\/) { ($main_folder,$folder) = split(/\\/,$emAlbum{'path'}); $folder_name = $folder; $folder_name =~ s/\_/ /g; $main_folder_name = $main_folder; $main_folder_name =~ s/\_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $main_folder_name $text{'8'} $folder_name $text{'8'}~; } else { $folder = $emAlbum{'path'}; $folder_name = $folder; $folder_name =~ s/\_/ /g; $emAlbumNavigation = qq~$home_link$main_link $text{'8'} $folder_name $text{'8'}~; } $emAlbumMain = qq~
$image_src
$display_name
~; unless ($emAlbum{'speed'}) { $emAlbum{'speed'} = $default_speed; } if ($display_number >= $total_images) { $emAlbumSS = ""; $slide_link = qq~$text{'32'} ~; $slide_link .= qq~$text{'30'} ~; $slide_link .= qq~ ~; $slide_link .= qq~~; $slide_link .= qq~$text{'20'} ~; $slide_link .= qq~   $text{'29'} ~; $slide_link .= qq~~; $speed_info = "$text{'24'}"; } else { if ($emAlbum{'action'} eq "speed_up") { if ($emAlbum{'speed'} > 1) { $emAlbum{'speed'} = $emAlbum{'speed'} - 1; } else { $emAlbum{'speed'} = 1; } $emAlbumSS = qq~~; $slide_link = qq~$text{'32'} $text{'26'} ~; $slide_link .= qq~~; $slide_link .= qq~$text{'27'} ~; $slide_link .= qq~~; $slide_link .= qq~$text{'20'} ~; $slide_link .= qq~   $text{'29'} ~; $slide_link .= qq~$text{'22'} ~; $slide_link .= qq~ ~; $slide_link .= qq~$text{'21'} ~; $speed_info = qq~$emAlbum{'speed'} $text{'23'}~; } elsif ($emAlbum{'action'} eq "slow_down") { $emAlbum{'speed'} = $emAlbum{'speed'} + 1; $emAlbumSS = qq~~; $slide_link = qq~$text{'32'} $text{'26'} ~; $slide_link .= qq~~; $slide_link .= qq~$text{'27'} ~; $slide_link .= qq~~; $slide_link .= qq~$text{'20'} ~; $slide_link .= qq~   $text{'29'} ~; $slide_link .= qq~$text{'22'} ~; $slide_link .= qq~ ~; $slide_link .= qq~$text{'21'} ~; $speed_info = qq~$emAlbum{'speed'} $text{'23'}~; } elsif ($emAlbum{'action'} eq "play") { $emAlbumSS = qq~~; $slide_link = qq~$text{'32'} $text{'26'} ~; $slide_link .= qq~~; $slide_link .= qq~$text{'27'} ~; $slide_link .= qq~~; $slide_link .= qq~$text{'20'} ~; $slide_link .= qq~   $text{'29'} ~; $slide_link .= qq~$text{'22'} ~; $slide_link .= qq~ ~; $slide_link .= qq~$text{'21'} ~; $speed_info = qq~$emAlbum{'speed'} $text{'23'}~; } elsif ($emAlbum{'action'} eq "pause") { $emAlbumSS = ""; $slide_link = qq~$text{'32'} ~; $slide_link .= qq~$text{'19'} ~; $slide_link .= qq~ ~; $slide_link .= qq~~; $slide_link .= qq~$text{'20'} ~; $slide_link .= qq~   $text{'29'} ~; $slide_link .= qq~$text{'21'}~; $speed_info = qq~$text{'28'}~; } } $emAlbumHeader = qq~ $text{'14'} $display_number $text{'15'} $total_images $slide_link $speed_info ~; $emAlbumFooter = qq~ ~; &html; } sub html { $emAlbumCP = qq~ $text{'pb'} $text{'cp'} ~; # Open template open(TMP,$template_path); my @template = ; close(TMP); if (($text{'pb'} !~ /emAlbum/) || ($text{'cp'} !~ /emAlbum/)) { &error("112|"); } # Search template for triggers and put in data foreach $line (@template) { if ($line =~ "") { $line =~ s//$emAlbumSS/g; } if ($line =~ "") { $line =~ s//$title/g; } if ($line =~ "") { $line =~ s//$emAlbumNavigation/g; } if ($line =~ "") { $line =~ s//$emAlbumHeader/g; } if ($line =~ "") { $line =~ s//$emAlbumMain/g; } if ($line =~ "") { $line =~ s//$emAlbumFooter/g; } if ($line =~ "") { $line =~ s//$emAlbumCP/g; $cp = 1; } if ($line =~ "") { $line =~ s//$image_url/g; } } if ($cp != 1) { &error("113|<emAlbumCP>"); } # Display the page and exit the script print(@template); exit(0); } sub error { ($err) = @_; ($err_num,$err_msg) = split(/\|/,$err); if ($err == 100) { print qq~ emAlbum Error
$text{'err'}
 
$text{'err_code'} $err_num
$text{'err_msg'} $text{"$err_num"} $err_msg
 
$text{'err_rpt'} $text{'err_rpt1'} $text{'err_rpt2'}
~; } else { # Open template open(TMP,$template_path); my @template = ; close(TMP); $emAlbumNavigation = qq~
$main_link $text{'8'} $text{'err1'} $text{'8'}~; $emAlbumHeader = qq~ $text{'err'} ~; $emAlbumMain = qq~   $text{'err_code'} $err_num $text{'err_msg'} $text{"$err_num"} $err_msg   $text{'err_rpt'} $text{'err_rpt1'} $text{'err_rpt2'} ~; $emAlbumFooter = qq~  ~; $emAlbumCP = qq~ $text{'pb'} $text{'cp'} ~; foreach $line (@template) { if ($line =~ "") { $line =~ s///g; } if ($line =~ "") { $line =~ s//$title/g; } if ($line =~ "") { $line =~ s//$emAlbumNavigation/g; } if ($line =~ "") { $line =~ s//$emAlbumHeader/g; } if ($line =~ "") { $line =~ s//$emAlbumMain/g; } if ($line =~ "") { $line =~ s//$emAlbumFooter/g; } if ($line =~ "") { $line =~ s//$image_url/g; } } print(@template); } exit(0); }