/** * @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(); } }
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); }
/** * @param EventInterface $event * @param ElementInterface $element * @param $tag */ public function handleBlockquote(EventInterface $event, ElementInterface $element, $tag) { $classAttr = explode(' ', $element->getAttribute('class')); if (in_array('twitter-tweet', $classAttr) && false !== ($twitterStatusId = $this->getStatusId($element))) { $container = $element->createWritableElement('div', ['class' => 'amp-twitter-container']); $container->appendChild($this->createAmpTwitterTag($element, $twitterStatusId)); $element->replaceWith($container); $event->stopPropagation(); } }
protected function handleMention(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)?/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: Noot! Noot!', [$payload['user']]), $channel); log_message('info', 'Interaction', sprintf('Replied to mention in %s.', $channel->getId())); }); }
protected function sendPingReport(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)? ping$/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: My current ping towards Slack is %ums.', [$payload['user'], $this->ping]), $channel); log_message('info', 'Ping', sprintf('Ping report posted to %s.', $channel->getId())); }); }
protected function handleCheckout(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)? checkout$/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: Not yet implemented. Sorry!', [$payload['user']]), $channel); log_message('info', 'Presence', sprintf('%s checked out.', $payload['user'])); }); }
protected function sendUptimeReport(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)? uptime$/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: My current uptime is %s.', [$payload['user'], $this->uptime->diffForHumans(new Carbon(), true)]), $channel); log_message('info', 'Uptime', sprintf('Uptime report posted to %s.', $channel->getId())); }); }
public function handleInstagram(EventInterface $event, ElementInterface $element) { if ($this->convertToAmp($element) == false) { return; } $shortcode = $this->getEmbedShortcode($element); if ($shortcode == null) { return; } $attrs = ['layout' => "responsive", 'width' => 600, 'height' => 384, 'data-shortcode' => $shortcode]; $element->replaceWith($element->createWritableElement('amp-instagram', $attrs)); $event->stopPropagation(); }
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(); } }
/** * @param \League\Event\EventInterface $event * * @return \Symfony\Component\HttpFoundation\Response */ public function handle(EventInterface $event) { $this->response->setStatusCode(404); $this->logger->addError(sprintf('Page "%s" could not be found.', $this->request->getPathInfo())); $event->stopPropagation(); }