Esempio n. 1
0
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     $entryId = $this->getRequestParameter("entry_id");
     $flavorId = $this->getRequestParameter("flavor");
     $fileName = $this->getRequestParameter("file_name");
     $ksStr = $this->getRequestParameter("ks");
     $referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     // get entry
     $entry = entryPeer::retrieveByPK($entryId);
     if (is_null($entry)) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer);
     $securyEntryHelper->validateForDownload($entry, $ksStr);
     $flavorAsset = null;
     if ($flavorId) {
         // get flavor asset
         $flavorAsset = flavorAssetPeer::retrieveById($flavorId);
         if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
         // the request flavor should belong to the requested entry
         if ($flavorAsset->getEntryId() != $entryId) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
     } else {
         $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($entry->getId());
     }
     // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source
     if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) {
         $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     }
     if ($flavorAsset) {
         $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset);
     } else {
         $syncKey = $this->getBestSyncKeyForEntry($entry);
     }
     list($fileBaseName, $fileExt) = $this->getFileName($entry, $flavorAsset);
     if (!$fileName) {
         $fileName = $fileBaseName;
     }
     if ($fileExt) {
         $fileName = $fileName . '.' . $fileExt;
     }
     if (is_null($syncKey)) {
         KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
     }
     $this->handleFileSyncRedirection($syncKey);
     $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     $this->dumpFile($filePath, $fileName);
     die;
     // no view
 }
Esempio n. 2
0
 public function getThumbnailUrl(KSecureEntryHelper $securyEntryHelper, $storageId = null, KalturaThumbParams $thumbParams = null)
 {
     if ($thumbParams) {
         $assetUrl = $this->getDownloadUrlWithExpiry(84600);
         $assetParameters = KalturaRequestParameterSerializer::serialize($thumbParams, "thumbParams");
         $thumbnailUrl = $assetUrl . "?thumbParams:objectType=KalturaThumbParams&" . implode("&", $assetParameters);
     }
     if ($storageId) {
         $thumbnailUrl = $this->getExternalUrl($storageId);
     }
     $thumbnailUrl = $this->getDownloadUrl(true);
     /* @var $serverNode EdgeServerNode */
     $serverNode = $securyEntryHelper->shouldServeFromServerNode();
     if (!$serverNode) {
         return $thumbnailUrl;
     }
     $urlParts = explode("://", $thumbnailUrl);
     return $urlParts[0] . "://" . $serverNode->buildEdgeFullPath('http', null, null, assetType::THUMBNAIL) . $urlParts[1];
 }
Esempio n. 3
0
 private function validateAccessControl(entry $entry, flavorAsset $flavorAsset, $referrer64base)
 {
     $referrer = base64_decode(str_replace(" ", "+", $referrer64base));
     if (!is_string($referrer)) {
         $referrer = "";
     }
     // base64_decode can return binary data
     $secureEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, $referrer, ContextType::PLAY);
     if (!$secureEntryHelper->isKsAdmin()) {
         if (!$entry->isScheduledNow()) {
             throw new KalturaWidevineLicenseProxyException(KalturaWidevineErrorCodes::ENTRY_NOT_SCHEDULED_NOW);
         }
         if ($secureEntryHelper->isEntryInModeration()) {
             throw new KalturaWidevineLicenseProxyException(KalturaWidevineErrorCodes::ENTRY_MODERATION_ERROR);
         }
     }
     if ($secureEntryHelper->shouldBlock()) {
         throw new KalturaWidevineLicenseProxyException(KalturaWidevineErrorCodes::ACCESS_CONTROL_RESTRICTED);
     }
     if (!$secureEntryHelper->isAssetAllowed($flavorAsset)) {
         throw new KalturaWidevineLicenseProxyException(KalturaWidevineErrorCodes::FLAVOR_ASSET_ID_NOT_FOUND);
     }
 }
 function checkForPreview(KSecureEntryHelper $securyEntryHelper, $clip_to)
 {
     $request = $_SERVER["REQUEST_URI"];
     $preview_length_msec = $securyEntryHelper->getPreviewLength() * 1000;
     if ((int) $clip_to !== (int) $preview_length_msec) {
         if (strpos($request, '/clip_to/') !== false) {
             if ($preview_length_msec === 0) {
                 header("Content-Type: video/x-flv");
                 die;
             }
             $request = str_replace('/clip_to/' . $clip_to, '/clip_to/' . $preview_length_msec, $request);
             header("Location: {$request}");
         } else {
             if (strpos($request, "?") !== false) {
                 $last_slash = strrpos($request, "/");
                 $request = substr_replace($request, "/clip_to/{$preview_length_msec}", $last_slash, 0);
                 header("Location: {$request}");
             } else {
                 header("Location: {$request}/clip_to/{$preview_length_msec}");
             }
         }
         die;
     }
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 /**
  * Serves the file content
  * 
  * @action serveByFlavorParamsId
  * @param string $entryId Document entry id
  * @param string $flavorParamsId Flavor params id
  * @param bool $forceProxy force to get the content without redirect
  * @return file
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY
  * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND
  */
 public function serveByFlavorParamsIdAction($entryId, $flavorParamsId = null, $forceProxy = false)
 {
     // temporary workaround for getting the referrer from a url with the format ....&forceProxy/true/referrer/...
     $referrer = null;
     if (isset($_GET["forceProxy"]) && kString::beginsWith($_GET["forceProxy"], "true/referrer/")) {
         $referrer = substr($_GET["forceProxy"], strlen("true/referrer/"));
         $referrer = base64_decode($referrer);
     }
     KalturaResponseCacher::disableCache();
     myPartnerUtils::resetPartnerFilter('entry');
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != entryType::DOCUMENT) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ksObj = $this->getKs();
     $ks = $ksObj ? $ksObj->getOriginalString() : null;
     $securyEntryHelper = new KSecureEntryHelper($dbEntry, $ks, $referrer, ContextType::DOWNLOAD);
     $securyEntryHelper->validateForDownload();
     $flavorAsset = null;
     if ($flavorParamsId) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId);
         if (!$flavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorParamsId);
         }
     } else {
         $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
         if (!$flavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId);
         }
     }
     if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId);
     }
     $fileName = $dbEntry->getName() . '.' . $flavorAsset->getFileExt();
     return $this->serveFlavorAsset($flavorAsset, $fileName, $forceProxy);
 }
Esempio n. 7
0
 /**
  * serve action returan the file from dataContent field.
  * 
  * @action serve
  * @serverOnly
  * @param string $entryId Data entry id
  * @param int $version Desired version of the data
  * @param bool $forceProxy force to get the content without redirect
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  */
 function serveAction($entryId, $version = -1, $forceProxy = false)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DATA) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ksObj = $this->getKs();
     $ks = $ksObj ? $ksObj->getOriginalString() : null;
     $securyEntryHelper = new KSecureEntryHelper($dbEntry, $ks, null);
     $securyEntryHelper->validateForDownload();
     if (!$version || $version == -1) {
         $version = null;
     }
     $fileName = $dbEntry->getName();
     $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         kFile::dumpFile($filePath, $mimeType);
     } else {
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         KalturaLog::info("Redirecting to [{$remoteUrl}]");
         if ($forceProxy) {
             kFile::dumpUrl($remoteUrl);
         } else {
             // or redirect if no proxy
             header("Location: {$remoteUrl}");
         }
     }
 }
Esempio n. 8
0
 /**
  * Ensure the request for media arrived in a way approved by the partner.
  * this may include restricting to a specific cdn, enforcing token usage etc..
  * Die in case of a breach.
  * 
  * @param entry $entry
  * @param asset $asset
  */
 public static function enforceDelivery($entry, $asset = null)
 {
     // block inactive partner
     $partnerId = $entry->getPartnerId();
     self::blockInactivePartner($partnerId);
     // validate serve access control
     $flavorParamsId = $asset ? $asset->getFlavorParamsId() : null;
     $secureEntryHelper = new KSecureEntryHelper($entry, null, null, ContextType::SERVE);
     $secureEntryHelper->validateForServe($flavorParamsId);
     // enforce delivery
     $partner = PartnerPeer::retrieveByPK($partnerId);
     // Note: Partner was already loaded by blockInactivePartner, no need to check for null
     $restricted = DeliveryProfilePeer::isRequestRestricted($partner);
     if ($restricted) {
         KalturaLog::log("DELIVERY_METHOD_NOT_ALLOWED partner [{$partnerId}]");
         KExternalErrors::dieError(KExternalErrors::DELIVERY_METHOD_NOT_ALLOWED);
     }
 }
