AMP_DOM_Utils::get_node_attributes_as_assoc_array PHP Method

get_node_attributes_as_assoc_array() public static method

public static get_node_attributes_as_assoc_array ( $node )
    public static function get_node_attributes_as_assoc_array($node)
    {
        $attributes = array();
        if (!$node->hasAttributes()) {
            return $attributes;
        }
        foreach ($node->attributes as $attribute) {
            $attributes[$attribute->nodeName] = $attribute->nodeValue;
        }
        return $attributes;
    }

Usage Example

 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;
         }
         $this->did_convert_elements = true;
         $new_attributes = $this->filter_attributes($old_attributes);
         $new_attributes = $this->enforce_sizes_attribute($new_attributes);
         $new_attributes = array_merge($new_attributes, $amp_attributes);
         $new_node = AMP_DOM_Utils::create_node($this->dom, 'amp-iframe', $new_attributes);
         if (true === $this->args['add_placeholder']) {
             $placeholder_node = $this->build_placeholder($new_attributes);
             $new_node->appendChild($placeholder_node);
         }
         $parent_node = $node->parentNode;
         if ('p' === strtolower($parent_node->tagName)) {
             // AMP does not like iframes in p tags
             $parent_node->parentNode->replaceChild($new_node, $parent_node);
         } else {
             $parent_node->replaceChild($new_node, $node);
         }
     }
 }
All Usage Examples Of AMP_DOM_Utils::get_node_attributes_as_assoc_array