Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function readLink(LinkInterface $link)
 {
     $client = $this->getClient();
     try {
         $response = $client->request('GET', $link->getUrl(), array_merge($this->config, ['on_stats' => function (TransferStats $stats) use(&$link) {
             $link->setEffectiveUrl($stats->getEffectiveUri());
         }]));
         $link->setContent($response->getBody())->setContentType($response->getHeader('Content-Type')[0]);
     } catch (ConnectException $e) {
         $link->setContent(false)->setContentType(false);
     }
     return $link;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function parseLink(LinkInterface $link)
 {
     preg_match(static::PATTERN, $link->getUrl(), $matches);
     $this->getPreview()->setId($matches[1])->setEmbed('<iframe id="viplayer" width="640" height="390" src="//player.vimeo.com/video/' . $this->getPreview()->getId() . '"" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Extract required data from html source
  * @param LinkInterface $link
  * @return array
  */
 protected function parseHtml(LinkInterface $link)
 {
     $images = [];
     try {
         $parser = new Crawler($link->getContent());
         // Parse all known tags
         foreach ($this->tags as $tag => $selectors) {
             foreach ($selectors as $selector) {
                 if ($parser->filter($selector['selector'])->count() > 0) {
                     if (isset($selector['attribute'])) {
                         ${$tag} = $parser->filter($selector['selector'])->first()->attr($selector['attribute']);
                     } else {
                         ${$tag} = $parser->filter($selector['selector'])->first()->text();
                     }
                     break;
                 }
             }
             // Default is empty string
             if (!isset(${$tag})) {
                 ${$tag} = '';
             }
         }
         // Parse all images on this page
         foreach ($parser->filter('img') as $image) {
             if (!$image->hasAttribute('src')) {
                 continue;
             }
             if (filter_var($image->getAttribute('src'), FILTER_VALIDATE_URL) === false) {
                 continue;
             }
             // This is not bulletproof, actual image maybe bigger than tags
             if ($image->hasAttribute('width') && $image->getAttribute('width') < $this->imageMinimumWidth) {
                 continue;
             }
             if ($image->hasAttribute('height') && $image->getAttribute('height') < $this->imageMinimumHeight) {
                 continue;
             }
             $images[] = $image->getAttribute('src');
         }
     } catch (\InvalidArgumentException $e) {
         // Ignore exceptions
     }
     $images = array_unique($images);
     if (!isset($cover) && count($images)) {
         $cover = $images[0];
     }
     return compact('cover', 'title', 'description', 'images', 'video', 'videoType');
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function parseLink(LinkInterface $link)
 {
     preg_match(static::PATTERN, $link->getUrl(), $matches);
     $this->getPreview()->setId($matches[1])->setEmbed('<iframe id="ytplayer" type="text/html" width="640" height="390" src="//www.youtube.com/embed/' . $this->getPreview()->getId() . '" frameborder="0"></iframe>');
     return $this;
 }