当前位置: 首页>>代码示例>>PHP>>正文


PHP DOMElement::getElementsBytagName方法代码示例

本文整理汇总了PHP中DOMElement::getElementsBytagName方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::getElementsBytagName方法的具体用法?PHP DOMElement::getElementsBytagName怎么用?PHP DOMElement::getElementsBytagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOMElement的用法示例。


在下文中一共展示了DOMElement::getElementsBytagName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:42,代码来源:mediaobject.php

示例2: 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;
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:45,代码来源:mediaobject.php

示例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;
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:37,代码来源:mediaobject.php

示例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)
 {
     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;
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:24,代码来源:head.php

示例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)
 {
     $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;
 }
开发者ID:jackalope,项目名称:jr_cr_demo,代码行数:27,代码来源:head.php


注:本文中的DOMElement::getElementsBytagName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。