Esempio n. 9
0
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     requestUtils::handleConditionalGet();
     $entry_id = $this->getRequestParameter("entry_id");
     $type = $this->getRequestParameter("type");
     $ks = $this->getRequestParameter("ks");
     $file_sync = null;
     $ret_file_name = "name";
     $referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     $request_file_name = $this->getRequestParameter("file_name");
     if ($request_file_name) {
         $ret_file_name = $request_file_name;
     }
     $direct_serve = $this->getRequestParameter("direct_serve");
     $entry = entryPeer::retrieveByPK($entry_id);
     if (!$entry) {
         // what to return ??
         die;
     }
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     $securyEntryHelper = new KSecureEntryHelper($entry, $ks, $referrer);
     $securyEntryHelper->validateForDownload();
     //		Rmoved by Tan-Tan - asked by Eran
     //		// allow access only via cdn unless these are documents (due to the current implementation of convert ppt2swf)
     //		if ($entry->getType() != entryType::DOCUMENT && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_IMAGE)
     //		{
     //			requestUtils::enforceCdnDelivery($entry->getPartnerId());
     //		}
     // relocate = did we use the redirect and added the extension to the name
     $relocate = $this->getRequestParameter("relocate");
     if ($ret_file_name == "name") {
         $ret_file_name = $entry->getName();
     }
     if ($ret_file_name) {
         //rawurlencode to content-disposition filename to handle spaces and other characters across different browsers
         //$name = rawurlencode($ret_file_name);
         // 19.04.2009 (Roman) - url encode is not needed when the filename in Content-Disposition header is in quotes
         // IE6/FF3/Chrome - Will show the filename correctly
         // IE7 - Will show the filename with underscores instead of spaces (this is better than showing %20)
         $name = $ret_file_name;
         if ($name) {
             if ($relocate) {
                 // if we have a good file extension (from the first time) - use it in the content-disposition
                 // in some browsers it will be stronger than the URL's extension
                 $file_ext = pathinfo($relocate, PATHINFO_EXTENSION);
                 $name .= ".{$file_ext}";
             }
             if (!$direct_serve) {
                 header("Content-Disposition: attachment; filename=\"{$name}\"");
             }
         }
     } else {
         $ret_file_name = $entry_id;
     }
     $format = $this->getRequestParameter("format");
     if ($type == "download" && $format && $entry->getType() != entryType::DOCUMENT) {
         // this is a video for a specifc extension - use the proper flavorAsset
         $flavor_asset = flavorAssetPeer::retrieveByEntryIdAndExtension($entry_id, $format);
         if ($flavor_asset && $flavor_asset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             $file_sync = $this->redirectIfRemote($flavor_asset, flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, null, true);
         } else {
             header('KalturaRaw: no flavor asset for extension');
             header("HTTP/1.0 404 Not Found");
             die;
         }
         $archive_file = $file_sync->getFullPath();
         $mime_type = kFile::mimeType($archive_file);
         kFile::dumpFile($archive_file, $mime_type);
     }
     // TODO - move to a different action - document should be plugin
     if ($entry->getType() == entryType::DOCUMENT) {
         // use the fileSync from the entry
         if ($type == "download" && $format) {
             $flavor_asset = flavorAssetPeer::retrieveByEntryIdAndExtension($entry_id, $format);
         } else {
             $flavor_asset = flavorAssetPeer::retrieveOriginalByEntryId($entry_id);
         }
         if ($flavor_asset && $flavor_asset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             $file_sync = $this->redirectIfRemote($flavor_asset, flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, null, true);
         } else {
             header('KalturaRaw: no flavor asset for extension');
             header("HTTP/1.0 404 Not Found");
             die;
         }
         // Gonen 2010-08-05 workaround to make sure file name includes correct extension
         // make sure a file extension is added to the downloaded file so browser will identify and
         // allow opening with default program
         // for direct serve we do not want to send content-disposition header
         if (!$direct_serve) {
             $ext = pathinfo($file_sync->getFullPath(), PATHINFO_EXTENSION);
             if ($relocate) {
                 // remove relocate file extension
                 $reloc_ext = pathinfo($relocate, PATHINFO_EXTENSION);
                 $name = str_replace(".{$reloc_ext}", '', $name);
             }
             header("Content-Disposition: attachment; filename=\"{$name}.{$ext}\"");
         }
         kFile::dumpFile($file_sync->getFullPath());
     } elseif ($entry->getType() == entryType::DATA) {
         $version = $this->getRequestParameter("version");
         $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $version);
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if ($local) {
             $path = $fileSync->getFullPath();
         } else {
             $path = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$path}]");
         }
         if (!$path) {
             header('KalturaRaw: no data was found available for download');
             header("HTTP/1.0 404 Not Found");
         } else {
             kFile::dumpFile($path);
         }
     }
     //$archive_file = $entry->getArchiveFile();
     $media_type = $entry->getMediaType();
     if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         // image - use data for entry
         $file_sync = $this->redirectIfRemote($entry, entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, null);
         $key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         kFile::dumpFile(kFileSyncUtils::getLocalFilePathForKey($key, true));
     } elseif ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
         $format = $this->getRequestParameter("format");
         if ($type == "download" && $format) {
             // this is a video for a specifc extension - use the proper flavorAsset
             $flavor_asset = flavorAssetPeer::retrieveByEntryIdAndExtension($entry_id, $format);
             if ($flavor_asset && $flavor_asset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
                 $file_sync = $this->redirectIfRemote($flavor_asset, flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, null, true);
             } else {
                 header('KalturaRaw: no flavor asset for extension');
                 die;
             }
             $archive_file = $file_sync->getFullPath();
         } else {
             // flavorAsset of the original
             $flavor_asset = flavorAssetPeer::retrieveOriginalByEntryId($entry_id);
             if ($flavor_asset && $flavor_asset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
                 $file_sync = $this->redirectIfRemote($flavor_asset, flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, null, false);
                 // NOT strict - if there is no archive, get the data version
                 if ($file_sync) {
                     $archive_file = $file_sync->getFullPath();
                 }
             }
             if (!$flavor_asset || !$file_sync || $flavor_asset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
                 // either no archive asset or no fileSync for archive asset
                 // use fallback flavorAsset
                 $flavor_asset = flavorAssetPeer::retrieveBestPlayByEntryId($entry_id);
                 if (!$flavor_asset) {
                     header('KalturaRaw: no original flavor asset for entry, no best play asset for entry');
                     die;
                 }
                 $file_sync = $this->redirectIfRemote($flavor_asset, flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, null, false);
                 // NOT strict - if there is no archive, get the data version
                 $archive_file = $file_sync->getFullPath();
             }
         }
     } elseif ($media_type == entry::ENTRY_MEDIA_TYPE_SHOW) {
         // in this case "raw" is a bad name
         // TODO - add the ability to fetch the actual XML by flagging "xml" or something
         $version = $this->getRequestParameter("version");
         // hotfix - links sent after flattening is done look like:
         // http://cdn.kaltura.com/p/387/sp/38700/raw/entry_id/0_ix99151g/version/100001
         // while waiting for flavor-adaptation in flattening, we want to find at least one file to return.
         $try_formats = array('mp4', 'mov', 'avi', 'flv');
         if ($format) {
             $key = array_search($format, $try_formats);
             if ($key !== FALSE) {
                 unset($try_formats[$key]);
             }
             $file_sync = $this->redirectIfRemote($entry, entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $format, false);
         }
         if (!isset($file_sync) || !$file_sync || !file_exists($file_sync->getFullPath())) {
             foreach ($try_formats as $ext) {
                 KalturaLog::log("raw for mix - trying to find filesync for extension: [{$ext}] on entry [{$entry->getId()}]");
                 $file_sync = $this->redirectIfRemote($entry, entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $ext, false);
                 if ($file_sync && file_exists($file_sync->getFullPath())) {
                     KalturaLog::log("raw for mix - found flattened video of extension: [{$ext}] continuing with this file {$file_sync->getFullPath()}");
                     break;
                 }
             }
             if (!$file_sync || !file_exists($file_sync->getFullPath())) {
                 $file_sync = $this->redirectIfRemote($entry, entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $ext, true);
             }
         }
         // use fileSync for entry - roughcuts don't have flavors
         //$file_sync =  $this->redirectIfRemote ( $entry ,  entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD , $version , true );  // strict - nothing to do if no flattened version
         // if got to here - fileSync was found for one of the extensions - continue with that file
         $archive_file = $file_sync->getFullPath();
     } else {
         // no archive for this file
         header("HTTP/1.0 404 Not Found");
         die;
     }
     //		echo "[$archive_file][" . file_exists ( $archive_file ) . "]";
     $mime_type = kFile::mimeType($archive_file);
     //		echo "[[$mime_type]]";
     if (!empty($relocate)) {
         // after relocation - dump the file
         kFile::dumpFile($archive_file, $mime_type);
         die;
     } else {
         // use new Location to add the best extension we can find for the file
         $file_ext = pathinfo($archive_file, PATHINFO_EXTENSION);
         if ($file_ext != "flv") {
             // if the file does not end with "flv" - it is the real extension
             $ext = $file_ext;
         } else {
             // for now - if "flv" return "flv" - // TODO - find the real extension from the file itself
             $ext = "flv";
         }
         // rebuild the URL and redirect to it with extraa parameters
         $url = $_SERVER["REQUEST_URI"];
         $format = $this->getRequestParameter("format");
         if (!$format) {
             $url = str_replace("format", "", $url);
         }
         if ($ret_file_name && pathinfo($ret_file_name, PATHINFO_EXTENSION) != "") {
             // if the name holds an extension - prefer it over the real file's extension
             $ext = pathinfo($ret_file_name, PATHINFO_EXTENSION);
         }
         if (!$ret_file_name) {
             // don't leave the name empty - if it is empty - use the entry id
             $ret_file_name = $entry_id;
         }
         if (strpos($url, "?") > 0) {
             $url = str_replace("?", "/{$ret_file_name}.{$ext}?", $url);
             $url .= "&relocate=f.{$ext}";
             // add the ufname as a query parameter
         } else {
             $url .= "/{$ret_file_name}.{$ext}?relocate=f.{$ext}";
             // add the ufname as a query parameter
         }
         // redirect and create the url so it will have the ufname
         header("Location: {$url}");
     }
     die;
 }
