PHP Class Pressbooks\Modules\Export\Epub\Epub201

Inheritance: extends Pressbooks\Modules\Export\Export
显示文件 Open project: pressbooks/pressbooks Class Usage Examples

Public Properties

Property Type Description
$timeout integer Used with wp_remote_get()

Protected Properties

Property Type Description
$compressImages boolean
$coverImage string Used to set cover-image in OPF for kindlegen compatibility.
$cssOverrides string CSS overrides
$dir $var string
$exportStylePath string Fullpath to book CSS file.
$extraCss string Extra CSS (to be used by child classes if necessary)
$fetchedFontCache array
$fetchedImageCache array
$filext string
$fixme array Used by HtmLawed with $GLOBALS['hl_Ids']
$frontMatterLastPos integer | boolean Last known front matter position. Used to insert the TOC in the correct place.
$frontMatterPos integer Keep track of where we are using this variable.
$hasIntroduction boolean Sometimes the user will omit an introduction so we must inject the style in either the first part or the first chapter ourselves.
$lang string Main language of document, two letter code
$manifest array Generated by createOEPBS(), used by createToc(), createOPF(), and creatdNCX() Note: Only XHTML files go in the manifest array (images are done automatically)
$numbered boolean
$romanizePartNumbers boolean Hack to romanize part numbers
$stylesheet string
$suffix $var string
$supportedFontExtensions string Regular expression for supported fonts (used in #($supportedFontExtensions)#i')
$supportedImageExtensions string Regular expression for supported images (used in #($supportedImageExtensions)#i')
$tmpDir string Temporary directory used to build EPUB, no trailing slash!

Public Methods

Method Description
__construct ( array $args )
__destruct ( ) Delete temporary directory when done.
convert ( ) : boolean Create $this->outputPath
fixAnnoyingCharacters ( string $html ) : string | void Fix annoying characters that the user probably didn't do on purpose
hasDependencies ( ) : boolean Dependency check.
mediaType ( string $file ) : mixed | string Override mimeType, get rid of '; charset=binary'
validate ( ) : boolean Check the sanity of $this->outputPath

Protected Methods

Method Description
buildManifestAssetsHtml ( ) : string Find all the image files, insert them into the OPF file
createBackMatter ( array $book_contents, array $metadata )
createBeforeTitle ( array $book_contents, array $metadata )
createContainer ( ) Create Open Publication Structure 2.0.1 container.
createCopyright ( array $book_contents, array $metadata )
createCover ( array $book_contents, array $metadata )
createDedicationAndEpigraph ( array $book_contents, array $metadata )
createFrontMatter ( array $book_contents, array $metadata )
createNCX ( array $book_contents, array $metadata ) Create NCX file.
createOEPBS ( array $book_contents, array $metadata ) Create OEBPS/* files.
createOPF ( array $book_contents, array $metadata ) Create OPF File.
createPartsAndChapters ( array $book_contents, array $metadata )
createPromo ( array $book_contents, array $metadata )
createStylesheet ( ) Create stylesheet. Change $this->stylesheet to a filename used by subsequent methods.
createTitle ( array $book_contents, array $metadata )
createToc ( array $book_contents, array $metadata ) Uses $this->manifest to generate itself.
deleteTmpDir ( ) Create a temporary directory
fetchAndSaveUniqueFont ( $url, $fullpath ) : string Fetch a font with wp_remote_get(), save it to $fullpath with a unique name.
fetchAndSaveUniqueImage ( $url, $fullpath ) : string Fetch an image with wp_remote_get(), save it to $fullpath with a unique name.
fuzzyHrefMatch ( $url, string $type, integer $pos ) : boolean | string Try to determine if a URL is pointing to internal content. TODO: Refactor, for the love of all that is holy.
fuzzyImageNameMatch ( string $file1, string $file2 ) : boolean Fuzzy image name match.
kneadHref ( DOMDocument $doc, string $type, integer $pos ) : DOMDocument Change hrefs
kneadHtml ( string $html, string $type, integer $pos ) : string Pummel the HTML into EPUB compatible dough.
positionOfToc ( ) : integer Determine position of TOC based on Chicago Manual Of Style.
preProcessBookContents ( $book_contents ) : mixed
preProcessPostContent ( string $content ) : string
scrapeAndKneadImages ( DOMDocument $doc ) : DOMDocument Parse HTML snippet, download all found tags into /OEBPS/assets/, return the HTML with changed paths.
scrapeAndKneadMedia ( DOMDocument $doc ) : DOMDocument This is a stub for an Epub3 feature Do nothing
scrapeKneadAndSaveCss ( string $path_to_original_stylesheet, string $path_to_copy_of_stylesheet ) Parse CSS, copy assets, rewrite copy.
themeOptionsOverrides ( ) Override based on Theme Options
tidy ( string $html ) : string Tidy HTML
zipEpub ( $filename ) : boolean Zip the contents of an EPUB following the conventions outlined in Open Publication Structure 2.0.1

Method Details

__construct() public method

public __construct ( array $args )
$args array

__destruct() public method

Delete temporary directory when done.
public __destruct ( )

buildManifestAssetsHtml() protected method

Find all the image files, insert them into the OPF file
protected buildManifestAssetsHtml ( ) : string
return string

convert() public method

Create $this->outputPath
public convert ( ) : boolean
return boolean

createBackMatter() protected method

protected createBackMatter ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createBeforeTitle() protected method

protected createBeforeTitle ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createContainer() protected method

Create Open Publication Structure 2.0.1 container.
protected createContainer ( )

createCopyright() protected method

protected createCopyright ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createCover() protected method

protected createCover ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createDedicationAndEpigraph() protected method

protected createDedicationAndEpigraph ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createFrontMatter() protected method

protected createFrontMatter ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createNCX() protected method

Create NCX file.
protected createNCX ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createOEPBS() protected method

Create OEBPS/* files.
protected createOEPBS ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createOPF() protected method

Create OPF File.
protected createOPF ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createPartsAndChapters() protected method

protected createPartsAndChapters ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createPromo() protected method

protected createPromo ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createStylesheet() protected method

Create stylesheet. Change $this->stylesheet to a filename used by subsequent methods.
protected createStylesheet ( )

createTitle() protected method

protected createTitle ( array $book_contents, array $metadata )
$book_contents array
$metadata array

createToc() protected method

Uses $this->manifest to generate itself.
protected createToc ( array $book_contents, array $metadata )
$book_contents array
$metadata array

deleteTmpDir() protected method

Create a temporary directory
protected deleteTmpDir ( )

fetchAndSaveUniqueFont() protected method

Will return an empty string if something went wrong.
protected fetchAndSaveUniqueFont ( $url, $fullpath ) : string
$url string
$fullpath string
return string filename

fetchAndSaveUniqueImage() protected method

Will return an empty string if something went wrong.
protected fetchAndSaveUniqueImage ( $url, $fullpath ) : string
$url string
$fullpath string
return string filename

fixAnnoyingCharacters() public method

Fix annoying characters that the user probably didn't do on purpose
public fixAnnoyingCharacters ( string $html ) : string | void
$html string
return string | void

fuzzyHrefMatch() protected method

Try to determine if a URL is pointing to internal content. TODO: Refactor, for the love of all that is holy.
protected fuzzyHrefMatch ( $url, string $type, integer $pos ) : boolean | string
$url
$type string front-matter, part, chapter, back-matter, ...
$pos integer (optional) position of content, used when creating filenames like: chapter-001, chapter-002, ...
return boolean | string

fuzzyImageNameMatch() protected method

For example: We consider both 'href' and 'src' above 'the same'
protected fuzzyImageNameMatch ( string $file1, string $file2 ) : boolean
$file1 string
$file2 string
return boolean

hasDependencies() static public method

Dependency check.
static public hasDependencies ( ) : boolean
return boolean

kneadHref() protected method

Change hrefs
protected kneadHref ( DOMDocument $doc, string $type, integer $pos ) : DOMDocument
$doc DOMDocument
$type string front-matter, part, chapter, back-matter, ...
$pos integer (optional) position of content, used when creating filenames like: chapter-001, chapter-002, ...
return DOMDocument

kneadHtml() protected method

Pummel the HTML into EPUB compatible dough.
protected kneadHtml ( string $html, string $type, integer $pos ) : string
$html string
$type string front-matter, part, chapter, back-matter, ...
$pos integer (optional) position of content, used when creating filenames like: chapter-001, chapter-002, ...
return string

mediaType() public method

Override mimeType, get rid of '; charset=binary'
public mediaType ( string $file ) : mixed | string
$file string
return mixed | string

positionOfToc() protected method

Determine position of TOC based on Chicago Manual Of Style.
protected positionOfToc ( ) : integer
return integer

preProcessBookContents() protected method

protected preProcessBookContents ( $book_contents ) : mixed
$book_contents
return mixed

preProcessPostContent() protected method

protected preProcessPostContent ( string $content ) : string
$content string
return string

scrapeAndKneadImages() protected method

Parse HTML snippet, download all found tags into /OEBPS/assets/, return the HTML with changed paths.
protected scrapeAndKneadImages ( DOMDocument $doc ) : DOMDocument
$doc DOMDocument
return DOMDocument

scrapeAndKneadMedia() protected method

This is a stub for an Epub3 feature Do nothing
protected scrapeAndKneadMedia ( DOMDocument $doc ) : DOMDocument
$doc DOMDocument
return DOMDocument

scrapeKneadAndSaveCss() protected method

Parse CSS, copy assets, rewrite copy.
protected scrapeKneadAndSaveCss ( string $path_to_original_stylesheet, string $path_to_copy_of_stylesheet )
$path_to_original_stylesheet string *
$path_to_copy_of_stylesheet string

themeOptionsOverrides() protected method

Override based on Theme Options
protected themeOptionsOverrides ( )

tidy() protected method

Tidy HTML
protected tidy ( string $html ) : string
$html string
return string

validate() public method

Check the sanity of $this->outputPath
public validate ( ) : boolean
return boolean

zipEpub() protected method

Zip the contents of an EPUB following the conventions outlined in Open Publication Structure 2.0.1
protected zipEpub ( $filename ) : boolean
$filename
return boolean

Property Details

$compressImages protected_oe property

protected bool $compressImages
return boolean

$coverImage protected_oe property

Used to set cover-image in OPF for kindlegen compatibility.
protected string $coverImage
return string

$cssOverrides protected_oe property

CSS overrides
protected string $cssOverrides
return string

$dir protected_oe property

$var string
protected $dir

$exportStylePath protected_oe property

Fullpath to book CSS file.
protected string $exportStylePath
return string

$extraCss protected_oe property

Extra CSS (to be used by child classes if necessary)
protected string $extraCss
return string

$fetchedFontCache protected_oe property

protected array $fetchedFontCache
return array

$fetchedImageCache protected_oe property

protected array $fetchedImageCache
return array

$filext protected_oe property

protected string $filext
return string

$fixme protected_oe property

Used by HtmLawed with $GLOBALS['hl_Ids']
protected array $fixme
return array

$frontMatterLastPos protected_oe property

Last known front matter position. Used to insert the TOC in the correct place.
protected int|bool $frontMatterLastPos
return integer | boolean

$frontMatterPos protected_oe property

Keep track of where we are using this variable.
protected int $frontMatterPos
return integer

$hasIntroduction protected_oe property

Sometimes the user will omit an introduction so we must inject the style in either the first part or the first chapter ourselves.
protected bool $hasIntroduction
return boolean

$lang protected_oe property

Main language of document, two letter code
protected string $lang
return string

$manifest protected_oe property

Generated by createOEPBS(), used by createToc(), createOPF(), and creatdNCX() Note: Only XHTML files go in the manifest array (images are done automatically)
protected array $manifest
return array

$numbered protected_oe property

protected bool $numbered
return boolean

$romanizePartNumbers protected_oe property

Hack to romanize part numbers
protected bool $romanizePartNumbers
return boolean

$stylesheet protected_oe property

protected string $stylesheet
return string

$suffix protected_oe property

$var string
protected $suffix

$supportedFontExtensions protected_oe property

Regular expression for supported fonts (used in #($supportedFontExtensions)#i')
protected string $supportedFontExtensions
return string

$supportedImageExtensions protected_oe property

Regular expression for supported images (used in #($supportedImageExtensions)#i')
protected string $supportedImageExtensions
return string

$timeout public_oe property

Used with wp_remote_get()
public int $timeout
return integer

$tmpDir protected_oe property

Temporary directory used to build EPUB, no trailing slash!
protected string $tmpDir
return string