Beispiel #1
0
 /**
  *	{@inheritDoc}
  */
 public function extractAttributes($html, array $options)
 {
     $Document = $this->_document($html);
     $options = Hash::normalize($options, []);
     $data = [];
     foreach ($options as $name => $required) {
         $tags = $Document->getElementsByTagName($name);
         $required = Hash::normalize((array) $required, '');
         $data[$name] = [];
         foreach ($tags as $Tag) {
             if ($Tag->hasAttributes()) {
                 $attributes = $this->_extractAttributesFromTag($Tag, $required);
                 if (!empty($attributes)) {
                     $data[$name][] = $attributes;
                 }
             }
         }
     }
     return $data;
 }
Beispiel #2
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']));
 }
Beispiel #3
0
 /**
  *
  */
 public function testNormalize()
 {
     $data = Hash::normalize(['one', 'two' => 'three', 'four'], 'default');
     $this->assertEquals(['one' => 'default', 'two' => 'three', 'four' => 'default'], $data);
 }
Beispiel #4
0
 /**
  *	Fetches informations about the given URLs.
  *
  *	@param array $urls An array of URLs to fetch informations from.
  *	@param array $options Custom options to be interpreted by a provider.
  *	@return array An array of informations, indexed by URL.
  */
 public function extractAll(array $urls, array $options = [])
 {
     return Hash::combine($urls, function ($url) use($options) {
         (yield $url => $this->extract($url, $options));
     });
 }
Beispiel #5
0
 /**
  *	{@inheritDoc}
  */
 protected function _embed($url, array $options)
 {
     return new Media(Hash::reindex($this->_extractInformations($url), ['og:type' => 'type', 'og:title' => 'title', 'og:description' => 'description', 'og:site_name' => 'providerName', 'og:image' => 'thumbnailUrl', 'og:image:url' => 'thumbnailUrl', 'og:image:width' => 'width', 'og:image:height' => 'height', 'og:video:width' => 'width', 'og:video:height' => 'height', 'og:url' => 'url']));
 }
Beispiel #6
0
 /**
  *	Builds a media from the given meta tags.
  *
  *	@param array $metas Meta tags.
  *	@return Media Media.
  */
 protected function _media(array $metas)
 {
     $metas = Hash::combine($metas, function ($Meta) {
         (yield $Meta->get('property') => $Meta->get('content'));
     });
     return new Media($metas);
 }
Beispiel #7
0
 /**
  *	{@inheritDoc}
  */
 public function present(Media $Media)
 {
     return $Media->setProperties(Hash::reindex($Media->properties(), $this->_mapping));
 }