AMP_DOM_Utils::create_node PHP Метод

create_node() публичный статический Метод

public static create_node ( $dom, $tag, $attributes )
    public static function create_node($dom, $tag, $attributes)
    {
        $node = $dom->createElement($tag);
        self::add_attributes_to_node($node, $attributes);
        return $node;
    }

Usage Example

Пример #1
0
 public function sanitize($amp_attributes = array())
 {
     $nodes = $this->dom->getElementsByTagName(self::$tag);
     $num_nodes = $nodes->length;
     if (0 === $num_nodes) {
         return;
     }
     for ($i = $num_nodes - 1; $i >= 0; $i--) {
         $node = $nodes->item($i);
         $old_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array($node);
         if (!array_key_exists('src', $old_attributes)) {
             $node->parentNode->removeChild($node);
             continue;
         }
         $new_attributes = $this->filter_attributes($old_attributes);
         if (!isset($new_attributes['width']) || !isset($new_attributes['height'])) {
             $dimensions = AMP_Image_Dimension_Extractor::extract($new_attributes['src']);
             if ($dimensions) {
                 $new_attributes['width'] = $dimensions[0];
                 $new_attributes['height'] = $dimensions[1];
             }
         }
         $new_attributes = $this->enforce_sizes_attribute($new_attributes);
         $new_attributes = array_merge($new_attributes, $amp_attributes);
         if ($this->is_gif_url($new_attributes['src'])) {
             $this->did_convert_elements = true;
             $new_tag = 'amp-anim';
         } else {
             $new_tag = 'amp-img';
         }
         $new_node = AMP_DOM_Utils::create_node($this->dom, $new_tag, $new_attributes);
         $node->parentNode->replaceChild($new_node, $node);
     }
 }
All Usage Examples Of AMP_DOM_Utils::create_node