Permalink
Browse files

Merge pull request #50 from bdolor/epub3

Epub 3 support, props @bdolor.
  • Loading branch information...
greatislander committed Apr 16, 2014
2 parents a46b26c + 821aed7 commit c564bcdc4d9ee0fc61d47ddf522d5dcdab78438e
@@ -62,12 +62,15 @@
<?php }
foreach ( $exports as $file ) {
$file_extension = substr( strrchr( $file, '.' ), 1 );
$pre_suffix = strstr( $file, '._3.epub' );
if ( 'html' == $file_extension )
if ( 'html' == $file_extension )
$file_class = 'xhtml';
elseif ( 'xml' == $file_extension )
$file_class = 'wxr';
else
elseif ( 'epub' == $file_extension && '._3.epub' == $pre_suffix )
$file_class = 'epub3';
else
$file_class = $file_extension;
?>
@@ -97,6 +100,7 @@
$options = get_option('export_formats');
if ( ! isset( $options['pdf'] ) ) { $options['pdf'] = 1; }
if ( ! isset( $options['epub'] ) ) { $options['epub'] = 1; }
if ( ! isset( $options['epub3'] ) ) { $options['epub3'] = 1; }
if ( ! isset( $options['mobi'] ) ) { $options['mobi'] = 1; }
if ( ! isset( $options['hpub'] ) ) { $options['hpub'] = 0; }
if ( ! isset( $options['icml'] ) ) { $options['icml'] = 0; }
@@ -113,6 +117,7 @@
<fieldset>
<legend>Exotic formats:</legend>
<input type="checkbox" id="epub3" name="export_formats[epub3]" value="1" <?php checked(1, $options['epub3'], false); ?>/><label for="epub3"> <?php _e( 'EPUB 3 (Experimental)', 'pressbooks' ); ?></label><br />
<input type="checkbox" id="hpub" name="export_formats[hpub]" value="1" <?php checked(1, $options['hpub'], false); ?>/><label for="hpub"> <?php _e( 'Hpub', 'pressbooks' ); ?></label><br />
<input type="checkbox" id="icml" name="export_formats[icml]" value="1" <?php checked(1, $options['icml'], false); ?>/><label for="icml"> <?php _e( 'ICML (for InDesign)', 'pressbooks' ); ?></label><br />
<input type="checkbox" id="xhtml" name="export_formats[xhtml]" value="1" <?php checked(1, $options['xhtml'], false); ?>/><label for="xhtml"> <?php _e( 'XHTML', 'pressbooks' ); ?></label><br />
@@ -365,6 +365,10 @@ a.toplevel_page_pb_sell > .wp-menu-image:before {
background: url(../images/epub-36.png) -0 0 no-repeat;
}
.export-page form.export-file span.export-file-icon.small.epub3 {
background: url(../images/epub3-36.png) -0 0 no-repeat;
}
.export-page form.export-file span.export-file-icon.small.hpub {
background: url(../images/hpub-36.png) -0 0 no-repeat;
}
@@ -393,6 +397,10 @@ a.toplevel_page_pb_sell > .wp-menu-image:before {
background: url(../images/epub-48.png) -0 0 no-repeat;
}
.export-page form.export-file span.export-file-icon.large.epub3 {
background: url(../images/epub3-48.png) -0 0 no-repeat;
}
.export-page form.export-file span.export-file-icon.large.hpub {
background: url(../images/hpub-48.png) -0 0 no-repeat;
}
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -18,6 +18,7 @@
require( PB_PLUGIN_DIR . 'includes/pb-redirect.php' );
require( PB_PLUGIN_DIR . 'includes/pb-sanitize.php' );
require( PB_PLUGIN_DIR . 'includes/pb-taxonomy.php' );
require( PB_PLUGIN_DIR . 'includes/pb-media.php' );
require( PB_PLUGIN_DIR . 'symbionts/pb-latex/pb-latex.php' );
// -------------------------------------------------------------------------------------------------------------------
@@ -51,6 +52,12 @@
add_action( 'delete_attachment', '\PressBooks\Image\delete_attachment' );
add_filter( 'wp_update_attachment_metadata', '\PressBooks\Image\save_attachment', 10, 2 );
// -------------------------------------------------------------------------------------------------------------------
// Audio/Video
// -------------------------------------------------------------------------------------------------------------------
add_filter('upload_mimes', '\PressBooks\Media\addMimeTypes');
// -------------------------------------------------------------------------------------------------------------------
// Custom Post Types and Taxonomies
// -------------------------------------------------------------------------------------------------------------------
@@ -507,6 +507,9 @@ static function formSubmit() {
if ( isset( $x['epub'] ) ) {
$modules[] = '\PressBooks\Export\Epub\Epub201'; // Must be set before MOBI
}
if ( isset( $x['epub3'] ) ) {
$modules[] = '\PressBooks\Export\Epub3\Epub3'; // Must be set before MOBI
}
if ( isset( $x['mobi'] ) ) {
$modules[] = '\PressBooks\Export\Mobi\Kindlegen'; // Must be set after EPUB
}
@@ -122,7 +122,24 @@ class Epub201 extends Export {
*/
protected $compressImages = false;
/**
* @var string
*/
protected $filext = 'html';
/**
* $var string
*/
protected $dir = __DIR__;
/**
* $var string
*/
protected $suffix = '.epub';
/**
* @param array $args
*/
@@ -193,7 +210,7 @@ function convert() {
return false;
}
$filename = $this->timestampedFileName( '.epub' );
$filename = $this->timestampedFileName( $this->suffix );
if ( ! $this->zipEpub( $filename ) ) {
return false;
}
@@ -467,11 +484,11 @@ protected function createContainer() {
file_put_contents(
$this->tmpDir . '/META-INF/container.xml',
$this->loadTemplate( __DIR__ . '/templates/container.php' ) );
$this->loadTemplate( $this->dir . '/templates/container.php' ) );
file_put_contents(
$this->tmpDir . '/META-INF/com.apple.ibooks.display-options.xml',
$this->loadTemplate( __DIR__ . '/templates/ibooks.php' ) );
$this->loadTemplate( $this->dir. '/templates/ibooks.php' ) );
}
@@ -663,11 +680,11 @@ protected function createCover( $book_contents, $metadata ) {
);
$file_id = 'front-cover';
$filename = "{$file_id}.html";
$filename = "{$file_id}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => -1,
@@ -723,11 +740,11 @@ protected function createBeforeTitle( $book_contents, $metadata ) {
'' );
$file_id = 'front-matter-' . sprintf( "%03s", $i );
$filename = "{$file_id}-{$slug}.html";
$filename = "{$file_id}-{$slug}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => $front_matter['ID'],
@@ -791,11 +808,11 @@ protected function createTitle( $book_contents, $metadata ) {
);
$file_id = 'title-page';
$filename = "{$file_id}.html";
$filename = "{$file_id}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => -1,
@@ -845,11 +862,11 @@ protected function createCopyright( $book_contents, $metadata ) {
);
$file_id = 'copyright';
$filename = "{$file_id}.html";
$filename = "{$file_id}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => - 1,
@@ -906,11 +923,11 @@ protected function createDedicationAndEpigraph( $book_contents, $metadata ) {
'' );
$file_id = 'front-matter-' . sprintf( "%03s", $i );
$filename = "{$file_id}-{$slug}.html";
$filename = "{$file_id}-{$slug}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => $front_matter['ID'],
@@ -990,11 +1007,11 @@ protected function createFrontMatter( $book_contents, $metadata ) {
'' );
$file_id = 'front-matter-' . sprintf( "%03s", $i );
$filename = "{$file_id}-{$slug}.html";
$filename = "{$file_id}-{$slug}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => $front_matter['ID'],
@@ -1019,7 +1036,7 @@ protected function createPromo( $book_contents, $metadata ) {
if ( $promo_html ) {
$file_id = 'pressbooks-promo';
$filename = "{$file_id}.html";
$filename = "{$file_id}.{$this->filext}";
$vars = array(
'post_title' => __( 'Make your own books using PressBooks.com', 'pressbooks' ),
@@ -1030,7 +1047,7 @@ protected function createPromo( $book_contents, $metadata ) {
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => -1,
@@ -1132,11 +1149,11 @@ protected function createPartsAndChapters( $book_contents, $metadata ) {
'' );
$file_id = 'chapter-' . sprintf( "%03s", $j );
$filename = "{$file_id}-{$slug}.html";
$filename = "{$file_id}-{$slug}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => $chapter['ID'],
@@ -1166,11 +1183,11 @@ protected function createPartsAndChapters( $book_contents, $metadata ) {
Sanitize\decode( $part['post_title'] ) );
$file_id = 'part-' . sprintf( "%03s", $i );
$filename = "{$file_id}-{$slug}.html";
$filename = "{$file_id}-{$slug}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
// Insert into correct pos
$this->manifest = array_slice( $this->manifest, 0, $array_pos, true ) + array(
@@ -1250,11 +1267,11 @@ protected function createBackMatter( $book_contents, $metadata ) {
'' );
$file_id = 'back-matter-' . sprintf( "%03s", $i );
$filename = "{$file_id}-{$slug}.html";
$filename = "{$file_id}-{$slug}.{$this->filext}";
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
$this->manifest[$file_id] = array(
'ID' => $back_matter['ID'],
@@ -1287,7 +1304,7 @@ protected function createToc( $book_contents, $metadata ) {
$array_pos = $this->positionOfToc();
$file_id = 'table-of-contents';
$filename = "{$file_id}.html";
$filename = "{$file_id}.{$this->filext}";
$vars['post_title'] = __( 'Table Of Contents', 'pressbooks' );
$this->manifest = array_slice( $this->manifest, 0, $array_pos + 1, true ) + array(
@@ -1358,7 +1375,7 @@ protected function createToc( $book_contents, $metadata ) {
file_put_contents(
$this->tmpDir . "/OEBPS/$filename",
$this->loadTemplate( __DIR__ . '/templates/xhtml.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/xhtml.php', $vars ) );
}
@@ -1426,7 +1443,7 @@ protected function kneadHtml( $html, $type, $pos = 0 ) {
$html = preg_replace( '/^<!DOCTYPE.+?>/', '', str_replace( array( '<html>', '</html>', '<body>', '</body>' ), array( '', '', '', '' ), $html ) );
// Mobi7 hacks
$html = $this->transformXML( $utf8_hack . "<html>$html</html>", __DIR__ . '/templates/mobi-hacks.xsl' );
$html = $this->transformXML( $utf8_hack . "<html>$html</html>", $this->dir . '/templates/mobi-hacks.xsl' );
$errors = libxml_get_errors(); // TODO: Handle errors gracefully
libxml_clear_errors();
@@ -1737,7 +1754,7 @@ protected function fuzzyHrefMatch( $url, $type, $pos ) {
if ( $t == $new_type ) ++$new_pos;
if ( $p == $last_part ) break;
}
$new_url = "$new_type-" . sprintf( "%03s", $new_pos ) . "-$last_part.html";
$new_url = "$new_type-" . sprintf( "%03s", $new_pos ) . "-$last_part.{$this->filext}";
if ( $anchor )
$new_url .= $anchor;
@@ -1803,7 +1820,7 @@ protected function createOPF( $book_contents, $metadata ) {
file_put_contents(
$this->tmpDir . "/book.opf",
$this->loadTemplate( __DIR__ . '/templates/opf.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/opf.php', $vars ) );
}
@@ -1831,7 +1848,7 @@ protected function createNCX( $book_contents, $metadata ) {
file_put_contents(
$this->tmpDir . "/toc.ncx",
$this->loadTemplate( __DIR__ . '/templates/ncx.php', $vars ) );
$this->loadTemplate( $this->dir . '/templates/ncx.php', $vars ) );
}
Oops, something went wrong.

0 comments on commit c564bcd

Please sign in to comment.