/**
  *	{@inheritDoc}
  */
 protected function _extract($url, array $options)
 {
     $html = $this->_Http->get($url);
     $metas = $this->_extractMetas($html);
     if (empty($metas)) {
         throw new Exception("Unable to extract meta tags from '{$url}'.");
     }
     return $this->_media($metas);
 }
Example #2
0
 /**
  *	Extracts OpenGraph informations from the given URL.
  *
  *	@param string $url URL to fetch informations from.
  *	@return array Extracted informations.
  */
 protected function _extractInformations($url)
 {
     $attributes = $this->_Dom->extractAttributes($this->_Http->get($url), ['meta' => ['property' => '#^og:.+#i', 'content']]);
     $og = [];
     if (empty($attributes['meta'])) {
         throw new Exception("Unable to extract OpenGraph data from '{$url}'.");
     } else {
         foreach ($attributes['meta'] as $meta) {
             if (!isset($og[$meta['property']])) {
                 $og[$meta['property']] = trim($meta['content']);
             }
         }
     }
     return $og;
 }
Example #3
0
 /**
  *	Builds or extracts an oEmbed config.
  *
  *	@param string $url URL.
  *	@param array $options Options.
  *	@return Config Configuration.
  */
 protected function _config($url, array $options)
 {
     $Config = $this->has('endpoint') ? $this->_buildConfig($url) : $this->_extractConfig($this->_Http->get($url));
     if ($options) {
         $Config->completeEndpoint($options);
     }
     return $Config;
 }
Example #4
0
 /**
  *	Fetches embed information from the given endpoint.
  *
  *	@param string $endpoint Endpoint to fetch informations from.
  *	@param string $format Response format.
  *	@return Media Embed informations.
  */
 protected function _embedEndpoint($endpoint, $format)
 {
     $response = $this->_Http->get($endpoint);
     switch ($format) {
         case self::json:
             $data = Json::parse($response);
             break;
         case self::xml:
             $data = Xml::parse($response);
             break;
         default:
             throw new Exception('Unsupported response format.');
     }
     return new Media(Hash::reindex($data, ['author_name' => 'authorName', 'author_url' => 'authorUrl', 'provider_name' => 'providerName', 'provider_url' => 'providerUrl', 'cache_age' => 'cacheAge', 'thumbnail_url' => 'thumbnailUrl', 'thumbnail_width' => 'thumbnailWidth', 'thumbnail_height' => 'thumbnailHeight']));
 }
Example #5
0
 /**
  *	Implementation of the extract method.
  *
  *	@see extract( )
  *	@param string $source The URL or HTML source to be extracted.
  *	@return array An array of extracted URLs.
  */
 protected function _extract($source)
 {
     if (filter_var($source, FILTER_VALIDATE_URL)) {
         try {
             $source = $this->_Http->get($source);
         } catch (Exception $Exception) {
             $this->_Logger->log(Logger::notice, "Unable to fetch {$source}", ['exception' => $Exception]);
             return [];
         }
     }
     $urls = $this->_extractUrls($source);
     $embeddable = [];
     foreach ($urls as $url) {
         if ($this->_Collection->hasProvider($url)) {
             $embeddable[] = $url;
         }
     }
     return array_unique($embeddable);
 }