예제 #1
0
 public function execute()
 {
     $this->forceSystemAuthentication();
     $file_path = $this->getP("file_path");
     if (!file_exists($file_path)) {
         echo "Cannot find file [{$file_path}]";
         die;
     }
     $mime_type = kFile::mimeType($file_path);
     //		echo "[[$mime_type]]";
     kFile::dumpFile($file_path, $mime_type);
     die;
 }
예제 #2
0
 /**
  * Serve update file
  *
  * @action serveUpdate
  * @param string $os
  * @param string $version
  * @return file
  * @throws CaptureSpaceErrors::NO_UPDATE_IS_AVAILABLE
  */
 public function serveUpdateAction($os, $version)
 {
     $filename = kCaptureSpaceVersionManager::getUpdateFile($os, $version);
     if (!$filename) {
         throw new KalturaAPIException(CaptureSpaceErrors::NO_UPDATE_IS_AVAILABLE, $version, $os);
     }
     $actualFilePath = myContentStorage::getFSContentRootPath() . "/content/third_party/capturespace/{$filename}";
     if (!file_exists($actualFilePath)) {
         throw new KalturaAPIException(CaptureSpaceErrors::NO_UPDATE_IS_AVAILABLE, $version, $os);
     }
     $mimeType = kFile::mimeType($actualFilePath);
     header("Content-Disposition: attachment; filename=\"{$filename}\"");
     return $this->dumpFile($actualFilePath, $mimeType);
 }
예제 #3
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}");
         }
     }
 }
 private function dumpFile($file_path, $file_name, $wams_asset_id = null, $wams_url = null)
 {
     $relocate = $this->getRequestParameter("relocate");
     $directServe = $this->getRequestParameter("direct_serve");
     if (!$relocate) {
         $url = $_SERVER["REQUEST_URI"];
         if (strpos($url, "?") !== false) {
             $url .= "&relocate=";
         } else {
             $url .= "/relocate/";
         }
         $url .= $this->encodeUrl($file_name);
         kFile::cacheRedirect($url);
         header("Location: {$url}");
         die;
     } else {
         if (!$directServe) {
             header("Content-Disposition: attachment; filename=\"{$file_name}\"");
         }
         if (!empty($wams_asset_id)) {
             $fileSync = FileSyncPeer::retrieveByWamsAssetId($wams_asset_id);
             kWAMS::getInstance($fileSync->getPartnerId())->dumpFile($wams_asset_id, pathinfo($file_name, PATHINFO_EXTENSION));
         } else {
             $mime_type = kFile::mimeType($file_path);
             kFile::dumpFile($file_path, $mime_type);
         }
     }
 }
예제 #5
0
파일: NdnFeed.php 프로젝트: DBezemer/server
 public function setFlavorAsset(DOMElement $item, array $flavorAssets, $flavorLang)
 {
     $flavorAsset = $flavorAssets[0];
     /* @var $flavorAsset flavorAsset */
     $url = $this->getAssetUrl($flavorAsset);
     kXml::setNodeValue($this->xpath, 'media:content/@url', $url, $item);
     kXml::setNodeValue($this->xpath, 'media:content/@width', $flavorAsset->getWidth(), $item);
     kXml::setNodeValue($this->xpath, 'media:content/@height', $flavorAsset->getHeight(), $item);
     //setting mime type
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::fileSync_exists($syncKey)) {
         $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         $mimeType = kFile::mimeType($filePath);
     }
     kXml::setNodeValue($this->xpath, 'media:content/@type', $mimeType, $item);
     if (!empty($flavorLang)) {
         kXml::setNodeValue($this->xpath, 'media:content/@lang', $flavorLang, $item);
     }
 }
예제 #6
0
 /**
  * Serves the file content
  * 
  * @action serve
  * @param flavorAsset $flavorAsset
  * @param string $fileName
  * @param bool $forceProxy
  * @return file
  * 
  * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY
  */
 protected function serveFlavorAsset(flavorAsset $flavorAsset, $fileName, $forceProxy = false)
 {
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     if (!$fileSync) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorAsset->getId());
     }
     /* @var $fileSync FileSync */
     if ($fileSync->getFileExt() != assetParams::CONTAINER_FORMAT_SWF) {
         header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     }
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         return $this->dumpFile($filePath, $mimeType);
     } else {
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         KalturaLog::info("Redirecting to [{$remoteUrl}]");
         if ($forceProxy) {
             kFileUtils::dumpUrl($remoteUrl);
         } else {
             // or redirect if no proxy
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }
예제 #7
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);
 }
예제 #8
0
 /**
  * serve action returns the original file.
  * 
  * @action serve
  * @param int $id job id
  * @return file
  * 
  */
 function serveAction($id)
 {
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $id);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $this->getPartnerId());
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_NOT_FOUND, $id);
     }
     KalturaLog::info("Batch job found for jobid [{$id}] bulk upload type [" . $batchJob->getJobSubType() . "]");
     $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     header("Content-Type: text/plain; charset=UTF-8");
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         return $this->dumpFile($filePath, $mimeType);
     } else {
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         KalturaLog::info("Redirecting to [{$remoteUrl}]");
         header("Location: {$remoteUrl}");
         die;
     }
 }
