Album

 view release on metacpan or  search on metacpan

script/album  view on Meta::CPAN

    # Format for journal pages (mostly).
    #
    # Variables:
    #
    #  $title
    #  $tag
    #  $vbuttons / $hbuttons
    #  $journal
    #  $jscript

    $format_for{journal} = $load->("journal.fmt", heredoc(<<'    EOD', 4));
    <?xml version="1.0" encoding="iso-8859-15"?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <!-- ALBUM-FMT-VERSION: 2.0 -->
    <html>
      <head>
	<title>$title</title>
        $css
	$jscript
      </head>
      <body>
	<table class='outer'>
	  <tr class='grey'>
	    <td>
	      <p class='hdl'>
		$tag
	      </p>
	    </td>
	    <td class='buttons'>
	      $hbuttons
	    </td>
	  </tr>
	  $journal
	  <tr class='grey'>
	    <td></td>
	    <td class='buttons'>
	      $hbuttons
	    </td>
	  </tr>
	</table>
      </body>
    </html>
    EOD

    print STDERR ("\n") if $did;
}

sub process_fmt {
    my ($fmt, %map) = @_;
    # THIS DOES ONLY ONE SUBST PER LINE
    $fmt =~ s/^(.*?)\$(\w+)\b/$1.indent($map{$2}, length($1))/gme;
    $fmt;
}

################ Style Sheets ################

my %css_for;

