/** * Extract directive parameters * * Extract the image directive parameters from a media object or inline * media object node in the Docbook document. Returns an array with * named keys containing the directive parameters. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @return array */ protected function getDirectiveParameters(ezcDocumentElementVisitorConverter $converter, DOMElement $node) { // Get image resource $resource = $node->getElementsBytagName('imagedata')->item(0); $parameter = $resource->getAttribute('fileref'); $options = array(); $content = null; // Transform attributes $attributes = array('width' => 'width', 'depth' => 'height'); foreach ($attributes as $src => $dst) { if ($resource->hasAttribute($src)) { $options[$dst] = $resource->getAttribute($src); } } // Check if the image has a description if (($textobject = $node->getElementsBytagName('textobject')) && $textobject->length > 0) { $options['alt'] = trim($textobject->item(0)->textContent); } // Check if the image has additional description assigned. In such a // case we wrap the image and the text inside another block. if (($textobject = $node->getElementsBytagName('caption')) && $textobject->length > 0) { $textobject = $textobject->item(0); // Decorate the childs of the caption node recursively, as it might // contain additional markup. $content = $converter->visitChildren($textobject, ''); } // If the directive has explicit content, we render it as a figure // instead of an image. $type = $content !== null ? 'figure' : 'image'; return array('type' => $type, 'parameter' => $parameter, 'options' => $options, 'content' => $content); }
/** * 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) { // Get image resource $resource = $node->getElementsBytagName('imagedata')->item(0); $image = $root->ownerDocument->createElement('img'); // Transform attributes $attributes = array('width' => 'width', 'depth' => 'height', 'fileref' => 'src'); foreach ($attributes as $src => $dst) { if ($resource->hasAttribute($src)) { $image->setAttribute($dst, htmlspecialchars($resource->getAttribute($src))); } } // Check if the image has a description if (($textobject = $node->getElementsBytagName('textobject')) && $textobject->length > 0) { $image->setAttribute('alt', htmlspecialchars(trim($textobject->item(0)->textContent))); } else { // Always set some alt value, as this is required by XHtml $image->setAttribute('alt', htmlspecialchars($resource->getAttribute('src'))); } // Check if the image has additional description assigned. In such a // case we wrap the image and the text inside another block. if (($textobject = $node->getElementsBytagName('caption')) && $textobject->length > 0) { $textobject = $textobject->item(0); $wrapper = $root->ownerDocument->createElement('div'); $wrapper->setAttribute('class', 'image'); $wrapper->appendChild($image); // Decorate the childs of the caption node recursively, as it might // contain additional markup. $textobject = $converter->visitChildren($textobject, $wrapper); $image = $wrapper; } $root->appendChild($image); return $root; }
/** * Extract image parameters * * Extract the image parameters from a media object or inline media object * node in the Docbook document. Returns an array with named keys * containing the directive parameters. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @return array */ protected function getImageParameters(ezcDocumentElementVisitorConverter $converter, DOMElement $node) { $resource = $node->getElementsBytagName('imagedata')->item(0); $options = array('resource' => $resource->getAttribute('fileref')); // Get image resource // Transform attributes $attributes = array('width' => 'width', 'depth' => 'height'); foreach ($attributes as $src => $dst) { if ($resource->hasAttribute($src)) { $options[$dst] = $resource->getAttribute($src); } } // Check if the image has a description if (($textobject = $node->getElementsBytagName('textobject')) && $textobject->length > 0) { $options['alt'] = trim($textobject->item(0)->textContent); } // Check if the image has additional description assigned. In such a // case we wrap the image and the text inside another block. if (($textobject = $node->getElementsBytagName('caption')) && $textobject->length > 0) { $textobject = $textobject->item(0); // Decorate the childs of the caption node recursively, as it might // contain additional markup. $options['text'] = preg_replace('(\\s+)', ' ', $converter->visitChildren($textobject, '')); } return $options; }
/** * 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) { foreach ($this->headerMapping as $tagName => $metaName) { if (($nodes = $node->getElementsBytagName($tagName)) && $nodes->length > 0) { foreach ($nodes as $child) { $root .= ":{$metaName}:\n"; $root .= ezcDocumentDocbookToRstConverter::wordWrap(trim($converter->visitChildren($child, '')), 2); $root .= "\n"; } } } 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) { $headerMapping = $converter->options->dublinCoreMetadata ? $this->dcHeaderMapping : $this->headerMapping; $head = $this->getHead($root); foreach ($headerMapping as $tagName => $metaName) { if (($nodes = $node->getElementsBytagName($tagName)) && $nodes->length > 0) { foreach ($nodes as $child) { $meta = $root->ownerDocument->createElement('meta'); $meta->setAttribute('name', $metaName); $meta->setAttribute('content', htmlspecialchars(trim($child->textContent))); $head->appendChild($meta); } } } return $root; }