PHP Class Pressbooks\Modules\Import\Ooxml\Docx

Inheritance: extends PressBooks\Modules\Import\Import
显示文件 Open project: pressbooks/pressbooks

Protected Properties

Property Type Description
$authors string
$en array
$fn array
$ln array
$tag string
$zip ZipArchive

Public Methods

Method Description
__construct ( )
import ( array $current_import ) : boolean
setCurrentImportOption ( array $upload ) : boolean

Protected Methods

Method Description
addFootnotes ( DOMDocument $chapter ) : DOMDocument adds footnotes, if they are present in the chapter
addHyperlinks ( DOMDocument $chapter ) : DOMDocument adds external hyperlinks, if they are present in a chapter
fetchAndSaveUniqueImage ( string $img_id ) : string Extract url from zip and load into WP using media_handle_sideload() Will return an empty string if something went wrong.
findTheNode ( DOMNode $node, string $chapter_name ) : DOMNode Recursive iterator to locate and return a specific node, targeting child nodes
getChapter ( DOMNodeList $dom_list, integer $index, string $chapter_title ) : string Find where to start, iterate through a list, add elements to a new DomDocument, return resulting xhtml
getFuzzyChapterTitles ( ) : array Returns an array of available chapters, or 'unknown' if none
getIDs ( DOMDocument $dom_doc, string $tag = 'footnoteReference', $attr = 'w:id' ) : array Given a documentElement, it will return an array of ids
getRelationshipPart ( array $ids, string $tag = 'footnotes' ) : array | boolean Give this some ids and it returns an associative array of footnotes
getTargetPath ( string $schema, string $id = '' ) : string Give it a schema, get back a path(s) that points to a resource
getZipContent ( string $file, boolean $as_xml = true ) : boolean | DOMDocument Give it a path to a file and it will return the contents of that file, either as xml or html
isValidZip ( string $fullpath ) Checks for standard DOCX file structure
kneadAndInsert ( string $html, string $title, string $post_type, integer $chapter_parent ) Pummel then insert HTML into our database
kneadHTML ( string $body ) : string Pummel the HTML into WordPress compatible dough.
parseContent ( DomDocument $xml, string $chapter_title ) : string
parseMetaData ( DomDocument $meta )
scrapeAndKneadImages ( DOMDocument $doc ) : DOMDocument Parse HTML snippet, save all found tags using media_handle_sideload(), return the HTML with changed paths.
tidy ( string $html ) : string Compliance with XTHML standards, rid cruft generated by word processors

Method Details

__construct() public method

public __construct ( )

addFootnotes() protected method

adds footnotes, if they are present in the chapter
protected addFootnotes ( DOMDocument $chapter ) : DOMDocument
$chapter DOMDocument
return DOMDocument

fetchAndSaveUniqueImage() protected method

Extract url from zip and load into WP using media_handle_sideload() Will return an empty string if something went wrong.
protected fetchAndSaveUniqueImage ( string $img_id ) : string
$img_id string
return string

findTheNode() protected method

Recursive iterator to locate and return a specific node, targeting child nodes
protected findTheNode ( DOMNode $node, string $chapter_name ) : DOMNode
$node DOMNode
$chapter_name string
return DOMNode

getChapter() protected method

Find where to start, iterate through a list, add elements to a new DomDocument, return resulting xhtml
protected getChapter ( DOMNodeList $dom_list, integer $index, string $chapter_title ) : string
$dom_list DOMNodeList
$index integer
$chapter_title string
return string XHTML

getFuzzyChapterTitles() protected method

Returns an array of available chapters, or 'unknown' if none
protected getFuzzyChapterTitles ( ) : array
return array Chapter titles

getIDs() protected method

Given a documentElement, it will return an array of ids
protected getIDs ( DOMDocument $dom_doc, string $tag = 'footnoteReference', $attr = 'w:id' ) : array
$dom_doc DOMDocument
$tag string
return array

getRelationshipPart() protected method

Give this some ids and it returns an associative array of footnotes
protected getRelationshipPart ( array $ids, string $tag = 'footnotes' ) : array | boolean
$ids array
$tag string
return array | boolean

getTargetPath() protected method

Give it a schema, get back a path(s) that points to a resource
protected getTargetPath ( string $schema, string $id = '' ) : string
$schema string
$id string
return string

getZipContent() protected method

Give it a path to a file and it will return the contents of that file, either as xml or html
protected getZipContent ( string $file, boolean $as_xml = true ) : boolean | DOMDocument
$file string
$as_xml boolean (optional)
return boolean | DOMDocument

import() public method

public import ( array $current_import ) : boolean
$current_import array
return boolean

isValidZip() protected method

Checks for standard DOCX file structure
protected isValidZip ( string $fullpath )
$fullpath string

kneadAndInsert() protected method

Pummel then insert HTML into our database
protected kneadAndInsert ( string $html, string $title, string $post_type, integer $chapter_parent )
$html string
$title string
$post_type string (front-matter', 'chapter', 'back-matter')
$chapter_parent integer

kneadHTML() protected method

Pummel the HTML into WordPress compatible dough.
protected kneadHTML ( string $body ) : string
$body string
return string - modified with correct image paths

parseContent() protected method

protected parseContent ( DomDocument $xml, string $chapter_title ) : string
$xml DomDocument
$chapter_title string
return string

parseMetaData() protected method

protected parseMetaData ( DomDocument $meta )
$meta DomDocument

scrapeAndKneadImages() protected method

Parse HTML snippet, save all found tags using media_handle_sideload(), return the HTML with changed paths.
protected scrapeAndKneadImages ( DOMDocument $doc ) : DOMDocument
$doc DOMDocument
return DOMDocument

setCurrentImportOption() public method

public setCurrentImportOption ( array $upload ) : boolean
$upload array
return boolean

tidy() protected method

Compliance with XTHML standards, rid cruft generated by word processors
protected tidy ( string $html ) : string
$html string
return string

Property Details

$authors protected_oe property

protected string $authors
return string

$en protected_oe property

protected array $en
return array

$fn protected_oe property

protected array $fn
return array

$ln protected_oe property

protected array $ln
return array

$tag protected_oe property

protected string $tag
return string

$zip protected_oe property

protected ZipArchive $zip
return ZipArchive