is_node_empty() public static method

public static is_node_empty ( $node )
 public function test__is_node_empty__no__has_child()
 {
     $source = '<p><b></b></p>';
     $dom = AMP_DOM_Utils::get_dom_from_content($source);
     $node = $dom->getElementsByTagName('p')->item(0);
     $this->assertFalse(AMP_DOM_Utils::is_node_empty($node));
 }
 private function strip_tags($node, $tag_names)
 {
     foreach ($tag_names as $tag_name) {
         $elements = $node->getElementsByTagName($tag_name);
         $length = $elements->length;
         if (0 === $length) {
             continue;
         }
         for ($i = $length - 1; $i >= 0; $i--) {
             $element = $elements->item($i);
             $parent_node = $element->parentNode;
             $parent_node->removeChild($element);
             if ('body' !== $parent_node->nodeName && AMP_DOM_Utils::is_node_empty($parent_node)) {
                 $parent_node->parentNode->removeChild($parent_node);
             }
         }
     }
 }
 public function sanitize()
 {
     $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);
         if (!isset($new_attributes['height'])) {
             unset($new_attributes['width']);
             $new_attributes['height'] = self::FALLBACK_HEIGHT;
         }
         if (!isset($new_attributes['width'])) {
             $new_attributes['layout'] = 'fixed-height';
         }
         $new_attributes = $this->enforce_sizes_attribute($new_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->removeChild($node);
             $parent_node->parentNode->insertBefore($new_node, $parent_node->nextSibling);
             if (AMP_DOM_Utils::is_node_empty($parent_node)) {
                 $parent_node->parentNode->removeChild($parent_node);
             }
         } else {
             $parent_node->replaceChild($new_node, $node);
         }
     }
 }
 public function sanitize()
 {
     $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);
         $new_attributes = $this->filter_attributes($old_attributes);
         // If the src doesn't exist, remove the node.
         // This means that it never existed or was invalidated
         // while filtering attributes above.
         //
         // TODO: add a filter to allow for a fallback element in this instance.
         // See: https://github.com/ampproject/amphtml/issues/2261
         if (empty($new_attributes['src'])) {
             $node->parentNode->removeChild($node);
             continue;
         }
         $this->did_convert_elements = true;
         $new_attributes = $this->enforce_fixed_height($new_attributes);
         $new_attributes = $this->enforce_sizes_attribute($new_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->removeChild($node);
             $parent_node->parentNode->insertBefore($new_node, $parent_node->nextSibling);
             if (AMP_DOM_Utils::is_node_empty($parent_node)) {
                 $parent_node->parentNode->removeChild($parent_node);
             }
         } else {
             $parent_node->replaceChild($new_node, $node);
         }
     }
 }