DocImportDOCX
extends DocImport
in package
Abstract class with additional stuff for the document importer system
The document importer loads docuemnts and returns XML files These files can then be processed by other parts of the CMS. The term "xmldoc" is referring to the intermediate XML file produced by the import libraries
Table of Contents
Properties
- $symbol_font_map : mixed
- Mapping between PUA for Symbol font to regular characters
- $number_formats : mixed
- $relationships : mixed
- $res : mixed
- $styles : mixed
- $zip : mixed
Methods
- getHeadingsTree() : Treenode
- For a given XML document, return a tree of headings
- getHtml() : string|null
- For a given XML doc file, return the HTML version.
- getResources() : array<string|int, mixed>|null
- For a given XML doc file, return an array of resources, in name => data format.
- instance() : mixed
- Return a `DocImport` object instance for converting a file with a given original name Throws an exception on error
- load() : string|DOMDocument
- The main load function for a document.
- symbolSanitizeString() : string
- Convert 'Symbol' font Private-Use-Area characters into real characters
- symbolUnicodeToUtf8Entity() : string
- Regular expression callback for Symbol font conversion
- block() : string
- Draw block element
- determineListTag() : string
- For a given style tag, return a list tag (either 'ul' or 'ol')
- determineParaTag() : string
- For a given style tag, return a paragraph tag (either 'p' or 'h1', 'h2', etc)
- determineStyle() : array<string|int, mixed>
- For a given paragraph element, determine the finalised style in use
- drawing() : string
- Render a w:drawing object, i.e. an image
- drawRuns() : string
- Output one or more `w:r` elements
- drawTable() : string
- Draw a w:tbl element
- EMUtoPX() : float
- EM units to pixels
- flattenBasedOnTree() : array<string|int, mixed>
- Walk the chain of styles via the "based on" field to generate a list of names
- isValidBlockElem() : bool
- Validates element as block display
- loadFormats() : array<string|int, mixed>
- Load the number formats from numbering.xml
- loadRelationships() : array<string|int, mixed>
- Relationships is how the main document.xml links together with various media files etc
- loadStyles() : array<string|int, mixed>
- Load styles
- numbersFromStyles() : void
- Sometimes a numbering format refers to a style, the style itself contains the actual number format This function dereferences the number formats back again
- parseCss() : array<string|int, mixed>
- Parse given css
- pict() : string
- Render a w:pict object, i.e. an image
- renderBlockRuns() : string
- Render all the runs (i.e. w:r elements) for a given block element
Properties
$symbol_font_map
Mapping between PUA for Symbol font to regular characters
public
static mixed
$symbol_font_map
= [15696032 => 32, 15696033 => 33, 15696034 => 8704, 15696035 => 35, 15696036 => 8707, 15696037 => 37, 15696038 => 38, 15696039 => 8715, 15696040 => 40, 15696041 => 41, 15696042 => 8727, 15696043 => 43, 15696044 => 44, 15696045 => 8722, 15696046 => 46, 15696047 => 47, 15696048 => 48, 15696049 => 49, 15696050 => 50, 15696051 => 51, 15696052 => 52, 15696053 => 53, 15696054 => 54, 15696055 => 55, 15696056 => 56, 15696057 => 57, 15696058 => 58, 15696059 => 59, 15696060 => 60, 15696061 => 61, 15696062 => 62, 15696063 => 63, 15696256 => 8773, 15696257 => 913, 15696258 => 914, 15696259 => 935, 15696260 => 916, 15696261 => 917, 15696262 => 934, 15696263 => 915, 15696264 => 919, 15696265 => 921, 15696266 => 977, 15696267 => 922, 15696268 => 923, 15696269 => 924, 15696270 => 925, 15696271 => 927, 15696272 => 928, 15696273 => 920, 15696274 => 929, 15696275 => 931, 15696276 => 932, 15696277 => 933, 15696278 => 962, 15696279 => 937, 15696280 => 926, 15696281 => 936, 15696282 => 918, 15696283 => 91, 15696284 => 8756, 15696285 => 93, 15696286 => 8869, 15696287 => 95, 15696288 => 63717, 15696289 => 945, 15696290 => 946, 15696291 => 967, 15696292 => 948, 15696293 => 949, 15696294 => 966, 15696295 => 947, 15696296 => 951, 15696297 => 953, 15696298 => 981, 15696299 => 954, 15696300 => 955, 15696301 => 956, 15696302 => 957, 15696303 => 959, 15696304 => 960, 15696305 => 952, 15696306 => 961, 15696307 => 963, 15696308 => 964, 15696309 => 965, 15696310 => 982, 15696311 => 969, 15696312 => 958, 15696313 => 968, 15696314 => 950, 15696315 => 123, 15696316 => 124, 15696317 => 125, 15696318 => 8764, 15696544 => 8364, 15696545 => 978, 15696546 => 8242, 15696547 => 8804, 15696548 => 8260, 15696549 => 8734, 15696550 => 402, 15696551 => 9827, 15696552 => 9830, 15696553 => 9829, 15696554 => 9824, 15696555 => 8596, 15696556 => 8592, 15696557 => 8593, 15696558 => 8594, 15696559 => 8595, 15696560 => 176, 15696561 => 177, 15696562 => 8243, 15696563 => 8805, 15696564 => 215, 15696565 => 8733, 15696566 => 8706, 15696567 => 8226, 15696568 => 247, 15696569 => 8800, 15696570 => 8801, 15696571 => 8776, 15696572 => 8230, 15696573 => 63718, 15696574 => 63719, 15696575 => 8629, 15696768 => 8501, 15696769 => 8465, 15696770 => 8476, 15696771 => 8472, 15696772 => 8855, 15696773 => 8853, 15696774 => 8709, 15696775 => 8745, 15696776 => 8746, 15696777 => 8835, 15696778 => 8839, 15696779 => 8836, 15696780 => 8834, 15696781 => 8838, 15696782 => 8712, 15696783 => 8713, 15696784 => 8736, 15696785 => 8711, 15696786 => 63194, 15696787 => 63193, 15696788 => 63195, 15696789 => 8719, 15696790 => 8730, 15696791 => 8901, 15696792 => 172, 15696793 => 8743, 15696794 => 8744, 15696795 => 8660, 15696796 => 8656, 15696797 => 8657, 15696798 => 8658, 15696799 => 8659, 15696800 => 9674, 15696801 => 9001, 15696802 => 63720, 15696803 => 63721, 15696804 => 63722, 15696805 => 8721, 15696806 => 63723, 15696807 => 63724, 15696808 => 63725, 15696809 => 63726, 15696810 => 63727, 15696811 => 63728, 15696812 => 63729, 15696813 => 63730, 15696814 => 63731, 15696815 => 63732, 15696817 => 9002, 15696818 => 8747, 15696819 => 8992, 15696820 => 63733, 15696821 => 8993, 15696822 => 63734, 15696823 => 63735, 15696824 => 63736, 15696825 => 63737, 15696826 => 63738, 15696827 => 63739, 15696828 => 63740, 15696829 => 63741, 15696830 => 63742]
Key - UTF-8 encoded bytes Value - Widechar bytes
$number_formats
private
mixed
$number_formats
$relationships
private
mixed
$relationships
$res
private
mixed
$res
$styles
private
mixed
$styles
$zip
private
mixed
$zip
Methods
getHeadingsTree()
For a given XML document, return a tree of headings
public
static getHeadingsTree(string|DOMDocument $filename, int $max_depth[, bool $include_body = false ]) : Treenode
Any heading level past the max_depth option is treated like body text.
Parameters
- $filename : string|DOMDocument
-
The XML file to load; this can also be passed as a DOMDocument object
- $max_depth : int
-
The maximum depth of headings to return
- $include_body : bool = false
-
True to include the body XML as a parameter on the node. Default false
Return values
Treenode —The tree of headings
getHtml()
For a given XML doc file, return the HTML version.
public
static getHtml(string|DOMDocument $filename[, array<string|int, mixed> $images = array() ][, array<string|int, mixed> $headings = array() ]) : string|null
Parameters
- $filename : string|DOMDocument
-
The file to load; this can also be passed as a DOMDocument object
- $images : array<string|int, mixed> = array()
-
Mapping of rel => filename for images
- $headings : array<string|int, mixed> = array()
-
Mapping of old to new level for headings (e.g. 3 => 2 for H3 -> H2)
Return values
string|null —The HTML, or NULL on error
getResources()
For a given XML doc file, return an array of resources, in name => data format.
public
static getResources(string $filename) : array<string|int, mixed>|null
Parameters
- $filename : string
-
The file to load
Return values
array<string|int, mixed>|null —The resources, or null on error
instance()
Return a `DocImport` object instance for converting a file with a given original name Throws an exception on error
public
static instance(mixed $orig_filename) : mixed
Parameters
- $orig_filename : mixed
load()
The main load function for a document.
public
load(string $filename) : string|DOMDocument
Throw an exception on error.
Parameters
- $filename : string
-
The file. The file will exist, but may not be valid
Return values
string|DOMDocument —$data Resultant XML data as a string or DOMDocument element
symbolSanitizeString()
Convert 'Symbol' font Private-Use-Area characters into real characters
public
symbolSanitizeString(string $string) : string
Parameters
- $string : string
Return values
stringsymbolUnicodeToUtf8Entity()
Regular expression callback for Symbol font conversion
public
symbolUnicodeToUtf8Entity(array<string|int, mixed> $wchar) : string
Parameters
- $wchar : array<string|int, mixed>
Return values
stringblock()
Draw block element
private
block(DOMElement $elem) : string
Parameters
- $elem : DOMElement
Return values
string —HTML
determineListTag()
For a given style tag, return a list tag (either 'ul' or 'ol')
private
determineListTag(array<string|int, mixed> $style) : string
Parameters
- $style : array<string|int, mixed>
Return values
string —Tag name
determineParaTag()
For a given style tag, return a paragraph tag (either 'p' or 'h1', 'h2', etc)
private
determineParaTag(array<string|int, mixed> $style) : string
Parameters
- $style : array<string|int, mixed>
Return values
string —Tag name
determineStyle()
For a given paragraph element, determine the finalised style in use
private
determineStyle(DOMElement $elem) : array<string|int, mixed>
Parameters
- $elem : DOMElement
Return values
array<string|int, mixed>drawing()
Render a w:drawing object, i.e. an image
private
drawing(DOMElement $elem) : string
Parameters
- $elem : DOMElement
Return values
string —HTML img tag
drawRuns()
Output one or more `w:r` elements
private
drawRuns(array<string|int, mixed> $runs) : string
Parameters
- $runs : array<string|int, mixed>
Return values
stringdrawTable()
Draw a w:tbl element
private
drawTable(DOMElement $elem) : string
Parameters
- $elem : DOMElement
Return values
string —HTML table
EMUtoPX()
EM units to pixels
private
EMUtoPX(int|float $emu[, int $dpi = 72 ]) : float
Parameters
- $emu : int|float
- $dpi : int = 72
Return values
float —Pixel value
flattenBasedOnTree()
Walk the chain of styles via the "based on" field to generate a list of names
private
flattenBasedOnTree(array<string|int, mixed> &$styles, array<string|int, mixed> $heading) : array<string|int, mixed>
Parameters
- $styles : array<string|int, mixed>
- $heading : array<string|int, mixed>
Return values
array<string|int, mixed> —List of names
isValidBlockElem()
Validates element as block display
private
isValidBlockElem(DOMElement $elem) : bool
Parameters
- $elem : DOMElement
Return values
bool —True Valid block element
loadFormats()
Load the number formats from numbering.xml
private
loadFormats() : array<string|int, mixed>
Return values
array<string|int, mixed>loadRelationships()
Relationships is how the main document.xml links together with various media files etc
private
loadRelationships() : array<string|int, mixed>
Return values
array<string|int, mixed>loadStyles()
Load styles
private
loadStyles() : array<string|int, mixed>
Return values
array<string|int, mixed>numbersFromStyles()
Sometimes a numbering format refers to a style, the style itself contains the actual number format This function dereferences the number formats back again
private
numbersFromStyles() : void
parseCss()
Parse given css
private
parseCss(string $css) : array<string|int, mixed>
Parameters
- $css : string
Return values
array<string|int, mixed>pict()
Render a w:pict object, i.e. an image
private
pict(DOMElement $elem) : string
Parameters
- $elem : DOMElement
Return values
string —HTML img tag
renderBlockRuns()
Render all the runs (i.e. w:r elements) for a given block element
private
renderBlockRuns(DOMElement $block) : string
You would think this would be a simple draw_runs call on the getElementsByTagName, but we would never actually have it that easy...
Parameters
- $block : DOMElement
Return values
string —XML tags representing the run content