#!/usr/bin/perl # Filename: simmer_theme # Author: David Ljung Madison # See License: http://MarginalHacks.com/License # Version: 1.16 # Description: Builds a theme based on: # 1) A group of icons following the same names of Dave Simmer's basic themes # 2) A Font and CREDIT file # # Documentation: Ha! # use strict; use Cwd 'abs_path'; my $PROGNAME = $0; my $THEME_DIRECTORY = "/Themes"; my $CONVERT = "convert"; my ($HEADER,$ALBUM,$IMAGE); # Image size sub get_size { my ($img) = @_; return (0,0) unless (-f $img); print STDERR "get_size() run: $CONVERT -verbose $img /dev/null\n" if ($MAIN::DEBUG); open(SIZE,"$CONVERT -verbose \Q$img\E /dev/null 2>&1 |") || die("[$PROGNAME] Couldn't run convert! [$CONVERT]\n"); while() { print STDERR "get_size(): $_" if ($MAIN::DEBUG); if(/\s(\d+)x(\d+)(\s|\+)/) { close(SIZE); return ($1,$2); } } print STDERR "[$PROGNAME] Can't get [$img] size from 'convert -verbose' output\n"; die("\n"); } my @SET; my @OPTIONS; my $CORNERS; sub get_img { my ($path,$img,$use_x,$use_y) = @_; my ($x,$y) = get_size("$path/$img"); return (0,0) unless $x && $y; $use_x = $use_x || $x; $use_y = $use_y || $y; my $arr = $img; $arr =~ s|\.[^\.]+$||; push(@SET, " \@$arr = (\"$img\", $use_x, $use_y);\n"); return ($x,$y); } sub fix_names { my ($path) = @_; sub my_rename { my ($path,$old,$new) = @_; rename("$path/$old","$path/$new") if (-f "$path/$old" && !-f "$path/$new"); } # Icons my_rename($path,"alb_bak.gif","Back.gif"); my_rename($path,"nav.gif", "Back.gif"); my_rename($path,"alb_mor.gif","More.gif"); my_rename($path,"alb_nam.gif","Icon.gif"); my_rename($path,"ico.gif", "Icon.gif"); my_rename($path,"alb_nex.gif","Next.gif"); my_rename($path,"alb_prv.gif","Prev.gif"); # Bar my_rename($path,"bar_lef.gif","Bar_L.gif"); my_rename($path,"bar_mid.gif","Bar_M.gif"); my_rename($path,"bar_rig.gif","Bar_R.gif"); # Thumbnail borders my_rename($path,"th_top.gif","ThBord_T.gif"); my_rename($path,"th_tlf.gif","ThBord_TL.gif"); my_rename($path,"th_trt.gif","ThBord_TR.gif"); my_rename($path,"th_bot.gif","ThBord_B.gif"); my_rename($path,"th_blf.gif","ThBord_BL.gif"); my_rename($path,"th_brt.gif","ThBord_BR.gif"); my_rename($path,"th_lef.gif","ThBord_L.gif"); my_rename($path,"th_ltp.gif","ThBord_LT.gif"); my_rename($path,"th_lbt.gif","ThBord_LB.gif"); my_rename($path,"th_rig.gif","ThBord_R.gif"); my_rename($path,"th_rtp.gif","ThBord_RT.gif"); my_rename($path,"th_rbt.gif","ThBord_RB.gif"); my_rename($path,"nul.gif","Null.gif"); my_rename($path,"spacer.gif","Null.gif"); print "Warning: Missing Null.gif\n" unless (-f "$path/Null.gif"); } sub get_settings { my ($path) = @_; my $name = abs_path($path); $name =~ s|.*/||; push(@SET, " # Path setting - this is the path to the images\n"); push(@SET, " \$PATH = Theme_URL();\n"); push(@SET, "\n"); if (open(FONT,"<$path/Font")) { while () { (/^\s*(#c)?\s*(\/\/)?\s*options?:\s*(\S.*)/i) ? push(@OPTIONS, $_) : push(@SET, $_); } close FONT; push(@SET, "\n"); } else { print "Warning: Missing $path/Font\n"; } push(@SET, " # Icons/graphics\n"); my ($blah,$bar_H) = get_img($path,"Bar_L.gif"); get_img($path,"Bar_M.gif",'"90%"'); get_img($path,"Bar_R.gif"); get_img($path,"Icon.gif"); get_img($path,"Back.gif"); get_img($path,"Next.gif"); get_img($path,"Prev.gif"); get_img($path,"More.gif"); #get_img($path,"Null.gif"); push(@SET, "\n"); push(@SET, " # Thumbnail border\n"); push(@SET, " \$X = Image_Page() ? Image_Width() : Get_Opt('x');\n"); push(@SET, " \$Y = Image_Page() ? Image_Height() : Get_Opt('y');\n"); my ($ltx,$lty) = get_img($path,"ThBord_LT.gif"); my ($rtx,$rty) = get_img($path,"ThBord_RT.gif"); my ($lbx,$lby) = get_img($path,"ThBord_LB.gif"); my ($rbx,$rby) = get_img($path,"ThBord_RB.gif"); my ($lx,$ly) = get_img($path,"ThBord_L.gif",undef,"\$Y-$lty-$lby"); my ($rx,$ry) = get_img($path,"ThBord_R.gif",undef,"\$Y-$rty-$rby"); my ($tlx,$tly) = get_img($path,"ThBord_TL.gif"); my ($trx,$try) = get_img($path,"ThBord_TR.gif"); my ($blx,$bly) = get_img($path,"ThBord_BL.gif"); my ($brx,$bry) = get_img($path,"ThBord_BR.gif"); get_img($path,"ThBord_T.gif","\$X+$lx+$rx-$tlx-$trx"); get_img($path,"ThBord_B.gif","\$X+$lx+$rx-$blx-$brx"); $CORNERS = $tlx ? 1 : 0; } sub can_simmer { # Auto generated by http://MarginalHacks.com/Hacks/album/simmer_theme my ($path) = @_; unless (-f "$path/album.th") { return 1 if -f "$path/th_top.gif"; return 1 if -f "$path/ThBord_T.gif"; return 0; } open(CHECK,"<$path/album.th") || return 0; my $simmered = grep(/Auto generated by .*simmer_theme/, ) ? 1 : 0; close(CHECK); $simmered; } sub album { my ($path) = @_; open(OUT,">$path/album.th") || die("Couldn't write $path/album.th"); print OUT @OPTIONS; print OUT $HEADER; print OUT @SET; print OUT $ALBUM; close OUT; } sub image { my ($path) = @_; open(OUT,">$path/image.th") || die("Couldn't write $path/image.th"); print OUT "#c// options: -image_sizes\n" if ($CORNERS); print OUT $HEADER; print OUT @SET; print OUT $IMAGE; close OUT; } sub main { my @themes = grep(-d $_, @ARGV); die("No theme args?") unless @themes; foreach my $path ( @themes ) { print "Theme: $path"; unless (can_simmer($path)) { print " [album.th is not a simmer_theme - skipping]\n"; next; } print "\n"; fix_names($path); get_settings($path); album($path); image($path); undef @SET; $CORNERS = 0; } } $HEADER = <<'END_OF_HEADER'; #c// ################################################################### #c// Album Theme by David Ljung Madison based on #c// generic SimmerTheme by Dave Simmer of DaveWeb.com #c// -- Auto generated by http://MarginalHacks.com/Hacks/album/simmer_theme #c// ################################################################### #c// <: # Image arrays are: name, width, height sub img_src { print "$_[4]" if ($_[1]); } END_OF_HEADER $ALBUM = <<'END_OF_ALBUM'; :>// #c// #c// ################################################################### #c// Everything beyond here is the same for the generic DaveWeb theme.. #c// ################################################################### <: # Shorthand for column info specified by -columns $Cols = Get_Opt('columns'); $Col_Perc = int(100/$Cols)."%"; :>// <: Meta() :> Album: <: pAlbum_Name() :> > <: if (isHeader()) { _:> <: } _:> #c// Are there more albums below this one? <: if (Child_Albums()) { _:> #c// Bar after child albums #c// #c// End if albums <: } :> #c// #c// The images <: if (Images()) { _:>// <: while (Images()) { _:>// <: if (!(Image_Cnt() % $Cols) && Images_Left()) { _:>// #c// #c// Start a new row <: } :> #c// #c// End image loop <: Next_Image(); } :>// <:}:>// <: if (isFooter()) { _:> <: } _:>
<:img_src("Null.gif",11,10):>
<:img_src(@Icon,"align='middle'"):>
>     <: pJoin_Parent_Albums(":"); :>
<: $back=Back(); if ($back && $back ne "''") { print ""; @Back ? img_src(@Back,"align='middle'") : print "

Back

"; print "
\n"; } :>

<:pHeader():>
<:img_src(@Bar_L); img_src(@Bar_M); img_src(@Bar_R);:>
<:img_src("Null.gif",20,10):>
<: if (@More) { :> <: } else { :> <: } :> #c// #c// Loop on all the albums <: while (Child_Albums()) { _:> <: Next_Child_Album(); # Start a new row after we use up $Cols if (!(Child_Album_Cnt() % $Cols) && Child_Albums_Left()) { _:> <: } } # End child album loop :>
<:img_src(@More):>

More albums:

><: pChild_Album() :>
<:img_src(@Bar_L); img_src(@Bar_M); img_src(@Bar_R);:>
<: if (@ThBord_LB) { _:> #c// The thumbnail is a complicated table for handling all the corners...
<:img_src(@ThBord_TL):><:img_src(@ThBord_T):><:img_src(@ThBord_TR):>
<:img_src(@ThBord_LT):> > alt=<:=Image_Alt():> width='<:=Get_Opt('x'):>' height="<:=Get_Opt('y'):>" border="0"> <:img_src(@ThBord_RT):>
<:img_src(@ThBord_L):> <:img_src(@ThBord_R):>
<:img_src(@ThBord_LB):> <:img_src(@ThBord_RB):>
<:img_src(@ThBord_BL):><:img_src(@ThBord_B):><:img_src(@ThBord_BR):>
<: } else { _:> <:img_src(@ThBord_TL):><:img_src(@ThBord_T):><:img_src(@ThBord_TR):>
<:img_src(@ThBord_L):>><:pImage_Thumb_Src():><:img_src(@ThBord_R):>
<:img_src(@ThBord_BL):><:img_src(@ThBord_B):><:img_src(@ThBord_BR):>
<: } _:> > > <:=Image_Name():>
<:pImage_Caption():>
<:img_src("Null.gif",20,20):>
<:img_src("Null.gif",20,20):>
<:img_src(@Bar_L); img_src(@Bar_M); img_src(@Bar_R);:>

<:pFooter():>
<:img_src(@Bar_L); img_src(@Bar_M); img_src(@Bar_R);:>
><: Credit() :> on <:=scalar localtime:>

END_OF_ALBUM $IMAGE = <<'END_OF_IMAGE'; :>// #c// #c// Everything beyond here is the same for the generic DaveWeb image theme.. <: Meta() :> Image: <:=Image_Name() :> > <:img_src("Null.gif",1,10):>
<:img_src(@Icon,"align='middle'"):>
>     <: pJoin_Parent_Albums(":"); :>
<:img_src(@Bar_L); img_src(@Bar_M); img_src(@Bar_R);:>

#c// #c// Prev/caption/next #c//
<: Set_Image_Prev() :>// PREV > <: Set_Image_This() :>// CAPTION
> > <:=Image_Name():>
> <:pImage_Caption():>
<: Set_Image_Next() :>// NEXT >
<: Set_Image_This() :>// #c// #c// The image #c//

#c// All corners <: if (@ThBord_LB) { _:>
<:img_src(@ThBord_TL):><:img_src(@ThBord_T):><:img_src(@ThBord_TR):>
<:img_src(@ThBord_LT):> ><:pImage_Src():> <:img_src(@ThBord_RT):>
<:img_src(@ThBord_L):> <:img_src(@ThBord_R):>
<:img_src(@ThBord_LB):> <:img_src(@ThBord_RB):>
<:img_src(@ThBord_BL):><:img_src(@ThBord_B):><:img_src(@ThBord_BR):>
#c// Two corners <: } elsif (@ThBord_TL) { _:> <:img_src(@ThBord_TL):><:img_src(@ThBord_T):><:img_src(@ThBord_TR):>
<:img_src(@ThBord_L):>><:pImage_Src():><:img_src(@ThBord_R):>
<:img_src(@ThBord_BL):><:img_src(@ThBord_B):><:img_src(@ThBord_BR):>
#c// No corners <: } else { _:> ><:pImage_Src():>
<: } _:>
<:img_src("Null.gif",20,20):>
<:img_src(@Bar_L); img_src(@Bar_M); img_src(@Bar_R);:>
><: Credit() :> on <:=scalar localtime:>

END_OF_IMAGE main();