Esempio n. 10
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);
 }
Esempio n. 11
0
 /**
  * Serves the file content
  * 
  * @action serveByFlavorParamsId
  * @serverOnly
  * @param string $entryId Document entry id
  * @param string $flavorParamsId Flavor params id
  * @param bool $forceProxy force to get the content without redirect
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY
  * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND
  */
 public function serveByFlavorParamsIdAction($entryId, $flavorParamsId = null, $forceProxy = false)
 {
     KalturaResponseCacher::disableCache();
     entryPeer::setDefaultCriteriaFilter();
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != entryType::DOCUMENT) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ksObj = $this->getKs();
     $ks = $ksObj ? $ksObj->getOriginalString() : null;
     $securyEntryHelper = new KSecureEntryHelper($dbEntry, $ks, null);
     $securyEntryHelper->validateForDownload();
     $flavorAsset = null;
     assetPeer::resetInstanceCriteriaFilter();
     if ($flavorParamsId) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId);
         if (!$flavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorParamsId);
         }
     } else {
         $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
         if (!$flavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId);
         }
     }
     $fileName = $dbEntry->getName() . '.' . $flavorAsset->getFileExt();
     return $this->serveFlavorAsset($flavorAsset, $fileName, $forceProxy);
 }
Esempio n. 12
0
 /**
  * Get download URL for the Flavor Asset
  * 
  * @action getDownloadUrl
  * @param string $id
  * @param bool $useCdn
  * @return string
  * @deprecated use getUrl instead
  */
 public function getDownloadUrlAction($id, $useCdn = false)
 {
     $flavorAssetDb = assetPeer::retrieveById($id);
     if (!$flavorAssetDb || !$flavorAssetDb instanceof flavorAsset) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $id);
     }
     $this->validateEntryEntitlement($flavorAssetDb->getEntryId(), $id);
     if ($flavorAssetDb->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY);
     }
     // Validate for download
     $entryDb = entryPeer::retrieveByPK($flavorAssetDb->getEntryId());
     if (is_null($entryDb)) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $flavorAssetDb->getEntryId());
     }
     $preview = null;
     $ksObj = $this->getKs();
     $ks = $ksObj ? $ksObj->getOriginalString() : null;
     $securyEntryHelper = new KSecureEntryHelper($entryDb, $ks, null, ContextType::DOWNLOAD);
     if ($securyEntryHelper->shouldPreview()) {
         $preview = $flavorAssetDb->estimateFileSize($entryDb, $securyEntryHelper->getPreviewLength());
     } else {
         $securyEntryHelper->validateForDownload();
     }
     return $flavorAssetDb->getDownloadUrl($useCdn, false, $preview);
 }
Esempio n. 13
0
 private function getAllowedFlavorAssets(KSecureEntryHelper $secureEntryHelper, $entryId, $format = null, $isOriginal = false, $isBestPlay = false)
 {
     $flavorAsset = null;
     if ($isBestPlay) {
         $flavorAssets = assetPeer::retrieveReadyWebByEntryId($entryId);
     } else {
         $c = new Criteria();
         $c->add(assetPeer::ENTRY_ID, $entryId);
         if ($format) {
             $c->add(assetPeer::FILE_EXT, $format);
         }
         if ($isOriginal) {
             $c->add(assetPeer::IS_ORIGINAL, true);
         }
         $flavorAssets = assetPeer::doSelect($c);
     }
     foreach ($flavorAssets as $currentFlavorAsset) {
         if ($secureEntryHelper->isAssetAllowed($currentFlavorAsset)) {
             $flavorAsset = $currentFlavorAsset;
             break;
         }
     }
     return $flavorAsset;
 }
Esempio n. 14
0
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     $entryId = $this->getRequestParameter("entry_id");
     $flavorId = $this->getRequestParameter("flavor");
     $fileName = $this->getRequestParameter("file_name");
     $fileName = basename($fileName);
     $ksStr = $this->getRequestParameter("ks");
     $referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     $entry = null;
     if ($ksStr) {
         try {
             kCurrentContext::initKsPartnerUser($ksStr);
         } catch (Exception $ex) {
             KExternalErrors::dieError(KExternalErrors::INVALID_KS);
         }
     } else {
         $entry = kCurrentContext::initPartnerByEntryId($entryId);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     kEntitlementUtils::initEntitlementEnforcement();
     if (!$entry) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     } else {
         if (!kEntitlementUtils::isEntryEntitled($entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     KalturaMonitorClient::initApiMonitor(false, 'extwidget.download', $entry->getPartnerId());
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     $shouldPreview = false;
     $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, ContextType::DOWNLOAD);
     if ($securyEntryHelper->shouldPreview()) {
         $shouldPreview = true;
     } else {
         $securyEntryHelper->validateForDownload();
     }
     $flavorAsset = null;
     if ($flavorId) {
         // get flavor asset
         $flavorAsset = assetPeer::retrieveById($flavorId);
         if (is_null($flavorAsset) || !$flavorAsset->isLocalReadyStatus()) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
         // the request flavor should belong to the requested entry
         if ($flavorAsset->getEntryId() != $entryId) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
         if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
     } else {
         $flavorAssets = assetPeer::retrieveReadyWebByEntryId($entry->getId());
         foreach ($flavorAssets as $curFlavorAsset) {
             if ($securyEntryHelper->isAssetAllowed($curFlavorAsset)) {
                 $flavorAsset = $curFlavorAsset;
                 break;
             }
         }
     }
     // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source
     if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) {
         $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
         if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) {
             $flavorAsset = null;
         }
     }
     if ($flavorAsset) {
         $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset);
     } else {
         $syncKey = $this->getBestSyncKeyForEntry($entry);
     }
     if (is_null($syncKey)) {
         KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
     }
     $this->handleFileSyncRedirection($syncKey);
     $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     list($fileBaseName, $fileExt) = kAssetUtils::getFileName($entry, $flavorAsset);
     if (!$fileName) {
         $fileName = $fileBaseName;
     }
     if ($fileExt && !is_dir($filePath)) {
         $fileName = $fileName . '.' . $fileExt;
     }
     $preview = 0;
     if ($shouldPreview && $flavorAsset) {
         $preview = $flavorAsset->estimateFileSize($entry, $securyEntryHelper->getPreviewLength());
     } else {
         if (kCurrentContext::$ks_object) {
             $preview = kCurrentContext::$ks_object->getPrivilegeValue(kSessionBase::PRIVILEGE_PREVIEW, 0);
         }
     }
     //enable downloading file_name which inside the flavor asset directory
     if (is_dir($filePath)) {
         $filePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
     }
     $this->dumpFile($filePath, $fileName, $preview);
     KExternalErrors::dieGracefully();
     // no view
 }