sub init_stylesheets {

    my $css_fontfam = "font-family: Verdana, Arial, Helvetica";
    my $WHITE = "#FFFFFF";
    my $BLACK = "#000000";
    my $RED   = "#FF0000";
    my $LGREY = "#E0E0E0";
    my $MGREY = "#D0D0D0";
    my $DGREY = "#C0C0C0";
    my $DDGREY = "#B0B0B0";
    my $BLUE  = "#0000FF";
    # Grey variants for index table borders.
    my $GR245 = "#F5F5F5";
    my $GR232 = "#E8E8E8";
    my $GR124 = "#7C7C7C";
    my $GR114 = "#727272";

    my $helper = $thumb + 4;

    my $did = 0;
    my $load = sub {
	my ($req, $data) = @_;
	my $css = d_css($req.".css");
	if ( -r $css ) {
	    my $major = $css_major;
	    my $minor = $css_minor;
	    my $orig;
	    if ( open(my $orig, "<", d_fmt("$req.fmt")) ) {
		my $line = <$orig>;
		close($orig);
		if ( $line =~ m;/\*\s*album-fmt-version:\s*(\d+)\.(\d+)\s*\*/;i ) {
		    ($major, $minor) = ($1, $2);
		}
	    }
	    # Check stylesheet compatibility.
	    open($orig, "<", $css);
	    my $line = <$orig>;
	    close($orig);
	    if ( $line =~ m;/\*\s*album-css-version:\s*(\d+)\.(\d+)\s*\*/;i ) {
		if ( $1 == $major ) {
		    return "";
		}
	    }
	    print STDERR "\n" if $did;
	    die(heredoc(<<"            EOD", 8));
	    *************************************************************************
	    Existing style sheet $req.css is not compatible with this version.
	    It has probably been created by an older version of this program, or it
	    has been modified manually.

	    If you did not change any style sheets, just remove the css directory and
	    try again.

	    If you did modify the style sheets move them away to a backup location,
	    run the program with '--extcss', and apply your changes to the new style
            sheets.
	    *************************************************************************
            EOD
	}
	elsif ( $externalize_css ) {
	    unless ( $did ) {
		my $fdir = d_css("");
		$fdir =~ s/\/+$//;
		unless ( -d $fdir ) {
		    print STDERR ("mkdir $fdir\n");
		    mkdir(d_css(""));
		}
	    }
	    print STDERR ("Creating stylesheets: ") if $verbose > 1 && !$did++;
	    print STDERR ("$req ") if $verbose > 1;
	    open (my $fh, '>', $css) || die("$css: $!\n");
	    print { $fh } $data;
	    close($fh);
	}
	$data =~ s/^([ \t]+)/detab($1)/gem;
	$data;
    };

    my $css_for_common = heredoc(<<"    EOD", 0);

    body {
	$css_fontfam;
	font-size:  80%;
	text: $BLACK;
    }

    a:link {
	color: $BLACK; text-decoration: none;
    }
    a:visited {
	color: $BLACK; text-decoration: none;
    }
    a:active {
	color: $RED; text-decoration: none;
    }

    img.image {
	border: 2px solid $BLACK;
    }

    img.button {
	border: 0;
	vertical-align: top;
    }

    table.vb {
	border: 0;
	border-spacing: 0 0;
    }
    table.vb td {
	padding: 0 0 0 0;
    }
    table.hb {
	border: 0;
	border-spacing: 0 0;
    }
    table.hb td {
	padding: 0 0 0 0;
    }
    EOD

    my $css_for_ipage = heredoc(<<"    EOD", 0);
    $css_for_common
    body {
	background: $DGREY;
    }
    td {
	font-size:  80%;
    }
    p.hdl, p.hdr {
	font-size: 140%; font-weight: bold;
	margin-top: 0; margin-bottom: 0;
    }
    p.ftl, p.ftr {
	font-size:  80%;
	margin-top: 0; margin-bottom: 0;
    }
    td.topleft {
	text-align: left;
	vertical-align: top;
    }
    td.topright {
	text-align: right;
	vertical-align: top;
    }
    td.image {
	text-align: center;
	vertical-align: top;
    }
    td.botleft {
	text-align: left;
	vertical-align: top;
    }
    td.botright {
	text-align: right;
	vertical-align: top;
    }
    td.vbuttons {
	vertical-align: top;
    }
    EOD

    $css_for{index} = $load->("index", heredoc(<<"    EOD", 4));
    /* ALBUM-CSS-VERSION: ${css_major}.${css_minor} */
    $css_for_ipage
    a.info {
	position: relative; z-index: 24; background-color: $LGREY;
	color: $BLACK; text-decoration:none;
    }
    a.info:hover {
	z-index: 25; background-color: $LGREY;
    }
    a.info:hover span {
	display: block;
	position: absolute; top: 2em; left: 2em; width: 25em;
	border: 0px; background-color: $MGREY; color: $BLACK;
	text-align: center;
    }
    a.info span {
	display: none;
    }
    table.outer {
	background: $MGREY;
	border-collapse: separate;
	border-width: 2px;           /* border=2 */
	border-style: solid;
	border-color: $GR232 $GR114 $GR114 $GR232;
	border-spacing: 3px;        /* cellspacing = 3 */
    }
    table.outer tr {
	background: $LGREY;
    }
    table.outer td {
	border-width: 1px;
	border-style: solid;
	border-color: $GR124 $GR245 $GR245 $GR124;
    }
    table.inner {
	/* need a width otherwise we cannot center it */
	width: ${helper}px;
	border: outset 0px;
    }
    table.inner td {
	border: inset 0px;
        padding: 0 0 0 0;
    }
    p.hdr {
	font-size: 140%; font-weight: bold;
	margin-top: 0; margin-bottom: 0;
    }
    p.hdr a:link {
	color: $BLACK; text-decoration: underline;
    }
    p.hdr a:visited {
	color: $BLACK; text-decoration: underline;
    }
    p.hdr a:hover {
	color: $RED; text-decoration: underline;
    }
    td.vimage {
	vertical-align: top;
    }
    td.oimg {
	text-align: center;
	vertical-align: bottom;
    }
    td.iimg {
	text-align: center;
    }
    td.itxt {
	text-align: center;
    }
    img.thumb {
	border: 0;
    }
    EOD

    my $css_for_image = heredoc(<<"    EOD", 4);
    /* ALBUM-CSS-VERSION: ${css_major}.${css_minor} */
    $css_for_ipage
    a.info {
	position: relative; z-index: 24; background-color: $DGREY;
	color:$BLACK; text-decoration:none;
    }
    a.info:hover {
	z-index: 25; background-color: $DGREY;
    }
    a.info span {
	display: none;
    }
    a.info:hover span {
	display: block;
	position: absolute; top:2em; left: 2em; width: 15em;
	border: 0px; background-color: $MGREY; color: $BLACK;
	text-align: center;
    }
    EOD

    $css_for{large}   = $load->("large",   $css_for_image);
    $css_for{medium}  = $load->("medium",  $css_for_image);

    $css_for{journal} = $load->("journal", heredoc(<<"    EOD", 4));
    /* ALBUM-CSS-VERSION: ${css_major}.${css_minor} */
    $css_for_common
    body {
	font-size: 100%;
	background: $WHITE;
    }
    td {
	font-size:  100%;
    }
    p.hdl {
	font-size: 140%; font-weight: bold;
	margin-left: 0.1in; margin-top: 0.1in; margin-bottom: 0.1in;
    }

    table.outer {
	width: 600px;
	border-spacing: 10px;
    }
    tr.grey {
	background: $DGREY;
    }
    table.outer td.twocol {
	vertical-align: top;
	text-align: left;
    }
    table.outer td.jl {
	vertical-align: top;
	text-align: left;
    }
    table.outer td.jr {
	width: ${thumb}px;
	vertical-align: top;
        text-align: center;
        background: $LGREY;
    }
    table.outer td.buttons {
	vertical-align: middle;
	text-align: right;
	padding-right: 0.1in;
    }
    EOD

    $css_for{main} = $load->("main", heredoc(<<"    EOD", 4));
    /* ALBUM-CSS-VERSION: ${css_major}.${css_minor} */
    body {
        $css_fontfam;
        font-size:  80%;
        background: $LGREY;
        background-image: url("icons/bg.jpg");
        background-repeat: no-repeat;
        background-position: 10% 60%;
    }
    p.ftr {
        padding-left: 10%;
        padding-top: 40%;
        font-size:  80%;
        text-align: left;
        color: $DDGREY;
    }
    p.indextitle {
        padding-left: 10%;
        font-size: 500%;
        font-weight: bold;
        color: $WHITE;
    }
    p.indextitle a {
        text-decoration: none;
        color: $WHITE;
    }
    EOD
}

