/**
  * Serves attachment by its id
  *  
  * @action serve
  * @param string $attachmentAssetId
  * @return file
  *  
  * @throws KalturaAttachmentErrors::ATTACHMENT_ASSET_ID_NOT_FOUND
  */
 public function serveAction($attachmentAssetId)
 {
     $attachmentAsset = null;
     if (!kCurrentContext::$ks) {
         $attachmentAsset = kCurrentContext::initPartnerByAssetId($attachmentAssetId);
         if (!$attachmentAsset || $attachmentAsset->getStatus() == asset::ASSET_STATUS_DELETED) {
             throw new KalturaAPIException(KalturaAttachmentErrors::ATTACHMENT_ASSET_ID_NOT_FOUND, $attachmentAssetId);
         }
         // enforce entitlement
         kEntitlementUtils::initEntitlementEnforcement();
     } else {
         $attachmentAsset = assetPeer::retrieveById($attachmentAssetId);
     }
     if (!$attachmentAsset || !$attachmentAsset instanceof AttachmentAsset) {
         throw new KalturaAPIException(KalturaAttachmentErrors::ATTACHMENT_ASSET_ID_NOT_FOUND, $attachmentAssetId);
     }
     $entry = entryPeer::retrieveByPK($attachmentAsset->getEntryId());
     if (!$entry) {
         //we will throw attachment asset not found, as the user is not entitled, and should not know that the entry exists.
         throw new KalturaAPIException(KalturaAttachmentErrors::ATTACHMENT_ASSET_ID_NOT_FOUND, $attachmentAssetId);
     }
     $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, accessControlContextType::DOWNLOAD);
     $securyEntryHelper->validateForDownload();
     $ext = $attachmentAsset->getFileExt();
     if (is_null($ext)) {
         $ext = 'txt';
     }
     $fileName = $attachmentAsset->getFilename();
     if (!$fileName) {
         $fileName = $attachmentAsset->getEntryId() . "_" . $attachmentAsset->getId() . ".{$ext}";
     }
     return $this->serveAsset($attachmentAsset, $fileName);
 }
