本文整理汇总了PHP中ezcDocumentElementVisitorConverter类的典型用法代码示例。如果您正苦于以下问题:PHP ezcDocumentElementVisitorConverter类的具体用法?PHP ezcDocumentElementVisitorConverter怎么用?PHP ezcDocumentElementVisitorConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ezcDocumentElementVisitorConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* 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)
{
// Locate optional attribution elements, and transform them below the
// recursive quote visiting.
$xpath = new DOMXPath($node->ownerDocument);
$attributionNodes = $xpath->query('*[local-name() = "attribution"]', $node);
$attributions = array();
foreach ($attributionNodes as $attribution) {
$attributions[] = $attribution->cloneNode(true);
$attribution->parentNode->removeChild($attribution);
}
// Recursively decorate blockquote, after all attribution nodes are
// removed
ezcDocumentDocbookToRstConverter::$indentation += 4;
$root = $converter->visitChildren($node, $root);
// Append attribution nodes, if any
foreach ($attributions as $attribution) {
$converter->setSkipPostDecoration(true);
$attributionLine = '-- ' . trim($converter->visitChildren($attribution, ''));
$converter->setSkipPostDecoration(false);
$root .= ezcDocumentDocbookToRstConverter::wordWrap($attributionLine) . "\n\n";
}
ezcDocumentDocbookToRstConverter::$indentation -= 4;
return $root;
}
示例2: getDirectiveParameters
/**
* 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);
}
示例3: getImageParameters
/**
* 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;
}
示例4: handle
/**
* 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;
}
示例5: handle
/**
* 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)
{
$element = $root->ownerDocument->createElement('literallayout');
$element->setAttribute('class', 'normal');
$root->parentNode->appendChild($element);
// Recurse
$converter->visitChildren($node, $element);
// Aggregate additional line block elements
if ($node->nextSibling && ($node->nextSibling->nodeType === XML_ELEMENT_NODE && $node->nextSibling->tagName === 'line' || $node->nextSibling->nodeType === XML_TEXT_NODE && trim($node->nextSibling->data) === '')) {
do {
if ($node->nextSibling->nodeType === XML_ELEMENT_NODE) {
$element->appendChild(new DOMText("\n"));
$converter->visitChildren($node->nextSibling, $element);
}
$node->parentNode->removeChild($node->nextSibling);
} while ($node->nextSibling && ($node->nextSibling->nodeType === XML_ELEMENT_NODE && $node->nextSibling->tagName === 'line' || $node->nextSibling->nodeType === XML_TEXT_NODE && trim($node->nextSibling->data) === ''));
}
// If there are any siblings, put them into a new paragraph node,
// "below" the list node.
if ($node->nextSibling) {
$newParagraph = $node->ownerDocument->createElement('paragraph');
do {
$newParagraph->appendChild($node->nextSibling->cloneNode(true));
$node->parentNode->removeChild($node->nextSibling);
} while ($node->nextSibling);
$node->parentNode->parentNode->appendChild($newParagraph);
}
return $root;
}
示例6: handle
/**
* 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;
}
示例7: handle
/**
* 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)
{
$type = $this->types[$node->tagName];
$content = $converter->visitChildren($node, '');
$root .= $this->renderDirective($type, '', array(), $content);
return $root;
}
示例8: handle
/**
* 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;
}
示例9: handle
/**
* 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->tagName === 'title') {
// Also set the document title from the first heading
if ($this->level === 1) {
$head = $this->getHead($root);
$title = $root->ownerDocument->createElement('title', htmlspecialchars(trim($node->textContent)));
$head->appendChild($title);
}
// Create common HTML headers
$header = $root->ownerDocument->createElement('h' . min(6, $this->level));
if ($this->level >= 6) {
$header->setAttribute('class', 'h' . $this->level);
}
$root->appendChild($header);
// Recurse
$converter->visitChildren($node, $header);
} else {
++$this->level;
// Set internal cross reference target if section has an ID assigned
if ($node->hasAttribute('ID')) {
$target = $root->ownerDocument->createElement('a');
$target->setAttribute('name', $node->getAttribute('ID'));
$root->appendChild($target);
}
// Recurse
$converter->visitChildren($node, $root);
// Reduce header level back to original state after recursion
--$this->level;
}
return $root;
}
示例10: handle
/**
* 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 (!$this->deepIgnore) {
return $converter->visitChildren($node, $root);
}
return $root;
}
示例11: handle
/**
* 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)
{
$p = $root->appendChild($root->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:p'));
$this->styler->applyStyles($node, $p);
$converter->visitChildren($node, $p);
return $root;
}
示例12: handle
/**
* 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)
{
// 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
$title = trim($converter->visitChildren($node, ''));
// 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;
}
示例13: handle
/**
* 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)
{
$footnoteContent = trim($converter->visitChildren($node, ''));
$number = $converter->appendFootnote($footnoteContent);
// Add autonumbered footnote reference
$root .= '[#]_ ';
return $root;
}
示例14: handle
/**
* 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)
{
$anchor = $root->ownerDocument->createElement('anchor');
$anchor->setAttribute('ID', $node->getAttribute('name'));
$root->appendChild($anchor);
$converter->visitChildren($node, $anchor);
return $root;
}
示例15: handle
/**
* 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)
{
$converter->setSkipPostDecoration(true);
$comment = $converter->visitChildren($node, '');
$converter->setSkipPostDecoration(false);
$root .= '.. ' . trim(ezcDocumentDocbookToRstConverter::wordWrap($comment, 3)) . "\n\n";
return $root;
}