sub css_for {
    my ($type) = shift(@_);
    defined(my $css = $css_for{$type}) or die("PROGRAM ERROR: css_for($type)");
    return qq{<link rel="stylesheet" href="}.d_up(d_css($type.".css")).qq{">}
      unless $css;
    qq{<style type=\"text/css\">\n} . $css . qq{</style>};
}

################ Helpers for Image/Index/Journal pages ################

sub jscript {
    my (%nav) = @_;
    my $next = $nav{next};
    my $prev = $nav{prev};
    my $up   = $nav{up};
    my $down = $nav{down};
    my $idx  = $nav{idx};
    my $jnl  = $nav{jnl};
    my $js = heredoc(<<"    EOD", 4);
    <script type='text/javascript'>
    function handleKey(e) {
      var key;
      if ( e == null ) { // IE
	key = event.keyCode
      }
      else { // Mozilla
	if ( e.altKey || e.ctrlKey ) {
	  return true
	}
	key = e.which
      }
      switch(key) {
    EOD

    $js .= "    case   8: window.location = '$prev'; break // Backspace\n" if $prev;
    $js .= "    case  32: window.location = '$next'; break // Space\n"     if $next;
    $js .= "    case  13: window.location = '$down'; break // Enter\n"     if $down;
    $js .= "    case  43: window.location = '$down'; break // '+'\n"       if $down;
    $js .= "    case 117: window.location = '$up'; break // 'u'\n"         if $up;
    $js .= "    case  45: window.location = '$up'; break // '-'\n"         if $up;
    $js .= "    case 100: window.location = '$idx'; break // 'd'\n"        if $idx;
    $js .= "    case 106: window.location = '$jnl'; break // 'j'\n"        if $jnl;

    $js .= heredoc(<<"    EOD", 4);
       default:
      }
      return false
    }
    
    document.onkeypress = handleKey
    </script>



( run in 1.394 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )