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); }
/** * Extract a Twitter Status ID from a blockquote * @param $element * @return mixed|bool|string */ private function getStatusId(ElementInterface $element) { foreach ($element->getChildren() as $child) { if (preg_match('/status(?:es)?\\/(\\d+)/i', $child->getAttribute('href'), $match)) { return $match[1]; } } return false; }
private function convertChildren(ElementInterface $element) { if ($element->hasChildren()) { foreach ($element->getChildren() as $child) { $this->convertChildren($child); } } $this->convertToAmp($element); }
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'); }
public function handleObject(EventInterface $event, ElementInterface $element) { $embedCode = false; /** @var ElementInterface $child */ foreach ($element->getChildren() as $child) { if (1 === preg_match('/youtube\\.com\\/(?:v|embed)\\/([a-zA-z0-9_-]+)/i', $child->getAttribute('value'), $match)) { $embedCode = $match[1]; } } if ($embedCode !== false) { $container = $element->createWritableElement('div', ['class' => 'youtube-container']); $container->appendChild($this->createAmpTag($element, $embedCode)); $element->replaceWith($container); $event->stopPropagation(); } }