Exemplo n.º 2
0
 /**
  * @param string $captionAssetId
  * @throws KalturaAPIException
  * @return CaptionAsset
  */
 protected function validateForDownload($captionAssetId)
 {
     $captionAsset = null;
     if (!kCurrentContext::$ks) {
         $captionAsset = kCurrentContext::initPartnerByAssetId($captionAssetId);
         if (!$captionAsset || $captionAsset->getStatus() == asset::ASSET_STATUS_DELETED) {
             throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
         kEntitlementUtils::initEntitlementEnforcement();
     } else {
         $captionAsset = assetPeer::retrieveById($captionAssetId);
     }
     if (!$captionAsset || !$captionAsset instanceof CaptionAsset) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
     }
     if (kCurrentContext::$ks_object && kCurrentContext::$ks_object->verifyPrivileges(CaptionPlugin::KS_PRIVILEGE_CAPTION, $captionAsset->getEntryId())) {
         return $captionAsset;
     }
     $entry = entryPeer::retrieveByPK($captionAsset->getEntryId());
     if (!$entry) {
         //we will throw caption asset not found, as the user is not entitled, and should not know that the entry exists.
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
     }
     $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, ContextType::DOWNLOAD);
     $securyEntryHelper->validateForDownload();
     return $captionAsset;
 }
 /**
  * Serves thumbnail by its id
  *  
  * @action serve
  * @param string $thumbAssetId
  * @param int $version
  * @return file
  *  
  * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  */
 public function serveAction($thumbAssetId, $version = null)
 {
     if (!kCurrentContext::$ks) {
         $thumbAsset = kCurrentContext::initPartnerByAssetId($thumbAssetId);
         if (!$thumbAsset || $thumbAsset->getStatus() == asset::ASSET_STATUS_DELETED) {
             throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
         }
         // enforce entitlement
         kEntitlementUtils::initEntitlementEnforcement();
     } else {
         $thumbAsset = assetPeer::retrieveById($thumbAssetId);
     }
     if (!$thumbAsset || !$thumbAsset instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $entry = entryPeer::retrieveByPK($thumbAsset->getEntryId());
     if (!$entry) {
         //we will throw thumb asset not found, as the user is not entitled, and should not know that the entry exists.
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, accessControlContextType::THUMBNAIL);
     $securyEntryHelper->validateAccessControl();
     $ext = $thumbAsset->getFileExt();
     if (is_null($ext)) {
         $ext = 'jpg';
     }
     $fileName = $thumbAsset->getEntryId() . "_" . $thumbAsset->getId() . ".{$ext}";
     return $this->serveAsset($thumbAsset, $fileName, $version);
 }
Exemplo n.º 4
0
 private function getFlavorAssetObject($flavorAssetId)
 {
     try {
         if (!kCurrentContext::$ks) {
             $flavorAsset = kCurrentContext::initPartnerByAssetId($flavorAssetId);
             // enforce entitlement
             $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
             kEntitlementUtils::initEntitlementEnforcement();
         } else {
             $flavorAsset = assetPeer::retrieveById($flavorAssetId);
         }
         if (!$flavorAsset || $flavorAsset->getStatus() == asset::ASSET_STATUS_DELETED) {
             throw new KalturaWidevineLicenseProxyException(KalturaWidevineErrorCodes::FLAVOR_ASSET_ID_NOT_FOUND);
         }
         return $flavorAsset;
     } catch (PropelException $e) {
         throw new KalturaWidevineLicenseProxyException(KalturaWidevineErrorCodes::FLAVOR_ASSET_ID_NOT_FOUND);
     }
 }
Exemplo n.º 5
0
 /**
  * Serves thumbnail by its id
  *  
  * @action serve
  * @param string $thumbAssetId
  * @param int $version
  * @param KalturaThumbParams $thumbParams
  * @param KalturaThumbnailServeOptions $options
  * @return file
  *  
  * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  */
 public function serveAction($thumbAssetId, $version = null, KalturaThumbParams $thumbParams = null, KalturaThumbnailServeOptions $options = null)
 {
     if (!kCurrentContext::$ks) {
         $thumbAsset = kCurrentContext::initPartnerByAssetId($thumbAssetId);
         if (!$thumbAsset || $thumbAsset->getStatus() == asset::ASSET_STATUS_DELETED) {
             throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
         kEntitlementUtils::initEntitlementEnforcement();
     } else {
         $thumbAsset = assetPeer::retrieveById($thumbAssetId);
     }
     if (!$thumbAsset || !$thumbAsset instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $entry = entryPeer::retrieveByPK($thumbAsset->getEntryId());
     if (!$entry) {
         //we will throw thumb asset not found, as the user is not entitled, and should not know that the entry exists.
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, ContextType::THUMBNAIL);
     $securyEntryHelper->validateAccessControl();
     $ext = $thumbAsset->getFileExt();
     if (is_null($ext)) {
         $ext = 'jpg';
     }
     $fileName = $thumbAsset->getEntryId() . "_" . $thumbAsset->getId() . ".{$ext}";
     if (!$thumbParams) {
         if ($options && $options->download) {
             header("Content-Disposition: attachment; filename=\"{$fileName}\"");
         }
         return $this->serveAsset($thumbAsset, $fileName, $version);
     }
     $thumbParams->validate();
     $syncKey = $thumbAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $version);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     /* @var $fileSync FileSync */
     if (!$local) {
         if (!in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         KalturaLog::info("Redirecting to [{$remoteUrl}]");
         header("Location: {$remoteUrl}");
         die;
     }
     $filePath = $fileSync->getFullPath();
     $thumbVersion = $thumbAsset->getId() . '_' . $version;
     $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $thumbVersion, $thumbParams->width, $thumbParams->height, $thumbParams->cropType, $thumbParams->backgroundColor, null, $thumbParams->quality, $thumbParams->cropX, $thumbParams->cropY, $thumbParams->cropWidth, $thumbParams->cropHeight, -1, 0, -1, $filePath, $thumbParams->density, $thumbParams->stripProfiles, null);
     if ($options && $options->download) {
         header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     }
     $mimeType = kFile::mimeType($tempThumbPath);
     return $this->dumpFile($tempThumbPath, $mimeType);
 }