Esempio n. 15
0
 public function execute()
 {
     KExternalErrors::setResponseErrorCode(KExternalErrors::HTTP_STATUS_NOT_FOUND);
     $this->deliveryAttributes = new DeliveryProfileDynamicAttributes();
     // Parse input parameters
     $this->deliveryAttributes->setSeekFromTime($this->getRequestParameter("seekFrom", -1));
     if ($this->deliveryAttributes->getSeekFromTime() <= 0) {
         $this->deliveryAttributes->setSeekFromTime(-1);
     }
     $this->deliveryAttributes->setClipTo($this->getRequestParameter("clipTo", 0));
     $this->deliveryAttributes->setPlaybackRate($this->getRequestParameter("playbackRate", 0));
     $deliveryCode = $this->getRequestParameter("deliveryCode", null);
     $playbackContext = $this->getRequestParameter("playbackContext", null);
     $this->deliveryAttributes->setMediaProtocol($this->getRequestParameter("protocol", null));
     if (!$this->deliveryAttributes->getMediaProtocol() || $this->deliveryAttributes->getMediaProtocol() === "null") {
         $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP);
     }
     $this->deliveryAttributes->setFormat($this->getRequestParameter("format"));
     if (!$this->deliveryAttributes->getFormat()) {
         $this->deliveryAttributes->setFormat(PlaybackProtocol::HTTP);
     }
     if ($this->deliveryAttributes->getFormat() == self::HDNETWORKSMIL) {
         $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP);
     }
     // Akamai HD doesn't support any other protocol
     if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::AKAMAI_HDS) {
         if (strpos($this->deliveryAttributes->getMediaProtocol(), "http") !== 0) {
             $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP);
         }
     }
     $tags = $this->getRequestParameter("tags", null);
     if (!$tags) {
         $this->deliveryAttributes->setTags(self::getDefaultTagsByFormat($this->deliveryAttributes->getFormat()));
     } else {
         $tagsArray = explode(',', $tags);
         $tags = array();
         foreach ($tagsArray as $tag) {
             $tags[] = array(trim($tag));
         }
         $this->deliveryAttributes->setTags($tags);
     }
     $this->deliveryAttributes->setpreferredBitrate($this->getRequestParameter("preferredBitrate", null));
     $this->maxBitrate = $this->getRequestParameter("maxBitrate", null);
     if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) {
         KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE);
     }
     $this->deliveryAttributes->setStorageId($this->getRequestParameter("storageId", null));
     $this->cdnHost = $this->getRequestParameter("cdnHost", null);
     $this->deliveryAttributes->setResponseFormat($this->getRequestParameter("responseFormat", null));
     // Initialize
     $this->initEntry();
     $this->deliveryAttributes->setEntryId($this->entryId);
     $this->deliveryAttributes->setUsePlayServer((bool) $this->getRequestParameter("usePlayServer") && PermissionPeer::isValidForPartner(PermissionName::FEATURE_PLAY_SERVER, $this->entry->getPartnerId()));
     if ($this->deliveryAttributes->getUsePlayServer()) {
         $this->deliveryAttributes->setPlayerConfig($this->getRequestParameter("playerConfig"));
         //In case request needs to be redirected to play-server we need to add the ui conf id to the manifest url as well
         $this->deliveryAttributes->setUiConfId($this->getRequestParameter("uiConfId"));
     }
     $this->secureEntryHelper->updateDeliveryAttributes($this->deliveryAttributes);
     $this->enforceEncryption();
     $renderer = null;
     switch ($this->entry->getType()) {
         case entryType::MEDIA_CLIP:
             // VOD
             $renderer = $this->serveVodEntry();
             break;
         case entryType::LIVE_STREAM:
         case entryType::LIVE_CHANNEL:
             // Live stream
             $renderer = $this->serveLiveEntry();
             break;
         default:
             KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE);
     }
     if (!$renderer) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'This format is unsupported');
     }
     $renderer->contributors = array();
     $config = new kManifestContributorConfig();
     $config->format = $this->deliveryAttributes->getFormat();
     $config->deliveryCode = $deliveryCode;
     $config->storageId = $this->deliveryAttributes->getStorageId();
     $config->entryId = $this->entryId;
     $contributors = KalturaPluginManager::getPluginInstances('IKalturaPlayManifestContributor');
     foreach ($contributors as $contributor) {
         /* @var $contributor IKalturaPlayManifestContributor */
         $renderer->contributors = array_merge($renderer->contributors, $contributor->getManifestEditors($config));
     }
     $renderer->entryId = $this->entryId;
     $renderer->duration = $this->duration;
     if ($this->deliveryProfile) {
         $renderer->tokenizer = $this->deliveryProfile->getTokenizer();
     }
     $renderer->defaultDeliveryCode = $this->entry->getPartner()->getDefaultDeliveryCode();
     $renderer->lastModified = time();
     // Handle caching
     $canCacheAccessControl = false;
     if (kConf::hasParam("force_caching_headers") && in_array($this->entry->getPartnerId(), kConf::get("force_caching_headers"))) {
         $renderer->cachingHeadersAge = 60;
         $renderer->forceCachingHeaders = true;
     }
     if (!$this->secureEntryHelper) {
         $canCacheAccessControl = true;
         // TODO: reconsider this if/when expired ktokens will be used
     } else {
         if (!$this->secureEntryHelper->shouldDisableCache() && !$this->secureEntryHelper->isKsAdmin() && ($this->secureEntryHelper->isKsWidget() || !$this->secureEntryHelper->hasRules())) {
             $canCacheAccessControl = true;
         }
     }
     if (!$renderer->tokenizer && $canCacheAccessControl) {
         // Note: kApiCache::hasExtraFields is checked in kManifestRenderers
         $renderer->cachingHeadersAge = 60;
     }
     if (!$this->secureEntryHelper || !$this->secureEntryHelper->shouldDisableCache()) {
         $cache = kPlayManifestCacher::getInstance();
         $cache->storeRendererToCache($renderer);
     }
     // Output the response
     KExternalErrors::terminateDispatch();
     $renderer->output($deliveryCode, $playbackContext);
 }
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     $entryId = $this->getRequestParameter("entry_id");
     $flavorId = $this->getRequestParameter("flavor");
     $fileName = $this->getRequestParameter("file_name");
     $fileName = basename($fileName);
     $ksStr = $this->getRequestParameter("ks");
     $referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     $entry = null;
     if ($ksStr) {
         try {
             kCurrentContext::initKsPartnerUser($ksStr);
         } catch (Exception $ex) {
             KExternalErrors::dieError(KExternalErrors::INVALID_KS);
         }
     } else {
         $entry = kCurrentContext::initPartnerByEntryId($entryId);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     kEntitlementUtils::initEntitlementEnforcement();
     if (!$entry) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     } else {
         if (!kEntitlementUtils::isEntryEntitled($entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, accessControlContextType::DOWNLOAD);
     $securyEntryHelper->validateForDownload($entry, $ksStr);
     $flavorAsset = null;
     if ($flavorId) {
         // get flavor asset
         $flavorAsset = assetPeer::retrieveById($flavorId);
         if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
         // the request flavor should belong to the requested entry
         if ($flavorAsset->getEntryId() != $entryId) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
     } else {
         $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId());
     }
     // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source
     if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) {
         $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     }
     if ($flavorAsset) {
         $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset);
     } else {
         $syncKey = $this->getBestSyncKeyForEntry($entry);
     }
     if (is_null($syncKey)) {
         KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
     }
     $this->handleFileSyncRedirection($syncKey);
     $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     $wamsAssetId = kFileSyncUtils::getWamsAssetIdForKey($syncKey);
     $wamsURL = kFileSyncUtils::getWamsURLForKey($syncKey);
     list($fileBaseName, $fileExt) = $this->getFileName($entry, $flavorAsset);
     if (!$fileName) {
         $fileName = $fileBaseName;
     }
     if ($fileExt && !is_dir($filePath)) {
         $fileName = $fileName . '.' . $fileExt;
     }
     //enable downloading file_name which inside the flavor asset directory
     if (is_dir($filePath)) {
         $filePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
     }
     $this->dumpFile($filePath, $fileName, $wamsAssetId, $wamsURL);
     die;
     // no view
 }
