';
+
+ $this->complexField = array('type' => 'PAGEREF');
+ }
+
+ if ($contentComplexField[0] == 'TIME') {
+ // remove TIME \@ values and get the date
+ array_shift($contentComplexField);
+ array_shift($contentComplexField);
+
+ // transform OOXML date format to PHP format
+ // join the content of the complex field
+ $date = join(' ', $contentComplexField);
+ // split by symbol
+ $dateElements = preg_split('/(\w+)/', $date, -1, PREG_SPLIT_DELIM_CAPTURE);
+ // iterate each content to transform the date
+ $dateTransformed = '';
+ foreach ($dateElements as $dateElement) {
+ switch ($dateElement) {
+ case 'yyyy':
+ $dateTransformed .= date('Y');
+ break;
+ case 'yy':
+ $dateTransformed .= date('Y');
+ break;
+ case 'MMMM':
+ $dateTransformed .= date('F');
+ break;
+ case 'MM':
+ $dateTransformed .= date('m');
+ break;
+ case 'dd':
+ $dateTransformed .= date('d');
+ break;
+ case 'H':
+ $dateTransformed .= date('H');
+ break;
+ case 'mm':
+ $dateTransformed .= date('i');
+ break;
+ case 'ss':
+ $dateTransformed .= date('s');
+ break;
+ default:
+ // remove extra characters from the DATE
+ $dateElementTransformed = str_replace(array('"', '\''), '', $dateElement);
+ $dateTransformed .= $dateElementTransformed;
+ }
+ };
+
+ $this->html .= '' . $dateTransformed . '';
+
+ $this->complexField = array('type' => 'TIME');
+ }
+ }
+ }
+
+ /**
+ * Transform w:p tag
+ *
+ * @param DOMElement $childNode
+ * @param String $nodeClass
+ */
+ protected function transformW_P($childNode, $nodeClass)
+ {
+ // if it's an internal section avoid adding the paragraph
+ $sectPrTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'sectPr');
+ if ($sectPrTag->length > 0) {
+ $this->transformXml($childNode);
+ return;
+ }
+
+ // handle tag
+
+ // default element
+ $elementTag = $this->htmlPlugin->getTag('paragraph');
+
+ // heading tag
+ $outlineLvlTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'outlineLvl');
+ if ($outlineLvlTag->length > 0 && $outlineLvlTag->item(0)->hasAttribute('w:val')) {
+ $elementTag = $this->htmlPlugin->getTag('heading') . ((int)$outlineLvlTag->item(0)->getAttribute('w:val') + 1);
+ }
+
+ // numbering tag
+ if (is_array($this->numberingParagraph)) {
+ // handle as p tags
+
+ // handle numbering in paragraph
+ $numPrTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numPr');
+ // handle numbering in pStyle
+ if ($numPrTag->length == 0) {
+ $pStyle = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'pStyle');
+ if ($pStyle->length > 0) {
+ $pStyleId = $pStyle->item(0)->getAttribute('w:val');
+ $xpathStyles = new \DOMXPath($this->stylesDocxDOM);
+ $xpathStyles->registerNamespace('w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+ $numPrTag = $xpathStyles->query('//w:style[@w:styleId="' . $pStyleId . '"]/w:pPr/w:numPr');
+ }
+ }
+
+ if ($numPrTag->length > 0) {
+ $numIdTag = $numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numId');
+ if ($numIdTag->length > 0 && $numIdTag->item(0)->hasAttribute('w:val') && $numIdTag->item(0)->getAttribute('w:val') != '') {
+ $numPrIlvlTag = $numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'ilvl');
+ if ($numPrIlvlTag->length > 0) {
+ $numberingLevel = (int)$numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'ilvl')->item(0)->getAttribute('w:val');
+ } else {
+ // if there's no level tag, such as numbering in paragraph styles, set it as 0
+ $numberingLevel = 0;
+ }
+ $listStartValue = $this->getNumberingStart($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ $listLvlText = $this->getNumberingLvlText($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+
+ // get the numbering style based on the numbering ID and its level
+ $numberingStyle = $this->getNumberingType($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ if (!$numberingStyle && $numIdTag->item(0)->getAttribute('w:val') == '0') {
+ $numberingStyle = 'none';
+ }
+
+ // restart the value if it's the first time it appears or the level has changed and the new level is higher than the olf one
+ if (!isset($this->numberingParagraph['value'][$numberingLevel . $numIdTag->item(0)->getAttribute('w:val')]) || ($this->numberingParagraph['level'] != $numberingLevel && (int)$this->numberingParagraph['level'] < (int)$numberingLevel)) {
+ $this->numberingParagraph['value'][$numberingLevel . $numIdTag->item(0)->getAttribute('w:val')] = $listStartValue;
+ } else {
+ $this->numberingParagraph['value'][$numberingLevel . $numIdTag->item(0)->getAttribute('w:val')]++;
+ }
+
+ $this->numberingParagraph['level'] = $numberingLevel;
+ $this->numberingParagraph['numId'] = $numIdTag->item(0)->getAttribute('w:val');
+
+ switch ($numberingStyle) {
+ case 'bullet':
+ // default value
+ $this->prependTValue = '•' . ' ';
+ if ($listLvlText == 'o') {
+ $this->prependTValue = '◦' . ' ';
+ }
+ break;
+ case 'decimal':
+ // iterate numberLevel to handle level list when displaying sublevels such as 1.1. 1.2
+ for ($i = $numberingLevel; $i >= 0; $i--) {
+ $listLvlText = str_replace('%' . ($i + 1), $this->numberingParagraph['value'][$i . $numIdTag->item(0)->getAttribute('w:val')], $listLvlText) . ' ';
+ }
+ $this->prependTValue = $listLvlText;
+ break;
+ case 'lowerLetter':
+ for ($i = $numberingLevel; $i >= 0; $i--) {
+ $listLvlText = str_replace('%' . ($i + 1), chr((ord('a') + ($this->numberingParagraph['value'][$i . $numIdTag->item(0)->getAttribute('w:val')] - 1))), $listLvlText) . ' ';
+ }
+ $this->prependTValue = $listLvlText;
+ break;
+ case 'lowerRoman':
+ for ($i = $numberingLevel; $i >= 0; $i--) {
+ $listLvlText = str_replace('%' . ($i + 1), strtolower($this->transformIntegerToRoman($this->numberingParagraph['value'][$i . $numIdTag->item(0)->getAttribute('w:val')])), $listLvlText) . ' ';
+ }
+ $this->prependTValue = $listLvlText;
+ break;
+ case 'upperLetter':
+ for ($i = $numberingLevel; $i >= 0; $i--) {
+ $listLvlText = str_replace('%' . ($i + 1), chr((ord('A') + ($this->numberingParagraph['value'][$i . $numIdTag->item(0)->getAttribute('w:val')] - 1))), $listLvlText) . ' ';
+ }
+ $this->prependTValue = $listLvlText;
+ break;
+ case 'upperRoman':
+ for ($i = $numberingLevel; $i >= 0; $i--) {
+ $listLvlText = str_replace('%' . ($i + 1), strtoupper($this->transformIntegerToRoman($this->numberingParagraph['value'][$i . $numIdTag->item(0)->getAttribute('w:val')])), $listLvlText) . ' ';
+ }
+ $this->prependTValue = $listLvlText;
+ break;
+ case 'none':
+ $this->prependTValue = '';
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ } else {
+ // handle as ul or or tags
+ $numPrTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numPr');
+ if ($numPrTag->length > 0) {
+ // get w:numId to know the ID of the list
+ $numIdTag = $numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numId');
+ if ($numIdTag->length > 0 && $numIdTag->item(0)->hasAttribute('w:val') && $numIdTag->item(0)->getAttribute('w:val') != '') {
+ // handle start list number
+ if (!isset($this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')])) {
+ $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')] = array();
+ }
+ $numberingLevel = (int)$numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'ilvl')->item(0)->getAttribute('w:val');
+ // handle start list number
+ if (!isset($this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel])) {
+ // check if there's a start value in the numbering style
+ $startValue = $this->getNumberingStart($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] = $startValue;
+ } else {
+ $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] = $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] + 1;
+ }
+
+ // get the numbering style based on the numbering ID and its level
+ $numberingStyle = $this->getNumberingType($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ if (!$numberingStyle && $numIdTag->item(0)->getAttribute('w:val') == '0') {
+ $numberingStyle = 'none';
+ }
+
+ // check if the previous sibling is a numbering.
+ // If there's no previous sibling or the ID or level aren't the same starts a new list
+ $previousSiblingElement = $numPrTag->item(0)->parentNode->parentNode->previousSibling;
+ $initNewList = false;
+ if ($previousSiblingElement === null) {
+ $initNewList = true;
+ }
+
+ if ($previousSiblingElement !== null) {
+ $numPrPreviousSiblingElement = $previousSiblingElement->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numPr');
+ if ($numPrPreviousSiblingElement->length > 0) {
+ // the previous element is a numbering
+ $numIdPreviousSiblingElementTag = $numPrPreviousSiblingElement->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numId');
+ if ($numIdPreviousSiblingElementTag->length > 0 && $numIdPreviousSiblingElementTag->item(0)->hasAttribute('w:val') && $numIdPreviousSiblingElementTag->item(0)->getAttribute('w:val') != '') {
+ $numberingLevelPreviousSiblingElementTag = (int)$numPrPreviousSiblingElement->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'ilvl')->item(0)->getAttribute('w:val');
+ // get the numbering style based on the numbering ID and its level
+ $numberingStylePreviousSiblingElementTag = $this->getNumberingType($numIdPreviousSiblingElementTag->item(0)->getAttribute('w:val'), $numberingLevelPreviousSiblingElementTag);
+
+ if ($numIdPreviousSiblingElementTag->item(0)->getAttribute('w:val') != $numIdTag->item(0)->getAttribute('w:val')) {
+ $initNewList = true;
+ }
+
+ if ($numberingLevelPreviousSiblingElementTag < $numberingLevel) {
+ $initNewList = true;
+ }
+ }
+ } else {
+ // the previous element is not a numbering, then create a new list
+ $initNewList = true;
+ }
+ }
+
+ // create the new list
+ if ($initNewList === true) {
+ if (in_array($numberingStyle, array('decimal', 'upperRoman', 'lowerRoman', 'upperLetter', 'lowerLetter'))) {
+ $tagTypeList = $this->htmlPlugin->getTag('orderedList');
+ } else {
+ $tagTypeList = $this->htmlPlugin->getTag('unorderedList');
+ }
+ switch ($numberingStyle) {
+ case 'bullet':
+ $this->css[$nodeClass] .= 'list-style-type: disc;';
+ break;
+ case 'decimal':
+ $this->css[$nodeClass] .= 'list-style-type: decimal;';
+ break;
+ case 'lowerLetter':
+ $this->css[$nodeClass] .= 'list-style-type: lower-alpha;';
+ break;
+ case 'lowerRoman':
+ $this->css[$nodeClass] .= 'list-style-type: lower-roman;';
+ break;
+ case 'upperLetter':
+ $this->css[$nodeClass] .= 'list-style-type: upper-alpha;';
+ break;
+ case 'upperRoman':
+ $this->css[$nodeClass] .= 'list-style-type: upper-roman;';
+ break;
+ case 'none':
+ $this->css[$nodeClass] .= 'list-style-type: none;';
+ break;
+ default:
+ break;
+ }
+ $this->html .= '<'.$tagTypeList.' class="'.$nodeClass.' ' . ($this->htmlPlugin->getExtraClass('list')==null?'':$this->htmlPlugin->getExtraClass('list')) . '" ' . 'start="' . $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] . '">';
+ }
+
+ }
+
+ $elementTag = $this->htmlPlugin->getTag('itemList');
+ }
+ }
+
+ // paragraph style
+ $pStyle = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'pStyle');
+ $pStyleId = null;
+ if ($pStyle->length > 0) {
+ $pStyleId = $pStyle->item(0)->getAttribute('w:val');
+ if (!empty($pStyleId)) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] = '';
+ }
+ }
+
+ // handle styles
+ if ($childNode->hasChildNodes()) {
+ if ($elementTag == $this->htmlPlugin->getTag('itemList')) {
+ // numbering styles
+ $numberingLevelTags = $this->getNumberingStyles($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+
+ // pPr styles
+ if ($pStyleId) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] .= $this->addPprStyles($numberingLevelTags);
+ }
+ $this->css[$nodeClass] .= $this->addPprStyles($numberingLevelTags);
+
+ if ($pStyleId) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] .= 'text-indent: 0px; margin-left: 0px; margin-right: 0px;';
+ }
+ $this->css[$nodeClass] .= 'text-indent: 0px; margin-left: 0px; margin-right: 0px;';
+
+ // rPr styles
+ if ($pStyleId) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] .= $this->addRprStyles($numberingLevelTags);
+ }
+ $this->css[$nodeClass] .= $this->addRprStyles($numberingLevelTags);
+ } else {
+ $pPrTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'pPr');
+ // check if there's a pPr tag
+ if ($pPrTag->length > 0) {
+ if (is_array($this->numberingParagraph)) {
+ // numbering styles
+ if ($numIdTag && $numIdTag->length > 0) {
+ $numberingLevelTags = $this->getNumberingStyles($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ $this->css[$nodeClass] .= $this->addPprStyles($numberingLevelTags, 'numberingStyleParagraph');
+ }
+
+ // numbering styles in custom paragraph styles
+ $pStyle = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'pStyle');
+ if ($pStyle->length > 0) {
+ $pStyleId = $pStyle->item(0)->getAttribute('w:val');
+ $xpathStyles = new \DOMXPath($this->stylesDocxDOM);
+ $xpathStyles->registerNamespace('w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+ $numIdTag = $xpathStyles->query('//w:style[@w:styleId="' . $pStyleId . '"]/w:pPr/w:numPr/w:numId');
+ if ($numIdTag->length > 0) {
+ $numberingLevelTags = $this->getNumberingStyles($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ if ($pStyleId) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] .= $this->addPprStyles($numberingLevelTags, 'numberingStyleParagraph');
+ }
+ $this->css[$nodeClass] .= $this->addPprStyles($numberingLevelTags, 'numberingStyleParagraph');
+ }
+ }
+ }
+
+ // pPr styles
+ if ($pStyleId) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] .= $this->addPprStyles($childNode);
+ }
+ $this->css[$nodeClass] .= $this->addPprStyles($childNode);
+
+ // rPr styles
+ if ($pStyleId) {
+ $this->css[$nodeClass . ' .paragraph_' . $pStyleId] .= $this->addRprStyles($pPrTag->item(0));
+ }
+ $this->css[$nodeClass] .= $this->addRprStyles($pPrTag->item(0));
+ }
+ }
+ }
+
+ // remove extra , and . before adding it to the HTML
+ $nodeClassHTML = str_replace(array(',', '.'), '', $nodeClass);
+
+ $this->html .= '<'.$elementTag.' class="'.$nodeClassHTML.' ' . ($this->htmlPlugin->getExtraClass('list')==null?'':$this->htmlPlugin->getExtraClass('paragraph')) . '">';
+
+ // handle child elements
+ if ($childNode->hasChildNodes()) {
+ $this->transformXml($childNode);
+ }
+
+ $this->html .= ''.$elementTag.'>';
+
+ // numbering tag
+ if (!is_array($this->numberingParagraph)) {
+ // handle as ul or or tags
+ $numPrTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numPr');
+ if ($numPrTag->length > 0) {
+ // check if the next sibling is a numbering.
+ // If there's no next sibling or the ID isn't the same or level is lower close the list
+ $nextSiblingElement = $numPrTag->item(0)->parentNode->parentNode->nextSibling;
+ $closeNewList = false;
+ if ($nextSiblingElement === null) {
+ $closeNewList = true;
+ }
+
+ // sets how many list levels must be closed
+ $iterationListClose = 1;
+
+ if ($nextSiblingElement !== null) {
+ $numPrNextSiblingElement = $nextSiblingElement->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numPr');
+ if ($numPrNextSiblingElement->length > 0) {
+ // the next element is a numbering
+ $numIdNextSiblingElementTag = $numPrNextSiblingElement->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numId');
+ if ($numIdNextSiblingElementTag->length > 0 && $numIdNextSiblingElementTag->item(0)->hasAttribute('w:val') && $numIdNextSiblingElementTag->item(0)->getAttribute('w:val') != '') {
+ $numberingLevelNextSiblingElementTag = (int)$numPrNextSiblingElement->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'ilvl')->item(0)->getAttribute('w:val');
+ // get the numbering style based on the numbering ID and its level
+ $numberingStyleNextSiblingElementTag = $this->getNumberingType($numIdNextSiblingElementTag->item(0)->getAttribute('w:val'), $numberingLevelNextSiblingElementTag);
+
+ // handle close list levels
+ if ($numberingLevel > 0 && $numIdNextSiblingElementTag->item(0)->getAttribute('w:val') != $numIdTag->item(0)->getAttribute('w:val')) {
+ $closeNewList = true;
+ $iterationListClose += $numberingLevel;
+ }
+
+ if ($numIdNextSiblingElementTag->item(0)->getAttribute('w:val') != $numIdTag->item(0)->getAttribute('w:val')) {
+ $closeNewList = true;
+ }
+
+ if ($numberingLevelNextSiblingElementTag < $numberingLevel) {
+ $closeNewList = true;
+ if ($numberingLevel > 1) {
+ $iterationListClose = $numberingLevel - $numberingLevelNextSiblingElementTag;
+ }
+ }
+ }
+ } else {
+ // the next element is not a numbering, then close the list
+ $closeNewList = true;
+
+ // handle close list levels
+ if ($numberingLevel > 0) {
+ $iterationListClose += $numberingLevel;
+ }
+ }
+ }
+
+ // get the numbering style based on the numbering ID and its level
+ $numberingStyle = $this->getNumberingType($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
+ if (in_array($numberingStyle, array('decimal', 'upperRoman', 'lowerRoman', 'upperLetter', 'lowerLetter'))) {
+ $tagTypeList = $this->htmlPlugin->getTag('orderedList');
+ } else {
+ $tagTypeList = $this->htmlPlugin->getTag('unorderedList');
+ }
+ if ($closeNewList === true) {
+ unset($this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')]);
+ for ($iClose = 0; $iClose < $iterationListClose; $iClose++) {
+ $this->html .= ''.$tagTypeList.'>';
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Transform w:r tag
+ *
+ * @param DOMElement $childNode
+ * @param String $nodeClass
+ */
+ protected function transformW_R($childNode, $nodeClass)
+ {
+ // default element
+ $elementTag = $this->htmlPlugin->getTag('span');
+
+ // sup or sub element
+ $vertAlignTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'vertAlign');
+ if ($vertAlignTag->length > 0) {
+ if ($vertAlignTag->item(0)->getAttribute('w:val') == 'superscript') {
+ $elementTag = $this->htmlPlugin->getTag('superscript');
+ } elseif ($vertAlignTag->item(0)->getAttribute('w:val') == 'subscript') {
+ $elementTag = $this->htmlPlugin->getTag('subscript');
+ }
+ }
+
+ // bidi element
+ $bidiTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'bidi');
+ if ($bidiTag->length > 0 && $bidiTag->item(0)->getAttribute('w:val') == 'on') {
+ $elementTag = $this->htmlPlugin->getTag('bidi');
+ }
+
+ // character style
+ $rStyle = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'rStyle');
+ $rStyleId = null;
+ if ($rStyle->length > 0) {
+ $rStyleId = $rStyle->item(0)->getAttribute('w:val');
+ if (!empty($rStyleId)) {
+ $this->css[$nodeClass . ' .character_' . $rStyleId] = '';
+ $this->css['_span.' . $nodeClass . ' .character_' . $rStyleId] = '';
+ }
+ }
+ $this->css['_span.' . $nodeClass] = '';
+
+ // handle styles
+ if ($childNode->hasChildNodes()) {
+ if ($rStyleId) {
+ $this->css[$nodeClass . ' .character_' . $rStyleId] .= $this->addRprStyles($childNode);
+ $this->css['_span.' . $nodeClass . ' .character_' . $rStyleId] .= $this->addRprStyles($childNode);
+ }
+ // rPr styles
+ $this->css[$nodeClass] .= $this->addRprStyles($childNode);
+ $this->css['_span.' . $nodeClass] .= $this->addRprStyles($childNode);
+ }
+
+ // if it's a text in a complex field, reuse the CSS class in the complex tag.
+ // Use a CSS only if there's a w:t in it to avoid other complex field tags
+ if ($this->complexField !== null) {
+ $tTag = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 't');
+ if ($tTag->length > 0) {
+ $this->html = str_replace('{{ CLASS_COMPLEX_FIELD }}', $nodeClass, $this->html);
+ }
+ }
+
+ // remove extra , and . before adding it to the HTML
+ $nodeClassHTML = str_replace(array(',', '.'), '', $nodeClass);
+
+ $this->html .= '<'.$elementTag.' class="'.$nodeClassHTML.' ' . ($this->htmlPlugin->getExtraClass('span')==null?'':$this->htmlPlugin->getExtraClass('span')) . '">';
+
+ // get endnote contents if any exist. This avoid adding the endnote content out of the tag
+ if ($this->endnotesContent != null) {
+ $this->html .= $this->endnotesContent;
+ $this->endnotesContent = null;
+ }
+
+ // get footnote contents if any exist. This avoid adding the footnote content out of the
tag
+ if ($this->footnotesContent != null) {
+ $this->html .= $this->footnotesContent;
+ $this->footnotesContent = null;
+ }
+
+ // get comment contents if any exist. This avoid adding the comment content out of the
tag
+ if ($this->commentsContent != null) {
+ $this->html .= $this->commentsContent;
+ $this->commentsContent = null;
+ }
+
+ // handle child elements
+ if ($childNode->hasChildNodes()) {
+ $this->transformXml($childNode);
+ }
+
+ $this->html .= ''.$elementTag.'>';
+ }
+
+ /**
+ * Transform w:sectpr tag
+ *
+ * @param DOMElement $childNode
+ * @param String $nodeClass
+ */
+ protected function transformW_SECTPR($childNode, $nodeClass)
+ {
+ // keep headers and footers to be added to the section
+ $headerContentSection = '';
+ $footerContentSection = '';
+
+ // parse sectPr tags and add the CSS values to the current section CSS class
+ $sectionCSS = '';
+ /*foreach ($childNode->childNodes as $childNodesSection) {
+ switch ($childNodesSection->nodeName) {
+ case 'w:headerReference':
+ $target = $this->getRelationshipContent($childNodesSection->getAttribute('r:id'));
+
+ $headerContentSection = $this->headersContent['word/' . $target];
+ break;
+ case 'w:footerReference':
+ $target = $this->getRelationshipContent($childNodesSection->getAttribute('r:id'));
+
+ $footerContentSection = $this->footersContent['word/' . $target];
+ break;
+ default:
+ break;
+ }
+ }*/
+
+ // add headers and footers
+ if (!empty($headerContentSection)) {
+ // remove the headaer placeholder to add the header contents to the correct place
+ $this->html = str_replace('__HEADERCONTENTSECTION__', $headerContentSection, $this->html);
+ } else {
+ // as there's no header contents, remove the placeholder
+ $this->html = str_replace('__HEADERCONTENTSECTION__', '', $this->html);
+ }
+ if (!empty($footerContentSection)) {
+ $this->html .= $footerContentSection;
+ }
+
+ $this->currentSection++;
+
+ // if there're more sections create them before contents are added
+ // get the first section to generate the initial page
+ $this->xmlXpathBody = new \DOMXPath($this->xmlBody);
+ $this->xmlXpathBody->registerNamespace('w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+
+ // first section size
+ $querySection = '//w:sectPr';
+ $secptPrNodes = $this->xmlXpathBody->query($querySection);
+ if ($secptPrNodes->length > $this->currentSection) {
+ $this->addSection();
+ }
+ }
+
+ /**
+ * Transform w:tbl tag
+ *
+ * @param DOMElement $childNode
+ * @param String $nodeClass
+ */
+ protected function transformW_TBL($childNode, $nodeClass)
+ {
+ $borderStylesTable = '';
+ $cellPadding = '';
+ $borderInsideStylesTable = '';
+
+ // table styles tblStyle
+ $elementsWTblprTblStyle = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'tblStyle');
+ if ($elementsWTblprTblStyle->length > 0) {
+ $tableStyleId = $elementsWTblprTblStyle->item(0)->getAttribute('w:val');
+ if (!empty($tableStyleId)) {
+ // get table styles
+ $xpathStyles = new \DOMXPath($this->stylesDocxDOM);
+ $xpathStyles->registerNamespace('w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+ $stylesTbl = $xpathStyles->query('//w:style[@w:styleId="' . $tableStyleId . '"]');
+ if ($stylesTbl->length > 0) {
+ $stylesTable = $this->getTableStyles($stylesTbl->item(0));
+ $this->css[$nodeClass] .= $stylesTable['tableStyles'];
+
+ // add extra properties replacing pending __CLASSNAMETABLE__ placeholders by the class name
+ if (isset($stylesTable['firstLastStyles']) && is_array($stylesTable['firstLastStyles'])) {
+ foreach ($stylesTable['firstLastStyles'] as $keyFirstLastStyles => $valueFirstLastStyles) {
+ if (!isset($this->css[str_replace('__CLASSNAMETABLE__', $nodeClass, $keyFirstLastStyles)])) {
+ $this->css[str_replace('__CLASSNAMETABLE__', $nodeClass, $keyFirstLastStyles)] = $valueFirstLastStyles;
+ } else {
+ $this->css[str_replace('__CLASSNAMETABLE__', $nodeClass, $keyFirstLastStyles)] .= $valueFirstLastStyles;
+ }
+ }
+ }
+
+ $borderStylesTable .= $stylesTable['borderStylesTable'];
+ $cellPadding .= $stylesTable['cellPadding'];
+ $borderInsideStylesTable .= $stylesTable['borderInsideStylesTable'];
+ }
+ }
+ }
+
+ // table properties
+ $elementWTblPr = $childNode->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'tblPr');
+ if ($elementWTblPr->length > 0) {
+ $stylesTable = $this->getTableStyles($childNode);
+ $this->css[$nodeClass] .= $stylesTable['tableStyles'];
+
+ // add extra properties replacing pending __CLASSNAMETABLE__ placeholders by the class name
+ if (isset($stylesTable['firstLastStyles']) && is_array($stylesTable['firstLastStyles'])) {
+ foreach ($stylesTable['firstLastStyles'] as $keyFirstLastStyles => $valueFirstLastStyles) {
+ $this->css[str_replace('__CLASSNAMETABLE__', $nodeClass, $keyFirstLastStyles)] .= $valueFirstLastStyles;
+ }
+ }
+
+ $borderStylesTable .= $stylesTable['borderStylesTable'];
+ $cellPadding .= $stylesTable['cellPadding'];
+ $borderInsideStylesTable .= $stylesTable['borderInsideStylesTable'];
+ }
+
+ // default values
+ $this->css[$nodeClass] .= 'border-spacing: 0; border-collapse: collapse;';
+
+ $this->html .= '