Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getCode()
 {
     $url = new Url($this->request->url->getUrl());
     $url->setParameter('output', 'embed');
     $url->setParameter('s', '');
     return Utils::iframe($url->getUrl());
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public static function getEndPoint(Url $url)
 {
     if (is_numeric($url->getDirectoryPosition(1))) {
         return $url->createUrl()->withDirectoryPosition(2, 'oembed.json');
     }
     return '';
 }
Ejemplo n.º 3
0
 private static function addByAttribute($img, $attribute, \DOMElement $html, Bag $bag, $domain = null)
 {
     $src = $img->hasAttribute($attribute);
     if ($src) {
         $src = new Url($img->getAttribute($attribute));
         //Is src relative?
         if (!$src->getDomain()) {
             $bag->add('images', ['url' => $src->getUrl(), 'alt' => self::_getAltTag($img), 'href' => self::extractA($img, $bag->get('request_url'))]);
             return;
         }
         //Avoid external images or in external links
         if ($domain !== null) {
             if (!preg_match('~(ebayimg)~i', $src->getDomain())) {
                 return;
             }
             $bag->add('images', ['url' => $src->getUrl(), 'alt' => self::_getAltTag($img), 'href' => self::extractA($img, $bag->get('request_url'))]);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public static function getParams(Url $url)
 {
     return ['url' => $url->withScheme('http')->getUrl()];
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getImagesUrls()
 {
     $imagesUrls = Utils::getData($this->providers, 'imagesUrls', $this->request);
     $blacklist = $this->config['imagesBlacklist'];
     $hasBlacklist = is_array($blacklist) && count($blacklist) > 0;
     $imagesUrls = array_filter($imagesUrls, function ($imageUrl) use($blacklist, $hasBlacklist) {
         // Clean empty urls
         if (empty($imageUrl['value'])) {
             return false;
         }
         // Remove image url if on blacklist
         if ($hasBlacklist) {
             $url = new Url($imageUrl['value']);
             return !$url->match($blacklist) && !in_array($imageUrl['value'], $blacklist, true);
         }
         return true;
     });
     // Use array_values to reset keys after filter
     return array_values($imagesUrls);
 }
Ejemplo n.º 6
0
 /**
  * Extract <img> elements
  *
  * @param \DOMElement $html
  * @param Bag         $bag
  * @param null|string $domain
  */
 protected static function extractImages(\DOMElement $html, Bag $bag, $domain = null)
 {
     foreach ($html->getElementsByTagName('img') as $img) {
         if ($img->hasAttribute('src')) {
             $src = new Url($img->getAttribute('src'));
             //Is src relative?
             if (!$src->getDomain()) {
                 $bag->add('images', ['url' => $src->getUrl(), 'alt' => $img->hasAttribute('alt') ? $img->getAttribute('alt') : '', 'href' => self::extractA($img, $bag->get('request_url'))]);
                 continue;
             }
             //Avoid external images or in external links
             if ($domain !== null) {
                 if ($src->getDomain() !== $domain) {
                     continue;
                 }
                 $parent = $img->parentNode;
                 while ($parent && isset($parent->tagName)) {
                     if ($parent->tagName === 'a') {
                         if ($parent->hasAttribute('href')) {
                             $ahref = $parent->getAttribute('href');
                             $href = new Url($ahref);
                             //slow, very slow
                             //                                if(in_array(strtolower(pathinfo($ahref, PATHINFO_EXTENSION)), ['jpg', 'jpeg', 'png', 'gif'])) {
                             //                                    $src = new Url($ahref);
                             //                                    continue;
                             //                                }
                             if ($href->getDomain() && $src->getDomain() !== $domain) {
                                 continue 2;
                             }
                         }
                         if ($parent->hasAttribute('rel') && (string) $parent->getAttribute('rel') === 'nofollow') {
                             continue 2;
                         }
                         break;
                     }
                     $parent = $parent->parentNode;
                 }
                 $bag->add('images', ['url' => $src->getUrl(), 'alt' => $img->hasAttribute('alt') ? $img->getAttribute('alt') : '', 'href' => self::extractA($img, $bag->get('request_url'))]);
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Extract <img> elements
  *
  * @param \DOMElement $html
  * @param Bag         $bag
  * @param null|string $domain
  */
 protected static function extractImages(\DOMElement $html, Bag $bag, $domain = null)
 {
     foreach ($html->getElementsByTagName('img') as $img) {
         if ($img->hasAttribute('src')) {
             $src = new Url($img->getAttribute('src'));
             //Is src relative?
             if (!$src->getDomain()) {
                 $bag->add('images', $src->getUrl());
                 continue;
             }
             //Avoid external images or in external links
             if ($domain !== null) {
                 if ($src->getDomain() !== $domain) {
                     continue;
                 }
                 $parent = $img->parentNode;
                 while ($parent && isset($parent->tagName)) {
                     if ($parent->tagName === 'a') {
                         if ($parent->hasAttribute('href')) {
                             $href = new Url($parent->getAttribute('href'));
                             if ($href->getDomain() && $src->getDomain() !== $domain) {
                                 continue 2;
                             }
                         }
                         if ($parent->hasAttribute('rel') && (string) $parent->getAttribute('rel') === 'nofollow') {
                             continue 2;
                         }
                         break;
                     }
                     $parent = $parent->parentNode;
                 }
                 $bag->add('images', $src->getUrl());
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns the id found in an facebook url
  *
  * @param Url $url
  *
  * @return string
  */
 private function getId(Url $url)
 {
     if ($url->hasParameter('story_fbid')) {
         $this->isPost = true;
         return $url->getParameter('story_fbid');
     }
     if ($url->hasParameter('fbid')) {
         return $url->getParameter('fbid');
     }
     if ($url->hasParameter('id')) {
         return $url->getParameter('id');
     }
     if ($url->getDirectory(0) === 'events') {
         return $url->getDirectory(1);
     }
     if ($url->getDirectory(0) === 'pages') {
         return $url->getDirectory(2);
     }
     if ($url->getDirectory(1) === 'posts') {
         $this->isPost = true;
         return $url->getDirectory(2);
     }
     if ($url->getDirectory(2) === 'posts') {
         $this->isPost = true;
         return $url->getDirectory(3);
     }
     return $url->getDirectory(0);
 }
Ejemplo n.º 9
0
 /**
  * Returns the id found in a facebook url
  *
  * @param Url $url
  *
  * @return string
  */
 private function getId(Url $url)
 {
     if ($url->hasQueryParameter('story_fbid')) {
         $this->isEmbeddable = true;
         return $url->getQueryParameter('story_fbid');
     }
     if ($url->hasQueryParameter('fbid')) {
         return $url->getQueryParameter('fbid');
     }
     if ($url->hasQueryParameter('id')) {
         return $url->getQueryParameter('id');
     }
     if ($url->getDirectoryPosition(0) === 'events') {
         $this->isEmbeddable = true;
         return $url->getDirectoryPosition(1);
     }
     if ($url->getDirectoryPosition(0) === 'pages') {
         return $url->getDirectoryPosition(2);
     }
     if ($url->getDirectoryPosition(1) === 'posts') {
         $this->isEmbeddable = true;
         return $url->getDirectoryPosition(2);
     }
     if ($url->getDirectoryPosition(2) === 'posts') {
         $this->isEmbeddable = true;
         return $url->getDirectoryPosition(3);
     }
     return $url->getDirectoryPosition(0);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public static function getParams(Url $url)
 {
     return ['url' => $url->getUrl(), 'for' => 'embed'];
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function getCode()
 {
     $url = new Url($this->request->url->getUrl());
     $url->setDirectory(null, 'player');
     return Utils::iframe($url->getUrl(), $this->width, $this->height);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public static function getParams(Url $url)
 {
     return ['url' => $url->getUrl(), 'format' => 'json'];
 }
Ejemplo n.º 13
0
 /**
  * @access public
  * @author Oliver Lillie
  * @return array
  */
 public static function getParams(Url $url)
 {
     return ['url' => $url->getUrl()];
 }