Exemple #1
0
 /**
  * @param Uri $uri Absolute URL to get metadata for.
  * @return array|false
  */
 protected static function getRemoteUrlMetadata(Uri $uri)
 {
     $httpClient = new HttpClient();
     $httpClient->setTimeout(5);
     $httpClient->setStreamTimeout(5);
     if (!$httpClient->query('GET', $uri->getUri())) {
         return false;
     }
     if ($httpClient->getStatus() !== 200) {
         return false;
     }
     $htmlContentType = strtolower($httpClient->getHeaders()->getContentType());
     if ($htmlContentType !== 'text/html') {
         return static::getFileMetadata($httpClient->getEffectiveUrl(), $httpClient->getHeaders());
     }
     $html = $httpClient->getResult();
     $htmlDocument = new HtmlDocument($html, $uri);
     $htmlDocument->setEncoding($httpClient->getCharset());
     ParserChain::extractMetadata($htmlDocument);
     $metadata = $htmlDocument->getMetadata();
     if (is_array($metadata) && static::validateRemoteMetadata($metadata)) {
         if (isset($metadata['IMAGE']) && static::getOptionSaveImages()) {
             $metadata['IMAGE_ID'] = static::saveImage($metadata['IMAGE']);
             unset($metadata['IMAGE']);
         }
         return $metadata;
     }
     return false;
 }