function it_skips_converting_non_youtube_object_tags(EventInterface $event, ElementInterface $element, ElementInterface $childElement)
 {
     $element->getChildren()->shouldBeCalled()->willReturn([$childElement]);
     $childElement->getAttribute('value')->shouldBeCalled()->willReturn('http://metube.com/embed/XGSy3_Czz8k');
     $event->stopPropagation()->shouldNotBeCalled();
     $element->createWritableElement('div', ['class' => 'youtube-container'])->shouldNotBeCalled();
     $this->handleObject($event, $element);
 }
 public function convertToAmp(ElementInterface $element)
 {
     if ($element->hasChildren() == false) {
         return false;
     }
     $hasClass = in_array('instagram-media', explode(' ', $element->getAttribute('class')));
     $hasAttr = array_key_exists('data-instgrm-version', $element->getAttributes());
     return $hasClass || $hasAttr;
 }
 public function handleTagImg(EventInterface $event, ElementInterface $element)
 {
     /** @var ElementInterface $ampImg */
     $ampImg = $element->createWritableElement('amp-img');
     foreach ($this->validAttributes as $attribute) {
         if ($element->getAttribute($attribute)) {
             $ampImg->setAttribute($attribute, $element->getAttribute($attribute));
         }
     }
     return $element->replaceWith($ampImg);
 }
 /**
  * @param ElementInterface $element
  *
  * @return string
  */
 public function handleTagImg(EventInterface $event, ElementInterface $element)
 {
     // Should mutate all images and stop propagation
     if (function_exists('cloudinary_url')) {
         $src = $element->getAttribute('src');
         $width = $element->getAttribute('width');
         $height = $element->getAttribute('height');
         $sizes = $this->generateSizes();
         $srcset = $this->generateSrcset($src);
         $urlConfig = ['width' => 400, 'height' => 225, 'crop' => 'limit', 'sign_url' => true, 'type' => 'fetch', 'effect' => 'sharpen'];
         if ($width < 100 || $height < 100) {
             $width = $urlConfig['width'];
             $height = $urlConfig['height'];
         } else {
             $urlConfig['width'] = $width;
             $urlConfig['height'] = $height;
         }
         // Create the responsive <amp-img /> tag
         $ampImg = $element->createWritableElement('amp-img');
         $ampImg->setAttribute('src', cloudinary_url($src, $urlConfig));
         $ampImg->setAttribute('width', $width);
         $ampImg->setAttribute('height', $height);
         $ampImg->setAttribute('sizes', $sizes);
         $ampImg->setAttribute('srcset', $srcset);
         $ampImg->setAttribute('layout', 'responsive');
         $ampImg->setAttribute('alt', $element->getAttribute('alt'));
         $ampImg->setAttribute('attribution', $element->getAttribute('attribution'));
         $ampImg->setAttribute('class', 'amp-img');
         $element->replaceWith($ampImg);
         $event->stopPropagation();
     }
 }
 public function it_finds_the_instagram_code(ElementInterface $element)
 {
     $prophet = new Prophet();
     $anchor = $prophet->prophesize('Predmond\\HtmlToAmp\\Element');
     $anchor->getAttribute('href')->willReturn('https://www.instagram.com/p/AAA-aaa/');
     $sibling = $prophet->prophesize('Predmond\\HtmlToAmp\\Element');
     $sibling->getAttribute('href')->willReturn('');
     $parent = $prophet->prophesize('Predmond\\HtmlToAmp\\Element');
     $parent->getAttribute('href')->willReturn('');
     $parent->getChildren()->willReturn([$anchor, $sibling]);
     $element->getAttribute('href')->willReturn('');
     $element->getChildren()->willReturn([$parent]);
     $this->getEmbedShortcode($element)->shouldBe('AAA-aaa');
 }
Beispiel #6
0
 /**
  * Replace current element with a new DOMNode
  *
  * @param $node
  * @return DOMNode|bool
  */
 public function replaceWith(ElementInterface $element)
 {
     if ($this->node->parentNode !== null) {
         return $this->node->parentNode->replaceChild($element->getNode(), $this->getNode());
     }
     return false;
 }
 /**
  * Create an amp-twitter tag
  *
  * @param ElementInterface $element
  * @param $twitterStatusId
  * @return ElementInterface
  */
 private function createAmpTwitterTag(ElementInterface $element, $twitterStatusId)
 {
     return $element->createWritableElement('amp-twitter', ['layout' => 'responsive', 'data-tweetid' => $twitterStatusId, 'width' => 390, 'height' => 330, 'data-cards' => 'hidden']);
 }
 public function it_converts_an_image_to_amp_img(ElementInterface $ampImg, EventInterface $event, ElementInterface $element)
 {
     $ampImg->setAttribute('src', 'foo.jpg')->shouldBeCalled();
     $ampImg->setAttribute('width', 300)->shouldBeCalled();
     $ampImg->setAttribute('height', 250)->shouldBeCalled();
     $ampImg->setAttribute('class', 'amp-img')->shouldBeCalled();
     $ampImg->setAttribute('srcset', '')->shouldNotBeCalled();
     $ampImg->setAttribute('alt', '')->shouldNotBeCalled();
     $ampImg->setAttribute('attribution', '')->shouldNotBeCalled();
     $element->getAttribute('src')->shouldBeCalled()->willReturn('foo.jpg');
     $element->getAttribute('width')->shouldBeCalled()->willReturn(300);
     $element->getAttribute('height')->shouldBeCalled()->willReturn(250);
     $element->getAttribute('class')->shouldBeCalled()->willReturn('amp-img');
     $element->getAttribute('srcset')->shouldBeCalled()->willReturn('');
     $element->getAttribute('alt')->shouldBeCalled()->willReturn('');
     $element->getAttribute('attribution')->shouldBeCalled()->willReturn('');
     $element->createWritableElement('amp-img')->willReturn($ampImg);
     $element->replaceWith($ampImg)->shouldBeCalled();
     $this->handleTagImg($event, $element);
 }
Beispiel #9
0
 private function convertToAmp(ElementInterface $element)
 {
     $tag = $element->getTagName();
     /** @var ConverterInterface $converter */
     $event = $this->environment->getEventEmitter()->emit("convert.{$tag}", $element, $tag);
 }
 /**
  * @param ElementInterface $element
  * @param $embedCode
  * @return ElementInterface
  */
 private function createAmpTag(ElementInterface $element, $embedCode)
 {
     return $element->createWritableElement('amp-youtube', ['data-videoid' => $embedCode, 'layout' => 'responsive', 'width' => '560', 'height' => '315']);
 }