/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if (ezcDocumentDocbookToRstConverter::$indentation > 0) { $converter->triggerError(E_WARNING, "Indented section found, cannot be represented in RST."); } // Reset indenteation level, ever we reach a new section ezcDocumentDocbookToRstConverter::$indentation = 0; if ($node->tagName === 'title') { // Get actual title string by recursing into the title node $converter->setSkipPostDecoration(true); $title = trim($converter->visitChildren($node, '')); $converter->setSkipPostDecoration(false); // Get RST title decoration characters if (!isset($converter->options->headerTypes[$this->level])) { $converter->triggerError(E_ERROR, "No characters for title of level {$this->level} defined."); return $root . $title; } if (strlen($marker = $converter->options->headerTypes[$this->level]) > 1) { return $root . sprintf("\n%s\n%s\n%s\n\n", $marker = str_repeat($marker[0], strlen($title)), $title, $marker); } else { return $root . sprintf("\n%s\n%s\n\n", $title, str_repeat($marker, strlen($title))); } } else { ++$this->level; // Set internal cross reference target if section has an ID assigned if ($node->hasAttribute('ID')) { $root .= '.. _' . $node->getAttribute('ID') . ":\n\n"; } // Recurse $root = $converter->visitChildren($node, $root); // Reduce header level back to original state after recursion --$this->level; } return $root; }
/** * Handle a node. * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if ($node->hasAttribute('anchor_name')) { // This is an internal reference $link = $root->ownerDocument->createElement('link'); $link->setAttribute('linked', $node->getAttribute('anchor_name')); $root->appendChild($link); } else { switch (true) { case $node->hasAttribute('url_id'): $method = 'fetchUrlById'; $value = $node->getAttribute('url_id'); break; case $node->hasAttribute('node_id'): $method = 'fetchUrlByNodeId'; $value = $node->getAttribute('node_id'); break; case $node->hasAttribute('object_id'): $method = 'fetchUrlByObjectId'; $value = $node->getAttribute('object_id'); break; default: $converter->triggerError(E_WARNING, 'Unhandled link type.'); return $root; } $link = $root->ownerDocument->createElement('ulink'); $link->setAttribute('url', $converter->options->linkProvider->{$method}($value, $node->hasAttribute('view') ? $node->getAttribute('view') : null, $node->hasAttribute('show_path') ? $node->getAttribute('show_path') : null)); $root->appendChild($link); } $converter->visitChildren($node, $link); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $drawingId = ++$this->counter; if (($imageData = $this->extractImageData($node)) === false) { $converter->triggerError(E_PARSE, 'Missing information in <meadiaobject /> or <inlinemediaobject />.'); return $root; } $frame = $root->appendChild($root->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_DRAWING, 'draw:frame')); $frame->setAttributeNS(ezcDocumentOdt::NS_ODT_DRAWING, 'draw:name', 'graphics' . $drawingId); $this->styler->applyStyles($node, $frame); $anchorType = $this->detectAnchorTye($node); $frame->setAttributeNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:anchor-type', $anchorType); if ($imageData->hasAttribute('width')) { $frame->setAttributeNS(ezcDocumentOdt::NS_ODT_SVG, 'svg:width', $this->correctLengthMeasure($converter, $imageData->getAttribute('width'))); } if ($imageData->hasAttribute('depth')) { $frame->setAttributeNS(ezcDocumentOdt::NS_ODT_SVG, 'svg:height', $this->correctLengthMeasure($converter, $imageData->getAttribute('depth'))); } $image = $frame->appendChild($root->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_DRAWING, 'draw:image')); $imgPath = $converter->getImageLocator()->locateImage($imgFile = $imageData->getAttribute('fileref')); if ($imgPath === false) { $converter->triggerError(E_WARNING, "Could not find image '{$imgFile}'."); return $root; } if (!is_readable($imgPath)) { $converter->triggerError(E_WARNING, "Image not readable '{$imgFile}'."); return $root; } $binaryData = $image->appendChild($root->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_OFFICE, 'office:binary-data', base64_encode(file_get_contents($imgPath)))); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if (!isset($this->mapping[$node->tagName])) { $converter->triggerError(E_WARNING, "Mapping handler used for element '{$node->tagName}', not known by the mapping handler."); return $root; } $element = $root->ownerDocument->createElement($this->mapping[$node->tagName]); $root->appendChild($element); // Recurse $converter->visitChildren($node, $element); return $root; }