Esempio n. 17
0
 /**
  * Get download URL for the asset
  * 
  * @action getUrl
  * @param string $id
  * @param int $storageId
  * @param KalturaThumbParams $thumbParams
  * @return string
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY
  */
 public function getUrlAction($id, $storageId = null, KalturaThumbParams $thumbParams = null)
 {
     $assetDb = assetPeer::retrieveById($id);
     if (!$assetDb || !$assetDb instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $id);
     }
     $entry = entryPeer::retrieveByPK($assetDb->getEntryId());
     if (!$entry) {
         //we will throw thumb asset not found, as the user is not entitled, and should not know that the entry exists or entry does not exist.
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $id);
     }
     if ($assetDb->getStatus() != asset::ASSET_STATUS_READY) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_IS_NOT_READY);
     }
     $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, ContextType::THUMBNAIL);
     $securyEntryHelper->validateAccessControl();
     return $assetDb->getThumbnailUrl($securyEntryHelper, $storageId, $thumbParams);
 }
 public function execute()
 {
     $this->entryId = $this->getRequestParameter("entryId", null);
     $this->flavorId = $this->getRequestParameter("flavorId", null);
     $this->storageId = $this->getRequestParameter("storageId", null);
     $this->maxBitrate = $this->getRequestParameter("maxBitrate", null);
     $flavorIdsStr = $this->getRequestParameter("flavorIds", null);
     if ($flavorIdsStr) {
         $this->flavorIds = explode(",", $flavorIdsStr);
     }
     $this->entry = entryPeer::retrieveByPKNoFilter($this->entryId);
     if (!$this->entry) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     if (!$this->flavorId) {
         $flavorParamId = $this->getRequestParameter("flavorParamId", null);
         if ($flavorParamId) {
             $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entry->getId(), $flavorParamId);
             if (!$flavorAsset) {
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             $this->flavorId = $flavorAsset->getId();
         }
     }
     $this->validateStorageId();
     $this->protocol = $this->getRequestParameter("protocol", null);
     if (!$this->protocol) {
         $this->protocol = StorageProfile::PLAY_FORMAT_HTTP;
     }
     $this->format = $this->getRequestParameter("format");
     if (!$this->format) {
         $this->format = StorageProfile::PLAY_FORMAT_HTTP;
     }
     $this->cdnHost = $this->getRequestParameter("cdnHost", null);
     $partner = $this->entry->getPartner();
     if (!$this->cdnHost || $partner->getForceCdnHost()) {
         $this->cdnHost = myPartnerUtils::getCdnHost($this->entry->getPartnerId(), $this->protocol);
     }
     if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) {
         KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE);
     }
     $ksStr = $this->getRequestParameter("ks");
     $base64Referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($base64Referrer);
     if (!is_string($referrer)) {
         $referrer = "";
     }
     // base64_decode can return binary data
     $securyEntryHelper = new KSecureEntryHelper($this->entry, $ksStr, $referrer);
     if ($securyEntryHelper->shouldPreview()) {
         $this->clipTo = $securyEntryHelper->getPreviewLength() * 1000;
     } else {
         $securyEntryHelper->validateForPlay($this->entry, $ksStr);
     }
     // grab seekFrom parameter and normalize url
     $this->seekFrom = $this->getRequestParameter("seekFrom", -1);
     if ($this->seekFrom <= 0) {
         $this->seekFrom = -1;
     }
     if ($this->entry->getStatus() == entryStatus::DELETED) {
         // because the fiter was turned off - a manual check for deleted entries must be done.
         die;
     }
     $xml = null;
     switch ($this->format) {
         case StorageProfile::PLAY_FORMAT_HTTP:
             $xml = $this->serveHttp();
             break;
         case StorageProfile::PLAY_FORMAT_RTMP:
             $xml = $this->serveRtmp();
             break;
         case StorageProfile::PLAY_FORMAT_SILVER_LIGHT:
             $xml = $this->serveSilverLight();
             break;
         case StorageProfile::PLAY_FORMAT_APPLE_HTTP:
             $xml = $this->serveAppleHttp();
             break;
         case "url":
             return $this->serveUrl();
             break;
         case "hdnetworksmil":
             $xml = $this->serveHDNetwork();
             break;
         case "hdnetwork":
             $duration = $this->entry->getDurationInt();
             $mediaUrl = "<media url=\"" . requestUtils::getHost() . str_replace("f4m", "smil", str_replace("hdnetwork", "hdnetworksmil", $_SERVER["REQUEST_URI"])) . "\"/>";
             $xml = $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, array(), 'video/x-flv', $duration, null, $mediaUrl);
             break;
     }
     if ($this->format == StorageProfile::PLAY_FORMAT_APPLE_HTTP) {
         header("Content-Type: text/plain; charset=UTF-8");
     } else {
         header("Content-Type: text/xml; charset=UTF-8");
         header("Content-Disposition: inline; filename=manifest.xml");
     }
     echo $xml;
     die;
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Esempio n. 21
0
 /**
  * Will forward to the regular swf player according to the widget_id
  */
 public function execute()
 {
     KExternalErrors::setResponseErrorCode(KExternalErrors::HTTP_STATUS_NOT_FOUND);
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2;
     requestUtils::handleConditionalGet();
     ignore_user_abort();
     $entry_id = $this->getRequestParameter("entry_id");
     $widget_id = $this->getRequestParameter("widget_id", 0);
     $upload_token_id = $this->getRequestParameter("upload_token_id");
     $version = $this->getIntRequestParameter("version", null, 0, 10000000);
     $type = $this->getIntRequestParameter("type", 1, 1, 5);
     //Hack: if KMS sends thumbnail request containing "!" char, the type should be treated as 5.
     $width = $this->getRequestParameter("width", -1);
     $height = $this->getRequestParameter("height", -1);
     if (strpos($width, "!") || strpos($height, "!")) {
         $type = 5;
     }
     $width = $this->getFloatRequestParameter("width", -1, -1, 10000);
     $height = $this->getFloatRequestParameter("height", -1, -1, 10000);
     $nearest_aspect_ratio = $this->getIntRequestParameter("nearest_aspect_ratio", 0, 0, 1);
     $imageFilePath = null;
     $crop_provider = $this->getRequestParameter("crop_provider", null);
     $quality = $this->getIntRequestParameter("quality", 0, 0, 100);
     $src_x = $this->getFloatRequestParameter("src_x", 0, 0, 10000);
     $src_y = $this->getFloatRequestParameter("src_y", 0, 0, 10000);
     $src_w = $this->getFloatRequestParameter("src_w", 0, 0, 10000);
     $src_h = $this->getFloatRequestParameter("src_h", 0, 0, 10000);
     $vid_sec = $this->getFloatRequestParameter("vid_sec", -1, -1);
     $vid_slice = $this->getRequestParameter("vid_slice", -1);
     $vid_slices = $this->getRequestParameter("vid_slices", -1);
     $density = $this->getFloatRequestParameter("density", 0, 0);
     $stripProfiles = $this->getRequestParameter("strip", null);
     $flavor_id = $this->getRequestParameter("flavor_id", null);
     $file_name = $this->getRequestParameter("file_name", null);
     $file_name = basename($file_name);
     // actual width and height of image from which the src_* values were taken.
     // these will be used to multiply the src_* parameters to make them relate to the original image size.
     $rel_width = $this->getFloatRequestParameter("rel_width", -1, -1, 10000);
     $rel_height = $this->getFloatRequestParameter("rel_height", -1, -1, 10000);
     $def_width = $this->getFloatRequestParameter("def_width", -1, -1, 10000);
     $def_height = $this->getFloatRequestParameter("def_height", -1, -1, 10000);
     if ($width == -1 && $height == -1) {
         if ($def_width == -1) {
             $width = 120;
         } else {
             $width = $def_width;
         }
         if ($def_height == -1) {
             $height = 90;
         } else {
             $height = $def_height;
         }
     } else {
         if ($width == -1) {
             $width = 0;
         } else {
             if ($height == -1) {
                 $height = 0;
             }
         }
     }
     $bgcolor = $this->getRequestParameter("bgcolor", "ffffff");
     $partner = null;
     $format = $this->getRequestParameter("format", null);
     // validating the inputs
     if (!is_numeric($quality) || $quality < 0 || $quality > 100) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'quality must be between 20 and 100');
     }
     if (!is_numeric($src_x) || $src_x < 0 || $src_x > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_x must be between 0 and 10000');
     }
     if (!is_numeric($src_y) || $src_y < 0 || $src_y > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_y must be between 0 and 10000');
     }
     if (!is_numeric($src_w) || $src_w < 0 || $src_w > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_w must be between 0 and 10000');
     }
     if (!is_numeric($src_h) || $src_h < 0 || $src_h > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_h must be between 0 and 10000');
     }
     if (!is_numeric($width) || $width < 0 || $width > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'width must be between 0 and 10000');
     }
     if (!is_numeric($height) || $height < 0 || $height > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'height must be between 0 and 10000');
     }
     if (!is_numeric($density) || $density < 0) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'density must be positive');
     }
     if (!is_numeric($vid_sec) || $vid_sec < -1) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'vid_sec must be positive');
     }
     if (!preg_match('/^[0-9a-fA-F]{1,6}$/', $bgcolor)) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'bgcolor must be six hexadecimal characters');
     }
     if ($vid_slices != -1 && $vid_slices <= 0 || !is_numeric($vid_slices)) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'vid_slices must be positive');
     }
     if ($upload_token_id) {
         $upload_token = UploadTokenPeer::retrieveByPK($upload_token_id);
         if ($upload_token) {
             $partnerId = $upload_token->getPartnerId();
             $partner = PartnerPeer::retrieveByPK($partnerId);
             if ($partner) {
                 KalturaMonitorClient::initApiMonitor(false, 'extwidget.thumbnail', $partner->getId());
                 if ($quality == 0) {
                     $quality = $partner->getDefThumbQuality();
                 }
                 if ($density == 0) {
                     $density = $partner->getDefThumbDensity();
                 }
                 if (is_null($stripProfiles)) {
                     $stripProfiles = $partner->getStripThumbProfile();
                 }
             }
             $thumb_full_path = myContentStorage::getFSCacheRootPath() . myContentStorage::getGeneralEntityPath("uploadtokenthumb", $upload_token->getIntId(), $upload_token->getId(), $upload_token->getId() . ".jpg");
             kFile::fullMkdir($thumb_full_path);
             if (file_exists($upload_token->getUploadTempPath())) {
                 $src_full_path = $upload_token->getUploadTempPath();
                 $valid_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_WBMP);
                 $image_type = exif_imagetype($src_full_path);
                 if (!in_array($image_type, $valid_image_types)) {
                     // capture full frame
                     myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 3);
                     if (!file_exists($thumb_full_path)) {
                         myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 0);
                     }
                     $src_full_path = $thumb_full_path;
                 }
                 // and resize it
                 myFileConverter::convertImage($src_full_path, $thumb_full_path, $width, $height, $type, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h, $density, $stripProfiles, null, $format);
                 kFileUtils::dumpFile($thumb_full_path);
             } else {
                 KalturaLog::info("token_id [{$upload_token_id}] not found in DC [" . kDataCenterMgr::getCurrentDcId() . "]. dump url to romote DC");
                 $remoteUrl = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()) . $_SERVER['REQUEST_URI'];
                 kFileUtils::dumpUrl($remoteUrl);
             }
         }
     }
     if ($entry_id) {
         $entry = entryPeer::retrieveByPKNoFilter($entry_id);
         if (!$entry) {
             // problem could be due to replication lag
             kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()));
         }
     } else {
         // get the widget
         $widget = widgetPeer::retrieveByPK($widget_id);
         if (!$widget) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_AND_WIDGET_NOT_FOUND);
         }
         // get the kshow
         $kshow_id = $widget->getKshowId();
         $kshow = kshowPeer::retrieveByPK($kshow_id);
         if ($kshow) {
             $entry_id = $kshow->getShowEntryId();
         } else {
             $entry_id = $widget->getEntryId();
         }
         $entry = entryPeer::retrieveByPKNoFilter($entry_id);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     KalturaMonitorClient::initApiMonitor(false, 'extwidget.thumbnail', $entry->getPartnerId());
     if ($nearest_aspect_ratio) {
         // Get the entry's default thumbnail path (if any)
         $defaultThumbnailPath = myEntryUtils::getLocalImageFilePathByEntry($entry, $version);
         // Get the file path of the thumbnail with the nearest
         $selectedThumbnailDescriptor = kThumbnailUtils::getNearestAspectRatioThumbnailDescriptorByEntryId($entry_id, $width, $height, $defaultThumbnailPath);
         if ($selectedThumbnailDescriptor) {
             $imageFilePath = $selectedThumbnailDescriptor->getImageFilePath();
             $thumbWidth = $selectedThumbnailDescriptor->getWidth();
             $thumbHeight = $selectedThumbnailDescriptor->getHeight();
             // The required width and height will serve as the final crop values
             $src_w = $width;
             $src_h = $height;
             // Base on the thumbnail's dimensions
             kThumbnailUtils::scaleDimensions($thumbWidth, $thumbHeight, $width, $height, kThumbnailUtils::SCALE_UNIFORM_SMALLER_DIM, $width, $height);
             // Set crop type
             $type = KImageMagickCropper::CROP_AFTER_RESIZE;
         }
     }
     $partner = $entry->getPartner();
     // not allow capturing frames if the partner has FEATURE_DISALLOW_FRAME_CAPTURE permission
     if ($vid_sec != -1 || $vid_slice != -1 || $vid_slices != -1) {
         if ($partner->getEnabledService(PermissionName::FEATURE_BLOCK_THUMBNAIL_CAPTURE)) {
             KExternalErrors::dieError(KExternalErrors::NOT_ALLOWED_PARAMETER);
         }
     }
     if ($partner) {
         if ($quality == 0) {
             $quality = $partner->getDefThumbQuality();
         }
         if ($density == 0) {
             $density = $partner->getDefThumbDensity();
         }
     }
     $thumbParams = new kThumbnailParameters();
     $thumbParams->setSupportAnimatedThumbnail($partner->getSupportAnimatedThumbnails());
     if (is_null($stripProfiles)) {
         $stripProfiles = $partner->getStripThumbProfile();
     }
     //checks whether the thumbnail display should be restricted by KS
     $base64Referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($base64Referrer);
     if (!is_string($referrer)) {
         $referrer = "";
     }
     // base64_decode can return binary data
     if (!$referrer) {
         $referrer = kApiCache::getHttpReferrer();
     }
     $ksStr = $this->getRequestParameter("ks");
     $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, ContextType::THUMBNAIL);
     $securyEntryHelper->validateForPlay();
     // multiply the passed $src_* values so that they will relate to the original image size, according to $src_display_*
     if ($rel_width != -1 && $rel_width) {
         $widthRatio = $entry->getWidth() / $rel_width;
         $src_x = $src_x * $widthRatio;
         $src_w = $src_w * $widthRatio;
     }
     if ($rel_height != -1 && $rel_height) {
         $heightRatio = $entry->getHeight() / $rel_height;
         $src_y = $src_y * $heightRatio;
         $src_h = $src_h * $heightRatio;
     }
     $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB;
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
     }
     $dataKey = $entry->getSyncKey($subType);
     list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($dataKey, true, false);
     $tempThumbPath = null;
     $entry_status = $entry->getStatus();
     // both 640x480 and 0x0 requests are probably coming from the kdp
     // 640x480 - old kdp version requesting thumbnail
     // 0x0 - new kdp version requesting the thumbnail of an unready entry
     // we need to distinguish between calls from the kdp and calls from a browser: <img src=...>
     // that can't handle swf input
     if (($width == 640 && $height == 480 || $width == 0 && $height == 0) && ($entry_status == entryStatus::PRECONVERT || $entry_status == entryStatus::IMPORT || $entry_status == entryStatus::ERROR_CONVERTING || $entry_status == entryStatus::DELETED)) {
         $contentPath = myContentStorage::getFSContentRootPath();
         $msgPath = $contentPath . "content/templates/entry/bigthumbnail/";
         if ($entry_status == entryStatus::DELETED) {
             $msgPath .= $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK ? "entry_blocked.swf" : "entry_deleted.swf";
         } else {
             $msgPath .= $entry_status == entryStatus::ERROR_CONVERTING ? "entry_error.swf" : "entry_converting.swf";
         }
         kFileUtils::dumpFile($msgPath, null, 0);
     }
     if (!$file_sync) {
         $tempThumbPath = $entry->getLocalThumbFilePath($version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name);
         if (!$tempThumbPath) {
             KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
         }
     }
     if (!$local && !$tempThumbPath && $file_sync) {
         if (!in_array($file_sync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = $file_sync->getExternalUrl($entry->getId());
             header("Location: {$remoteUrl}");
             KExternalErrors::dieGracefully();
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($file_sync, $_SERVER['REQUEST_URI']);
         kFileUtils::dumpUrl($remoteUrl);
     }
     // if we didnt return a template for the player die and dont return the original deleted thumb
     if ($entry_status == entryStatus::DELETED) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED);
     }
     if (!$tempThumbPath) {
         try {
             $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $imageFilePath, $density, $stripProfiles, $thumbParams, $format);
         } catch (Exception $ex) {
             if ($ex->getCode() != kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) {
                 KalturaLog::err("Resize image failed");
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             // get original flavor asset
             $origFlavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id);
             if (!$origFlavorAsset) {
                 KalturaLog::err("No original flavor for entry [{$entry_id}]");
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             $syncKey = $origFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $remoteFileSync = kFileSyncUtils::getOriginFileSyncForKey($syncKey, false);
             if (!$remoteFileSync) {
                 // file does not exist on any DC - die
                 KalturaLog::log("Error - no FileSync for entry [{$entry_id}]");
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             if ($remoteFileSync->getDc() == kDataCenterMgr::getCurrentDcId()) {
                 KalturaLog::err("Trying to redirect to myself - stop here.");
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             if (!in_array($remoteFileSync->getDc(), kDataCenterMgr::getDcIds())) {
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync);
             kFileUtils::dumpUrl($remoteUrl);
         }
     }
     $nocache = false;
     if ($securyEntryHelper->shouldDisableCache() || kApiCache::hasExtraFields() || !$securyEntryHelper->isKsWidget() && $securyEntryHelper->hasRules(ContextType::THUMBNAIL)) {
         $nocache = true;
     }
     $cache = null;
     if (!is_null($entry->getPartner())) {
         $partnerCacheAge = $entry->getPartner()->getThumbnailCacheAge();
     }
     if ($nocache) {
         $cacheAge = 0;
     } else {
         if ($partnerCacheAge) {
             $cacheAge = $partnerCacheAge;
         } else {
             if (strpos($tempThumbPath, "_NOCACHE_") !== false) {
                 $cacheAge = 60;
             } else {
                 $cacheAge = 3600;
                 $cache = new myCache("thumb", 2592000);
                 // 30 days, the max memcache allows
             }
         }
     }
     $lastModified = $entry->getAssetCacheTime();
     $renderer = kFileUtils::getDumpFileRenderer($tempThumbPath, null, $cacheAge, 0, $lastModified);
     $renderer->partnerId = $entry->getPartnerId();
     if ($cache) {
         $invalidationKey = $entry->getCacheInvalidationKeys();
         $invalidationKey = kQueryCache::CACHE_PREFIX_INVALIDATION_KEY . $invalidationKey[0];
         $cacheTime = time() - kQueryCache::CLOCK_SYNC_TIME_MARGIN_SEC;
         $cachedResponse = array($renderer, $invalidationKey, $cacheTime);
         $cache->put($_SERVER["REQUEST_URI"], $cachedResponse);
     }
     $renderer->output();
     KExternalErrors::dieGracefully();
     // TODO - can delete from disk assuming we caneasily recreate it and it will anyway be cached in the CDN
     // however dumpfile dies at the end so we cant just write it here (maybe register a shutdown callback)
 }
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2;
     requestUtils::handleConditionalGet();
     ignore_user_abort();
     $entry_id = $this->getRequestParameter("entry_id");
     $widget_id = $this->getRequestParameter("widget_id", 0);
     $upload_token_id = $this->getRequestParameter("upload_token_id");
     $version = $this->getIntRequestParameter("version", null, 0, 10000000);
     $type = $this->getIntRequestParameter("type", 1, 1, 5);
     //Hack: if KMS sends thumbnail request containing "!" char, the type should be treated as 5.
     $width = $this->getRequestParameter("width", -1);
     $height = $this->getRequestParameter("height", -1);
     if (strpos($width, "!") || strpos($height, "!")) {
         $type = 5;
     }
     $width = $this->getFloatRequestParameter("width", -1, -1, 10000);
     $height = $this->getFloatRequestParameter("height", -1, -1, 10000);
     $crop_provider = $this->getRequestParameter("crop_provider", null);
     $quality = $this->getIntRequestParameter("quality", 0, 0, 100);
     $src_x = $this->getFloatRequestParameter("src_x", 0, 0, 10000);
     $src_y = $this->getFloatRequestParameter("src_y", 0, 0, 10000);
     $src_w = $this->getFloatRequestParameter("src_w", 0, 0, 10000);
     $src_h = $this->getFloatRequestParameter("src_h", 0, 0, 10000);
     $vid_sec = $this->getFloatRequestParameter("vid_sec", -1, -1);
     $vid_slice = $this->getRequestParameter("vid_slice", -1);
     $vid_slices = $this->getRequestParameter("vid_slices", -1);
     $density = $this->getFloatRequestParameter("density", 0, 0);
     $stripProfiles = $this->getRequestParameter("strip", null);
     $flavor_id = $this->getRequestParameter("flavor_id", null);
     $file_name = $this->getRequestParameter("file_name", null);
     $file_name = basename($file_name);
     // actual width and height of image from which the src_* values were taken.
     // these will be used to multiply the src_* parameters to make them relate to the original image size.
     $rel_width = $this->getFloatRequestParameter("rel_width", -1, -1, 10000);
     $rel_height = $this->getFloatRequestParameter("rel_height", -1, -1, 10000);
     if ($width == -1 && $height == -1) {
         $width = 120;
         $height = 90;
     } else {
         if ($width == -1) {
             // if only either width or height is missing reset them to zero, and convertImage will handle them
             $width = 0;
         } else {
             if ($height == -1) {
                 $height = 0;
             }
         }
     }
     $bgcolor = $this->getRequestParameter("bgcolor", "ffffff");
     $partner = null;
     // validating the inputs
     if (!is_numeric($quality) || $quality < 0 || $quality > 100) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'quality must be between 20 and 100');
     }
     if (!is_numeric($src_x) || $src_x < 0 || $src_x > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_x must be between 0 and 10000');
     }
     if (!is_numeric($src_y) || $src_y < 0 || $src_y > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_y must be between 0 and 10000');
     }
     if (!is_numeric($src_w) || $src_w < 0 || $src_w > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_w must be between 0 and 10000');
     }
     if (!is_numeric($src_h) || $src_h < 0 || $src_h > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'src_h must be between 0 and 10000');
     }
     if (!is_numeric($width) || $width < 0 || $width > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'width must be between 0 and 10000');
     }
     if (!is_numeric($height) || $height < 0 || $height > 10000) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'height must be between 0 and 10000');
     }
     if (!is_numeric($density) || $density < 0) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'density must be positive');
     }
     if (!is_numeric($vid_sec) || $vid_sec < -1) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'vid_sec must be positive');
     }
     if (!preg_match('/^[0-9a-fA-F]{1,6}$/', $bgcolor)) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'bgcolor must be six hexadecimal characters');
     }
     if ($upload_token_id) {
         $upload_token = UploadTokenPeer::retrieveByPK($upload_token_id);
         if ($upload_token) {
             $partnerId = $upload_token->getPartnerId();
             $partner = PartnerPeer::retrieveByPK($partnerId);
             if ($density == 0) {
                 $density = $partner->getDefThumbDensity();
             }
             if (is_null($stripProfiles)) {
                 $stripProfiles = $partner->getStripThumbProfile();
             }
             $thumb_full_path = myContentStorage::getFSCacheRootPath() . myContentStorage::getGeneralEntityPath("uploadtokenthumb", $upload_token->getIntId(), $upload_token->getId(), $upload_token->getId() . ".jpg");
             kFile::fullMkdir($thumb_full_path);
             if (file_exists($upload_token->getUploadTempPath())) {
                 $src_full_path = $upload_token->getUploadTempPath();
                 $valid_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_WBMP);
                 $image_type = exif_imagetype($src_full_path);
                 if (!in_array($image_type, $valid_image_types)) {
                     // capture full frame
                     myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 3);
                     if (!file_exists($thumb_full_path)) {
                         myFileConverter::captureFrame($src_full_path, $thumb_full_path, 1, "image2", -1, -1, 0);
                     }
                     $src_full_path = $thumb_full_path;
                 }
                 // and resize it
                 myFileConverter::convertImage($src_full_path, $thumb_full_path, $width, $height, $type, $bgcolor, true, $quality, $src_x, $src_y, $src_w, $src_h, $density, $stripProfiles);
                 kFile::dumpFile($thumb_full_path);
             } else {
                 KalturaLog::debug("token_id [{$upload_token_id}] not found in DC [" . kDataCenterMgr::getCurrentDcId() . "]. dump url to romote DC");
                 $remoteUrl = kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()) . $_SERVER['REQUEST_URI'];
                 kFile::dumpUrl($remoteUrl);
             }
         }
     }
     if ($entry_id) {
         $entry = entryPeer::retrieveByPKNoFilter($entry_id);
         if (!$entry) {
             // problem could be due to replication lag
             kFile::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId()));
         }
     } else {
         // get the widget
         $widget = widgetPeer::retrieveByPK($widget_id);
         if (!$widget) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_AND_WIDGET_NOT_FOUND);
         }
         // get the kshow
         $kshow_id = $widget->getKshowId();
         $kshow = kshowPeer::retrieveByPK($kshow_id);
         if ($kshow) {
             $entry_id = $kshow->getShowEntryId();
         } else {
             $entry_id = $widget->getEntryId();
         }
         $entry = entryPeer::retrieveByPKNoFilter($entry_id);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     $partner = $entry->getPartner();
     if ($density == 0) {
         $density = $partner->getDefThumbDensity();
     }
     $thumbParams = new kThumbnailParameters();
     $thumbParams->setSupportAnimatedThumbnail($partner->getSupportAnimatedThumbnails());
     if (is_null($stripProfiles)) {
         $stripProfiles = $partner->getStripThumbProfile();
     }
     //checks whether the thumbnail display should be restricted by KS
     $base64Referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($base64Referrer);
     if (!is_string($referrer)) {
         $referrer = "";
     }
     // base64_decode can return binary data
     if (!$referrer) {
         $referrer = kApiCache::getHttpReferrer();
     }
     $ksStr = $this->getRequestParameter("ks");
     $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer, accessControlContextType::THUMBNAIL);
     $securyEntryHelper->validateForPlay();
     // multiply the passed $src_* values so that they will relate to the original image size, according to $src_display_*
     if ($rel_width != -1) {
         $widthRatio = $entry->getWidth() / $rel_width;
         $src_x = $src_x * $widthRatio;
         $src_w = $src_w * $widthRatio;
     }
     if ($rel_height != -1) {
         $heightRatio = $entry->getHeight() / $rel_height;
         $src_y = $src_y * $heightRatio;
         $src_h = $src_h * $heightRatio;
     }
     $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB;
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
     }
     KalturaLog::debug("get thumbnail filesyncs");
     $dataKey = $entry->getSyncKey($subType);
     list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($dataKey, true, false);
     $tempThumbPath = null;
     $entry_status = $entry->getStatus();
     // both 640x480 and 0x0 requests are probably coming from the kdp
     // 640x480 - old kdp version requesting thumbnail
     // 0x0 - new kdp version requesting the thumbnail of an unready entry
     // we need to distinguish between calls from the kdp and calls from a browser: <img src=...>
     // that can't handle swf input
     if (($width == 640 && $height == 480 || $width == 0 && $height == 0) && ($entry_status == entryStatus::PRECONVERT || $entry_status == entryStatus::IMPORT || $entry_status == entryStatus::ERROR_CONVERTING || $entry_status == entryStatus::DELETED)) {
         $contentPath = myContentStorage::getFSContentRootPath();
         $msgPath = $contentPath . "content/templates/entry/bigthumbnail/";
         if ($entry_status == entryStatus::DELETED) {
             $msgPath .= $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK ? "entry_blocked.swf" : "entry_deleted.swf";
         } else {
             $msgPath .= $entry_status == entryStatus::ERROR_CONVERTING ? "entry_error.swf" : "entry_converting.swf";
         }
         kFile::dumpFile($msgPath, null, 0);
     }
     if (!$file_sync) {
         $tempThumbPath = $entry->getLocalThumbFilePath($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name);
         if (!$tempThumbPath) {
             KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
         }
     }
     if (!$local && !$tempThumbPath && $file_sync) {
         if (!in_array($file_sync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = $file_sync->getExternalUrl($entry->getId());
             header("Location: {$remoteUrl}");
             die;
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($file_sync, $_SERVER['REQUEST_URI']);
         kFile::dumpUrl($remoteUrl);
     }
     // if we didnt return a template for the player die and dont return the original deleted thumb
     if ($entry_status == entryStatus::DELETED) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED);
     }
     if (!$tempThumbPath) {
         try {
             $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, null, $density, $stripProfiles, $thumbParams);
         } catch (Exception $ex) {
             if ($ex->getCode() != kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) {
                 KalturaLog::log("Error - resize image failed");
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             // get original flavor asset
             $origFlavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id);
             if (!$origFlavorAsset) {
                 KalturaLog::log("Error - no original flavor for entry [{$entry_id}]");
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             $syncKey = $origFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $remoteFileSync = kFileSyncUtils::getOriginFileSyncForKey($syncKey, false);
             if (!$remoteFileSync) {
                 // file does not exist on any DC - die
                 KalturaLog::log("Error - no FileSync for entry [{$entry_id}]");
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             if ($remoteFileSync->getDc() == kDataCenterMgr::getCurrentDcId()) {
                 KalturaLog::log("ERROR - Trying to redirect to myself - stop here.");
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             if (!in_array($remoteFileSync->getDc(), kDataCenterMgr::getDcIds())) {
                 KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
             }
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync);
             kFile::dumpUrl($remoteUrl);
         }
     }
     $nocache = strpos($tempThumbPath, "_NOCACHE_") !== false;
     if ($securyEntryHelper->shouldDisableCache() || kApiCache::hasExtraFields() || !$securyEntryHelper->isKsWidget() && $securyEntryHelper->hasRules()) {
         $nocache = true;
     }
     // notify external proxy, so it'll cache this url
     if (!$nocache && requestUtils::getHost() == kConf::get("apphome_url") && file_exists($tempThumbPath)) {
         self::notifyProxy($_SERVER["REQUEST_URI"]);
     }
     // cache result
     if (!$nocache) {
         $requestKey = $_SERVER["REQUEST_URI"];
         $cache = new myCache("thumb", 86400 * 30);
         // 30 days
         $cache->put($requestKey, $tempThumbPath);
     }
     kFile::dumpFile($tempThumbPath, null, $nocache ? 0 : null);
     // TODO - can delete from disk assuming we caneasily recreate it and it will anyway be cached in the CDN
     // however dumpfile dies at the end so we cant just write it here (maybe register a shutdown callback)
 }
 public function execute()
 {
     $this->seekFrom = $this->getRequestParameter("seekFrom", -1);
     if ($this->seekFrom <= 0) {
         $this->seekFrom = -1;
     }
     $this->clipTo = $this->getRequestParameter("clipTo", 0);
     $this->deliveryCode = $this->getRequestParameter("deliveryCode", null);
     $playbackContext = $this->getRequestParameter("playbackContext", null);
     $this->protocol = $this->getRequestParameter("protocol", null);
     if (!$this->protocol || $this->protocol === "null") {
         $this->protocol = StorageProfile::PLAY_FORMAT_HTTP;
     }
     $this->format = $this->getRequestParameter("format");
     if (!$this->format) {
         $this->format = StorageProfile::PLAY_FORMAT_HTTP;
     }
     $this->tags = $this->getRequestParameter("tags", null);
     if (!$this->tags) {
         switch ($this->format) {
             case StorageProfile::PLAY_FORMAT_SILVER_LIGHT:
                 $this->tags = array(array(assetParams::TAG_SLWEB));
                 break;
             case StorageProfile::PLAY_FORMAT_APPLE_HTTP:
             case StorageProfile::PLAY_FORMAT_HDS:
                 $this->tags = array(array(assetParams::TAG_APPLEMBR), array('ipadnew', 'iphonenew'), array('ipad', 'iphone'));
                 break;
             default:
                 $this->tags = array(array(assetParams::TAG_MBR), array(assetParams::TAG_WEB));
         }
     } else {
         $this->tags = array(array($this->tags));
     }
     $this->cdnHost = $this->getRequestParameter("cdnHost", null);
     $this->preferredBitrate = $this->getRequestParameter("preferredBitrate", null);
     $this->maxBitrate = $this->getRequestParameter("maxBitrate", null);
     if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) {
         KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE);
     }
     $this->initEntry();
     $this->initFlavorIds();
     $this->storageId = $this->getRequestParameter("storageId", null);
     $this->validateStorageId();
     $partner = $this->entry->getPartner();
     if (!$this->cdnHost || $partner->getForceCdnHost()) {
         $this->cdnHost = myPartnerUtils::getCdnHost($this->entry->getPartnerId(), $this->protocol);
     }
     $playbackParams = array();
     if (kConf::hasMap("optimized_playback")) {
         $partnerId = $this->entry->getPartnerId();
         $optimizedPlayback = kConf::getMap("optimized_playback");
         if (array_key_exists($partnerId, $optimizedPlayback)) {
             $playbackParams = $optimizedPlayback[$partnerId];
         }
     }
     if (array_key_exists('enforce_encryption', $playbackParams) && $playbackParams['enforce_encryption']) {
         if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') {
             KExternalErrors::dieError(KExternalErrors::ACCESS_CONTROL_RESTRICTED, 'unencrypted manifest request - forbidden');
         }
         if (strtolower($this->protocol) != 'https') {
             KExternalErrors::dieError(KExternalErrors::ACCESS_CONTROL_RESTRICTED, 'unencrypted playback protocol - forbidden');
         }
     }
     $renderer = null;
     switch ($this->format) {
         case StorageProfile::PLAY_FORMAT_HTTP:
             $renderer = $this->serveHttp();
             break;
         case StorageProfile::PLAY_FORMAT_RTMP:
             $renderer = $this->serveRtmp();
             break;
         case StorageProfile::PLAY_FORMAT_SILVER_LIGHT:
             $renderer = $this->serveSilverLight();
             break;
         case StorageProfile::PLAY_FORMAT_APPLE_HTTP:
             $renderer = $this->serveAppleHttp();
             break;
         case StorageProfile::PLAY_FORMAT_HDS:
             $renderer = $this->serveHds();
             break;
         case "url":
             $this->format = "http";
             // build url for an http delivery
             $renderer = $this->serveUrl();
             break;
         case "rtsp":
             $renderer = $this->serveRtsp();
             break;
         case "hdnetworksmil":
             $renderer = $this->serveHDNetworkSmil();
             break;
         case "hdnetwork":
             $renderer = $this->serveHDNetwork();
             break;
         case "hdnetworkmanifest":
             $renderer = $this->serveHDNetworkManifest();
             break;
     }
     if (!$renderer) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'This format is unsupported');
     }
     $canCacheAccessControl = false;
     if (!$this->secureEntryHelper) {
         $canCacheAccessControl = true;
         // TODO: reconsider this if/when expired ktokens will be used
     } else {
         if (!$this->secureEntryHelper->shouldDisableCache() && !$this->secureEntryHelper->isKsAdmin() && ($this->secureEntryHelper->isKsWidget() || !$this->secureEntryHelper->hasRules())) {
             $canCacheAccessControl = true;
         }
     }
     if (!$renderer->tokenizer && $canCacheAccessControl) {
         // Note: kApiCache::hasExtraFields is checked in kManifestRenderers
         $renderer->cachingHeadersAge = 60;
     }
     if (!$this->secureEntryHelper || !$this->secureEntryHelper->shouldDisableCache()) {
         $cache = kPlayManifestCacher::getInstance();
         $cache->storeCache($renderer);
     }
     $renderer->output($playbackContext);
 }