summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-05-04 09:48:27 -0700
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-05-04 09:48:27 -0700
commit247f5d615539784c46b5c7c5b35b6ee348e04151 (patch)
tree6744bd1584ad1239417e4c8e148f98d1d27909eb
initial commitHEADmaster
-rw-r--r--.gitignore4
-rw-r--r--.htaccess1
-rw-r--r--Makefile46
-rw-r--r--gen.sh12
-rw-r--r--index.php22
-rw-r--r--issue.php52
-rw-r--r--main.php19
-rw-r--r--view.coffee54
-rw-r--r--view.scss41
9 files changed, 251 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5972c16
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*/
+*.css
+*.html
+*.js
diff --git a/.htaccess b/.htaccess
new file mode 100644
index 0000000..47b11e6
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1 @@
+Header unset Last-Modified
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2f9fab4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,46 @@
+Makefiles += gen.sh
+pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
+pick = $(firstword $(foreach prog,$1,$(call pathsearch,$(prog))) false)
+
+COFFEE = coffee
+CONVERT = convert
+CP = cp
+MKDIRS = mkdir -p
+PHP = $(call pick,php5 php)
+RM = rm -f
+SASS = sass
+
+PDF2PPM = pdftoppm
+PDF2TXT = pdftotext
+PHP2ANY = $(PHP) -f
+PPM2JPG = ppmtojpeg
+SCSS2CSS = $(SASS)
+
+all: PHONY
+ echo */|sed 's@/\s*@\n@g'|sort -n|xargs bash gen.sh
+
+.SECONDARY:
+
+%.ppm: %.pdf $(MAKEFILES)
+ $(PDF2PPM) '$<' > '$@'
+%.jpg: %.ppm $(MAKEFILES)
+ $(PPM2JPG) '$<' > '$@'
+%.txt: %.pdf $(MAKEFILES)
+ $(PDF2TXT) '$<' > '$@'
+%: %.php $(MAKEFILES)
+ $(PHP2ANY) '$<' > '$@'
+%.css: %.scss $(MAKEFILES)
+ $(SCSS2CSS) '$<' > '$@'
+%.js: %.coffee $(MAKEFILES)
+ $(COFFEE) -c '$<'
+%.small.jpg: %.jpg $(MAKEFILES)
+ $(CONVERT) '$<' -resize x700 '$@'
+
+%/index.php: issue.php $(MAKEFILES)
+ $(CP) '$<' '$@'
+%/view.css: view.css $(MAKEFILES)
+ $(CP) '$<' '$@'
+%/view.js: view.js $(MAKEFILES)
+ $(CP) '$<' '$@'
+
+.PHONY: PHONY \ No newline at end of file
diff --git a/gen.sh b/gen.sh
new file mode 100644
index 0000000..519b2a6
--- /dev/null
+++ b/gen.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+make view.js view.css
+for issue in "$@"; do
+ echo "=> making issue $issue"
+ {
+ list=`echo $issue/{index.php,view.css,view.js}`
+ list+=' '
+ list+=`ls -1 $issue/Page*.pdf|sed -r 's/(.*)\.pdf$/\1.jpg \1.small.jpg/'`
+ make $list
+ } 2>&1|sed 's/./ &/'
+done
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..f148923
--- /dev/null
+++ b/index.php
@@ -0,0 +1,22 @@
+<?php
+require_once('../wp-load.php');
+get_header(); ?>
+
+ <div id="primary">
+ <div id="content" role="main">
+
+ <article id="post-0" class="post">
+ <header class="entry-header">
+ <h1 class="entry-title"><?php _e( 'Online issues', 'twentyeleven' ); ?></h1>
+ </header><!-- .entry-header -->
+
+ <div class="entry-content">
+ <?php require('main.php'); ?>
+ </div><!-- .entry-content -->
+ </article><!-- #post-0 -->
+
+ </div><!-- #content -->
+ </div><!-- #primary -->
+
+<?php get_sidebar(); ?>
+<?php get_footer(); ?>
diff --git a/issue.php b/issue.php
new file mode 100644
index 0000000..3a3ed6f
--- /dev/null
+++ b/issue.php
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<?php
+function page($page, $count=1) {
+ if (file_exists("Page${page}.pdf")) {
+ echo "<td id='page${page}' class='pages-${count}' colspan='${count}'>";
+ echo "<img src='Page${page}.small.jpg' />";
+ echo "</td>\n";
+ } else {
+ echo "<td class='pages-${count} filler'> </td>\n";
+ }
+}
+
+function pages($first, $last) {
+ if (file_exists("Pages${first}-${last}.pdf")) {
+ page("s${first}-${last}", ($last-$first)+1);
+ } else {
+ $exists = false;
+ for ($i=$first; $i<=$last; $i++) {
+ $exists |= file_exists("Page${i}.pdf");
+ }
+ if ($exists) {
+ for ($i=$first; $i<=$last; $i++) {
+ page($i);
+ }
+ } else {
+ return false;
+ }
+ }
+ return true;
+}
+
+?>
+<html dir="ltr" lang="en-US">
+ <head>
+ <meta charset="UTF-8" />
+ <title>North Star issue <?php echo basename(dirname(__FILE__)) ?></title>
+ <link rel="stylesheet" href="view.css" .>
+ <script type="text/javascript" src="/wp-includes/js/jquery/jquery.js?ver=1.7.1"></script>
+ <script type="text/javascript" src="view.js"></script>
+ </head>
+ <body>
+ <div class="menu">Please give the paper a moment to load.</div>
+ <div class="spacer"> </div>
+ <table class="paper">
+ <?php $i=0; $still_going=true; while ($still_going) { ?>
+ <tr>
+ <?php $still_going = pages($i, $i+1); $i+=2; ?>
+ </tr>
+ <?php } ?>
+ </table>
+ </body>
+</html>
diff --git a/main.php b/main.php
new file mode 100644
index 0000000..b7e1fe0
--- /dev/null
+++ b/main.php
@@ -0,0 +1,19 @@
+<?php
+$dh = opendir('.');
+echo "<ul>";
+$files = glob('*');
+sort($files, SORT_NUMERIC);
+foreach ($files as $file) {
+ if (is_dir($file) && (substr($file,0,1)!='.')) {
+ echo "<li><a href='$file'>";
+ if (is_numeric($file)) {
+ echo "Issue $file";
+ } else {
+ echo "$file issue";
+ }
+ echo "</a></li>";
+ }
+}
+closedir($dh);
+echo "</ul>";
+
diff --git a/view.coffee b/view.coffee
new file mode 100644
index 0000000..8987630
--- /dev/null
+++ b/view.coffee
@@ -0,0 +1,54 @@
+$ = jQuery
+
+toReplace = 0
+replaced = 0
+
+class imageReplacer
+ constructor: (@orig, @src) ->
+ @replacement = new Image()
+ @replacement.onload = @replace
+ @replacement.src = @src
+ toReplace++
+ @updateText()
+ replace: =>
+ $(@orig).replaceWith(@replacement)
+ replaced++
+ @updateText()
+ updateText: =>
+ if ((toReplace-replaced)>0)
+ $('.loading').text('Please be patient, loading high-quality images ('+replaced+'/'+toReplace+')')
+ else
+ $('.loading').text('')
+
+loadHighRes = ->
+ images = $('img')
+ for image in images
+ new imageReplacer(image, image.src.replace('.small.', '.'))
+
+zoomIn = ->
+ width = $('.paper').width()
+ $('.paper').width(width*1.1)
+
+zoomOut = ->
+ width = $('.paper').width()
+ $('.paper').width(width*(1/1.1))
+
+fitPageHeight = ->
+ page_height = $('.paper img').height()
+ page_width = $('.paper img').width()
+ window_height = $(window).height() - $('.menu').height()
+ # We now want to set page_height=window_height, but through page_width
+ $('.paper').width(window_height*(2*page_width/page_height))
+
+updatePageNumber = ->
+
+
+$ ->
+ menu = $('.menu').text('')
+ $('<button>').text("Zoom Out").click(zoomOut).appendTo(menu)
+ $('<button>').text("Zoom In").click(zoomIn).appendTo(menu)
+ $('<button>').text("Fit Page Height").click(fitPageHeight).appendTo(menu)
+ $('<div>').addClass('loading').appendTo(menu)
+ $('.spacer').height(menu.height())
+ $('.paper').scroll(updatePageNumber)
+ loadHighRes()
diff --git a/view.scss b/view.scss
new file mode 100644
index 0000000..9771f22
--- /dev/null
+++ b/view.scss
@@ -0,0 +1,41 @@
+body {
+ margin: 0;
+ padding: 0;
+ background-color: #999999;
+}
+.menu {
+ position: fixed;
+ background-color: #557755;
+ width: 100%;
+ text-align: center;
+}
+table.paper {
+ width: 12.75in; /* one page width, so 50% actual size */
+ border: 0;
+ padding: 0;
+ margin: 0 auto;
+ background: transparent;
+ td {
+ border: 0;
+ padding: 0;
+ margin: 0;
+ &.pages {
+ /*display: inline;*/
+ margin: 0;
+ padding: 0;
+ padding-bottom: 1em;
+ }
+ &.pages-1 {
+ @extend .pages;
+ width: 50%;
+ }
+ &.pages-2 {
+ @extend .pages;
+ width: 100%;
+ }
+ img {
+ width: 100%;
+ height: auto;
+ }
+ }
+}