You are here

public function AcquiaDAM_Assets_AbstractAsset::getPreviewUrl in Media: Acquia DAM 7

Get the URL to the DAM-provided preview if possible.

Parameters

int $thumbnailSize: Find the closest thumbnail size without going over when multiple thumbnails are available.

Return value

string|false The preview URL or FALSE if none available.

File

src/AcquiaDAM/AcquiaDAM_Assets_AbstractAsset.inc, line 296

Class

AcquiaDAM_Assets_AbstractAsset
Abstract class base for Acquia DAM assets.

Code

public function getPreviewUrl($thumbnailSize = 1280) {
  $this
    ->get();

  // Audio files.
  if (!empty($this->asset['audiourl']['url'])) {
    return $this->asset['audiourl']['url'];
  }
  elseif (!empty($this->asset['videourls'][0]['url'])) {
    return $this->asset['videourls'][0]['url'];
  }
  elseif (!empty($this->asset['filetype']) && 'pdf' == $this->asset['filetype'] && !empty($this->asset['thumbnailurls'])) {

    // The embed code returned by the API uses the 550 thumbnail URL as the
    // base for a CDN link to the document. We can construct that URL by
    // combining a few elements.
    foreach ($this->asset['thumbnailurls'] as $tn) {
      if (!empty($tn['size']) && 550 == $tn['size'] && !empty($tn['url'])) {
        $url = drupal_parse_url($tn['url']);
        $url = sprintf('%s.%s', $url['path'], $this->asset['filetype']);
        $url = url($url, [
          'query' => [
            'v' => $this->asset['version'],
          ],
        ]);
        return $url;
      }
    }
  }
  else {
    return $this
      ->getThumbnailUrl($thumbnailSize);
  }
  return FALSE;
}