예제 #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;
 }
 /**
  * @param ISyncableFile $syncable
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false)
 {
     /* @var $fileSync FileSync */
     $syncKey = $syncable->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $wamsAssetId = $fileSync->getWamsAssetId();
         if (empty($wamsAssetId)) {
             $mimeType = kFile::mimeType($filePath);
             kFile::dumpFile($filePath, $mimeType);
         } else {
             kWAMS::getInstance($fileSync->getPartnerId())->dumpFile($wamsAssetId, pathinfo($filePath, PATHINFO_EXTENSION));
         }
     } else {
         if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$remoteUrl}]");
             if ($forceProxy) {
                 kFile::dumpApiRequest($remoteUrl);
             } else {
                 //TODO find or build function which redurects the API request with all its parameters without using curl.
                 // or redirect if no proxy
                 header("Location: {$remoteUrl}");
                 die;
             }
         } else {
             $remoteUrl = $fileSync->getExternalUrl($entryId);
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }
예제 #11
0
 /**
  * @param ISyncableFile $syncable
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false)
 {
     /* @var $fileSync FileSync */
     $syncKey = $syncable->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         return $this->dumpFile($filePath, $mimeType);
     } else {
         if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$remoteUrl}]");
             if ($forceProxy) {
                 kFileUtils::dumpApiRequest($remoteUrl);
             } else {
                 //TODO find or build function which redurects the API request with all its parameters without using curl.
                 // or redirect if no proxy
                 header("Location: {$remoteUrl}");
                 die;
             }
         } else {
             $remoteUrl = $fileSync->getExternalUrl($entryId);
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }
예제 #12
0
 /**
  * Server business-process case diagram
  * 
  * @action serveDiagram
  * @param KalturaEventNotificationEventObjectType $objectType
  * @param string $objectId
  * @param int $businessProcessStartNotificationTemplateId
  * @return file
  *
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND
  * @throws KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_CASE_NOT_FOUND
  * @throws KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_SERVER_NOT_FOUND
  */
 public function serveDiagramAction($objectType, $objectId, $businessProcessStartNotificationTemplateId)
 {
     $dbObject = kEventNotificationFlowManager::getObject($objectType, $objectId);
     if (!$dbObject) {
         throw new KalturaAPIException(KalturaErrors::OBJECT_NOT_FOUND);
     }
     $dbTemplate = EventNotificationTemplatePeer::retrieveByPK($businessProcessStartNotificationTemplateId);
     if (!$dbTemplate || !$dbTemplate instanceof BusinessProcessStartNotificationTemplate) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $businessProcessStartNotificationTemplateId);
     }
     $caseIds = $dbTemplate->getCaseIds($dbObject, false);
     if (!count($caseIds)) {
         throw new KalturaAPIException(KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_CASE_NOT_FOUND);
     }
     $dbBusinessProcessServer = BusinessProcessServerPeer::retrieveByPK($dbTemplate->getServerId());
     if (!$dbBusinessProcessServer) {
         throw new KalturaAPIException(KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_SERVER_NOT_FOUND, $dbTemplate->getServerId());
     }
     $businessProcessServer = KalturaBusinessProcessServer::getInstanceByType($dbBusinessProcessServer->getType());
     $businessProcessServer->fromObject($dbBusinessProcessServer);
     $provider = kBusinessProcessProvider::get($businessProcessServer);
     $caseId = end($caseIds);
     $filename = myContentStorage::getFSCacheRootPath() . 'bpm_diagram/bpm_';
     $filename .= $objectId . '_';
     $filename .= $businessProcessStartNotificationTemplateId . '_';
     $filename .= $caseId . '.jpg';
     $url = $provider->getCaseDiagram($caseId, $filename);
     KCurlWrapper::getDataFromFile($url, $filename);
     $mimeType = kFile::mimeType($filename);
     return $this->dumpFile($filename, $mimeType);
 }
예제 #13
0
 private function dumpFile($file_path, $file_name, $limit_file_size = 0)
 {
     $file_name = str_replace("\n", ' ', $file_name);
     $relocate = $this->getRequestParameter("relocate");
     $directServe = $this->getRequestParameter("direct_serve");
     if (!$relocate) {
         $url = $_SERVER["REQUEST_URI"];
         if (strpos($url, "?") !== false) {
             $url .= "&relocate=";
         } else {
             $url .= "/relocate/";
         }
         $url .= kString::stripInvalidUrlChars($file_name);
         kFile::cacheRedirect($url);
         header("Location: {$url}");
         KExternalErrors::dieGracefully();
     } else {
         if (!$directServe) {
             header("Content-Disposition: attachment; filename=\"{$file_name}\"");
         }
         $mime_type = kFile::mimeType($file_path);
         kFileUtils::dumpFile($file_path, $mime_type, null, $limit_file_size);
     }
 }
예제 #14
0
 /**
  * @param FileSync $fileSync
  * @param bool $local
  * @param string $fileName
  * @param bool $forceProxy
  */
 protected function serveThumbToFile(FileSync $fileSync, $local, $fileName, $forceProxy = 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}");
         }
     }
 }
예제 #15
0
 private function dumpFile($file_path, $file_name)
 {
     $relocate = $this->getRequestParameter("relocate");
     $directServe = $this->getRequestParameter("direct_serve");
     if (!$relocate) {
         $url = $_SERVER["REQUEST_URI"];
         if (strpos($url, "?") !== false) {
             $url = substr($url, 0, strpos($url, "?"));
         }
         $url .= "/relocate/" . $this->encodeUrl($file_name);
         header("Location: {$url}");
         die;
     } else {
         if (!$directServe) {
             header("Content-Disposition: attachment; filename=\"{$file_name}\"");
         }
         $mime_type = kFile::mimeType($file_path);
         kFile::dumpFile($file_path, $mime_type);
     }
 }
예제 #16
0
 /**
  * @param EntryDistribution $entryDistribution
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaAPIException
  */
 protected function serveFile(EntryDistribution $entryDistribution, $fileSubType, $fileName, $forceProxy = false)
 {
     $syncKey = $entryDistribution->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(ContentDistributionErrors::ENTRY_DISTRIBUTION_MISSING_LOG, $entryDistribution->getId(), $fileSubType);
     }
     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}");
         }
     }
 }