示例#1
0
 public function getEntry()
 {
     if ($this->aEntry == null && $this->getEntryId()) {
         $this->aEntry = entryPeer::retrieveByPKNoFilter($this->getEntryId());
     }
     return $this->aEntry;
 }
 public function objectUpdated(BaseObject $object, BatchJob $raisedJob = null)
 {
     $entry = entryPeer::retrieveByPKNoFilter($object->getEntryId());
     if ($entry) {
         $entry->setUpdatedAt(time());
         $entry->save();
     }
     return true;
 }
示例#3
0
 /**
  * @return entry
  */
 protected function getEntry()
 {
     $entryId = $this->getEntryId();
     $entry = entryPeer::getInstanceFromPool($entryId);
     if (!$entry) {
         $entry = entryPeer::retrieveByPKNoFilter($entryId);
     }
     return $entry;
 }
示例#4
0
 private static function calculateId()
 {
     $dc = kDataCenterMgr::getCurrentDc();
     for ($i = 0; $i < 10; ++$i) {
         $id = $dc["id"] . '_' . kString::generateStringId();
         $existing_object = entryPeer::retrieveByPKNoFilter($id);
         if (!$existing_object) {
             return $id;
         }
     }
     die;
 }
 public function execute()
 {
     $entry_id = $this->getRequestParameter("entryId");
     // workaround the filter which hides all the deleted entries -
     // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here
     $entry = entryPeer::retrieveByPKNoFilter($entry_id);
     if (!$entry) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     if ($entry->getType() != entryType::LIVE_STREAM || $entry->getStatus() == entryStatus::DELETED) {
         // because the fiter was turned off - a manual check for deleted entries must be done.
         die;
     }
     $file = $entry->getStreamName();
     $streamer = $entry->getStreamUrl();
     $this->logMessage("streamclipper: serving entry [{$entry_id}] file[{$file}] streamer[{$streamer}]", "warning");
     $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<config>\n\t<file>{$file}</file>\n\t<subscribe>true</subscribe>\n\t<streamer>{$streamer}</streamer>\n\t<type>fcsubscribe</type>\n</config>";
     header("Content-Type: text/xml; charset=UTF-8");
     echo $xml;
     die;
 }
 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;
 }
示例#7
0
 /**
  * @param kOperationResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset
  */
 protected function attachOperationResource(kOperationResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $isNewAsset = false;
     $isSource = false;
     if ($dbAsset) {
         if ($dbAsset instanceof flavorAsset) {
             $isSource = $dbAsset->getIsOriginal();
         }
     } else {
         $isNewAsset = true;
         $isSource = true;
         KalturaLog::debug("Creating original flavor asset");
         $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId());
     }
     if (!$dbAsset && $dbEntry->getStatus() == entryStatus::NO_CONTENT) {
         $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
         $dbEntry->save();
     }
     $operationAttributes = $resource->getOperationAttributes();
     $internalResource = $resource->getResource();
     if ($internalResource instanceof kLiveEntryResource) {
         $dbEntry->setOperationAttributes($operationAttributes);
         $dbEntry->save();
         return $this->attachLiveEntryResource($internalResource, $dbEntry, $dbAsset, $operationAttributes);
     }
     $dbAsset = $this->attachResource($internalResource, $dbEntry, $dbAsset);
     $sourceType = $resource->getSourceType();
     if ($sourceType) {
         $dbEntry->setSource($sourceType);
         $dbEntry->save();
     }
     $errDescription = '';
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $resource->getAssetParamsId(), $errDescription, $dbAsset->getId(), $operationAttributes);
     if ($isNewAsset) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
     }
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset));
     if ($isSource && $internalResource instanceof kFileSyncResource) {
         $srcEntryId = $internalResource->getEntryId();
         if ($srcEntryId) {
             $srcEntry = entryPeer::retrieveByPKNoFilter($srcEntryId);
             if ($srcEntry) {
                 $dbEntry->setSourceEntryId($srcEntryId);
                 $dbEntry->setRootEntryId($srcEntry->getRootEntryId(true));
             }
         }
         $dbEntry->setOperationAttributes($operationAttributes);
         $dbEntry->save();
     }
     return $dbAsset;
 }
示例#8
0
文件: asset.php 项目: DBezemer/server
 /**
  * (non-PHPdoc)
  * @see lib/model/ISyncableFile#generateFilePathArr()
  */
 public function generateFilePathArr($sub_type, $version = null)
 {
     static::validateFileSyncSubType($sub_type);
     $version = is_null($version) ? $this->getVersionForSubType($sub_type) : $version;
     $entry = entryPeer::retrieveByPKNoFilter($this->getEntryId());
     if (!$entry) {
         throw new Exception("Could not find entry [" . $this->getEntryId() . "] for asset [" . $this->getId() . "]");
     }
     $dir = intval($entry->getIntId() / 1000000) . '/' . intval($entry->getIntId() / 1000) % 1000;
     $path = "/content/entry/data/{$dir}/" . $this->generateFileName($sub_type, $version);
     return array(myContentStorage::getFSContentRootPath(), $path);
 }
示例#9
0
 /**
  * @param BatchJob $batchJob
  * @param $data
  * @param int $type
  * @param int $subType
  * @return BatchJob
  */
 public static function addJob(BatchJob $batchJob, kJobData $data, $type, $subType = null)
 {
     $batchJob->setJobType($type);
     $batchJob->setJobSubType($subType);
     $batchJob->setData($data);
     if (!$batchJob->getParentJobId() && $batchJob->getEntryId()) {
         $currentJob = kBatchManager::getCurrentUpdatingJob();
         if ($currentJob && $currentJob->getEntryId() == $batchJob->getEntryId()) {
             $batchJob->setParentJobId($currentJob->getId());
             $batchJob->setBulkJobId($currentJob->getBulkJobId());
             $batchJob->setRootJobId($currentJob->getRootJobId());
         } else {
             $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId());
             // some jobs could be on deleted entry
             if ($entry) {
                 $batchJob->setRootJobId($entry->getBulkUploadId());
                 $batchJob->setBulkJobId($entry->getBulkUploadId());
             }
         }
     }
     $lockInfo = new kLockInfoData($batchJob);
     $lockInfo->setEstimatedEffort($data->calculateEstimatedEffort($batchJob));
     $lockInfo->setPriority($data->calculatePriority($batchJob));
     $lockInfo->setUrgency($data->calculateUrgency($batchJob));
     $batchJob->setLockInfo($lockInfo);
     if (is_null($batchJob->getStatus())) {
         $batchJob = self::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
     } else {
         $batchJob = self::updateBatchJob($batchJob, $batchJob->getStatus());
     }
     return $batchJob;
 }
示例#10
0
 protected function updatedVirusScanFailed(BatchJob $dbBatchJob, kVirusScanJobData $data)
 {
     $entry = entryPeer::retrieveByPKNoFilter($dbBatchJob->getEntryId());
     if ($entry) {
         self::setEntryStatusBeforeScanFailure($entry, $entry->getStatus());
         $entry->setStatus(VirusScanPlugin::getEntryStatusCoreValue(VirusScanEntryStatus::SCAN_FAILURE));
         $entry->save();
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
     } else {
         KalturaLog::err('Entry not found with id [' . $dbBatchJob->getEntryId() . ']');
         throw new Exception('Entry not found with id [' . $dbBatchJob->getEntryId() . ']');
     }
     $flavorAsset = assetPeer::retrieveById($data->getFlavorAssetId());
     if ($flavorAsset) {
         self::setFlavorAssetStatusBeforeScanFailure($flavorAsset, $flavorAsset->getStatus());
         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
         $flavorAsset->save();
     } else {
         KalturaLog::err('Flavor asset not found with id [' . $data->getFlavorAssetId() . ']');
         throw new Exception('Flavor asset not found with id [' . $data->getFlavorAssetId() . ']');
     }
     // do not resume flavor asset added event consumption
     return $dbBatchJob;
 }
示例#11
0
 /**
  * 
  * @param $getDeleted
  * @param $enableCache
  * 
  * @return entry
  */
 public function getEntry($getDeleted = false, $enableCache = true)
 {
     if (!$enableCache) {
         $this->aEntry = null;
         entryPeer::clearInstancePool();
     }
     if ($this->aEntry == null && $this->getEntryId()) {
         if ($getDeleted) {
             $this->aEntry = entryPeer::retrieveByPKNoFilter($this->getEntryId());
         } else {
             $this->aEntry = entryPeer::retrieveByPK($this->getEntryId());
         }
     }
     return $this->aEntry;
 }
 protected function getFieldValuesXml(EntryDistribution $entryDistribution, $fieldName = null)
 {
     $entry = entryPeer::retrieveByPKNoFilter($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err('Entry not found with ID [' . $entryDistribution->getEntryId() . ']');
         return null;
     }
     // set the default criteria to use the current entry distribution partner id (it is restored later)
     // this is needed for related entries under kMetadataMrssManager which is using retrieveByPK without the correct partner id filter
     $oldEntryCriteria = entryPeer::getCriteriaFilter()->getFilter();
     myPartnerUtils::resetPartnerFilter('entry');
     myPartnerUtils::addPartnerToCriteria('entry', $entryDistribution->getPartnerId(), true);
     try {
         $mrss = null;
         $mrssParams = new kMrssParameters();
         if ($this->getItemXpathsToExtend()) {
             $mrssParams->setItemXpathsToExtend($this->getItemXpathsToExtend());
         }
         $mrss = kMrssManager::getEntryMrssXml($entry, $mrss, $mrssParams);
         $mrssStr = $mrss->asXML();
     } catch (Exception $e) {
         // restore the original criteria so it will not get stuck due to the exception
         entryPeer::getCriteriaFilter()->setFilter($oldEntryCriteria);
         throw $e;
     }
     // restore the original criteria
     entryPeer::getCriteriaFilter()->setFilter($oldEntryCriteria);
     if (!$mrssStr) {
         KalturaLog::err('No MRSS returned for entry [' . $entry->getId() . ']');
         return null;
     }
     $mrssObj = new DOMDocument();
     if (!$mrssObj->loadXML($mrssStr)) {
         KalturaLog::err('Error loading MRSS XML object for entry [' . $entry->getId() . ']');
         return null;
     }
     $xslObj = new DOMDocument();
     $xslStr = $this->getFieldValuesXslt($entryDistribution, $fieldName);
     $xslStr = trim($xslStr);
     if (!$xslObj->loadXML($xslStr)) {
         KalturaLog::err('Error loading distribution profile XSLT for profile ID [' . $this->getId() . ']');
         return null;
     }
     $proc = new XSLTProcessor();
     $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
     $proc->importStyleSheet($xslObj);
     $resultXml = $proc->transformToXml($mrssObj);
     //in order to keep the UTF-8 encoding we transformToXml http://www.php.net/manual/en/xsltprocessor.transformtodoc.php#69305
     $resultXmlObj = new DOMDocument();
     $resultXmlObj->loadXML($resultXml);
     if (!$resultXmlObj) {
         KalturaLog::err('Error transforming XML for distribution profile [' . $this->getId() . '] and entry id [' . $entry->getId() . ']');
         return null;
     }
     /* DEBUG logs
     		KalturaLog::log('entry mrss = '.$mrssStr);
     		KalturaLog::log('profile xslt = '.$xslStr);
     		*/
     KalturaLog::debug('Result XML: ' . $resultXmlObj->saveXML());
     return $resultXmlObj;
 }
 protected function flagEntry(KalturaModerationFlag $moderationFlag, $entryType = null)
 {
     $moderationFlag->validatePropertyNotNull("flaggedEntryId");
     $entryId = $moderationFlag->flaggedEntryId;
     $dbEntry = entryPeer::retrieveByPKNoFilter($entryId);
     if (!$dbEntry || $entryType !== null && $dbEntry->getType() != $entryType) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $validModerationStatuses = array(KalturaEntryModerationStatus::APPROVED, KalturaEntryModerationStatus::AUTO_APPROVED, KalturaEntryModerationStatus::FLAGGED_FOR_REVIEW);
     if (!in_array($dbEntry->getModerationStatus(), $validModerationStatuses)) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_CANNOT_BE_FLAGGED);
     }
     $dbModerationFlag = new moderationFlag();
     $dbModerationFlag->setPartnerId($dbEntry->getPartnerId());
     $dbModerationFlag->setKuserId($this->getKuser()->getId());
     $dbModerationFlag->setFlaggedEntryId($dbEntry->getId());
     $dbModerationFlag->setObjectType(KalturaModerationObjectType::ENTRY);
     $dbModerationFlag->setStatus(KalturaModerationFlagStatus::PENDING);
     $dbModerationFlag->setFlagType($moderationFlag->flagType);
     $dbModerationFlag->setComments($moderationFlag->comments);
     $dbModerationFlag->save();
     $dbEntry->setModerationStatus(KalturaEntryModerationStatus::FLAGGED_FOR_REVIEW);
     $dbEntry->incModerationCount();
     $dbEntry->save();
     $moderationFlag = new KalturaModerationFlag();
     $moderationFlag->fromObject($dbModerationFlag);
     // need to notify the partner that an entry was flagged - use the OLD moderation onject that is required for the
     // NOTIFICATION_TYPE_ENTRY_REPORT notification
     // TODO - change to moderationFlag object to implement the interface for the notification:
     // it should have "objectId", "comments" , "reportCode" as getters
     $oldModerationObj = new moderation();
     $oldModerationObj->setPartnerId($dbEntry->getPartnerId());
     $oldModerationObj->setComments($moderationFlag->comments);
     $oldModerationObj->setObjectId($dbEntry->getId());
     $oldModerationObj->setObjectType(moderation::MODERATION_OBJECT_TYPE_ENTRY);
     $oldModerationObj->setReportCode("");
     myNotificationMgr::createNotification(notification::NOTIFICATION_TYPE_ENTRY_REPORT, $oldModerationObj, $dbEntry->getPartnerId());
     return $moderationFlag;
 }
 /**
  * @param BatchJob $batchJob
  * @param $data
  * @param int $type
  * @param int $subType
  * @return BatchJob
  */
 public static function addJob(BatchJob $batchJob, $data, $type, $subType = null)
 {
     $batchJob->setJobType($type);
     $batchJob->setJobSubType($subType);
     $batchJob->setData($data);
     if (!$batchJob->getParentJobId() && $batchJob->getEntryId()) {
         $currentJob = kBatchManager::getCurrentUpdatingJob();
         if ($currentJob && $currentJob->getEntryId() == $batchJob->getEntryId()) {
             $batchJob->setParentJobId($currentJob->getId());
             $batchJob->setBulkJobId($currentJob->getBulkJobId());
             $batchJob->setRootJobId($currentJob->getRootJobId());
         } else {
             $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId());
             // some jobs could be on deleted entry
             if ($entry) {
                 $batchJob->setRootJobId($entry->getBulkUploadId());
                 $batchJob->setBulkJobId($entry->getBulkUploadId());
             }
         }
     }
     // validate partner id
     $partnerId = $batchJob->getPartnerId();
     //		if(!$partnerId)
     //			throw new APIException(APIErrors::PARTNER_NOT_SET);
     // validate that partner exists
     $partner = PartnerPeer::retrieveByPK($partnerId);
     if (!$partner) {
         KalturaLog::err("Invalid partner id [{$partnerId}]");
         throw new APIException(APIErrors::INVALID_PARTNER_ID, $partnerId);
     }
     // set the priority and work group
     $batchJob->setPriority($partner->getPriority($batchJob->getBulkJobId()));
     $batchJob = self::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
     // look for identical jobs
     $twinJobs = BatchJobPeer::retrieveDuplicated($type, $data);
     $twinJob = null;
     if (count($twinJobs)) {
         foreach ($twinJobs as $currentTwinJob) {
             if ($currentTwinJob->getId() != $batchJob->getId()) {
                 $twinJob = reset($twinJobs);
             }
         }
     }
     if (!is_null($twinJob)) {
         $batchJob->setTwinJobId($twinJob->getId());
         if (!kConf::get("batch_ignore_duplication")) {
             $batchJob = self::updateBatchJob($batchJob, $twinJob->getStatus(), $twinJob);
         } else {
             $batchJob->save();
         }
     }
     return $batchJob;
 }
示例#15
0
 /**
  * Restore deleted entry.
  *
  * @action restoreDeletedEntry
  * @param string $entryId
  * @return KalturaBaseEntry The restored entry
  */
 public function restoreDeletedEntryAction($entryId)
 {
     $deletedEntry = entryPeer::retrieveByPKNoFilter($entryId);
     if (!$deletedEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $fileSyncKeys = array();
     foreach (self::$fileSyncKeysToRestore as $key) {
         $fileSyncKeys[] = $deletedEntry->getSyncKey($key);
     }
     $c = new Criteria();
     $c->add(assetPeer::ENTRY_ID, $entryId, Criteria::EQUAL);
     assetPeer::setUseCriteriaFilter(false);
     $deletedAssets = assetPeer::doSelect($c);
     assetPeer::setUseCriteriaFilter(true);
     foreach ($deletedAssets as $deletedAsset) {
         array_push($fileSyncKeys, $deletedAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET), $deletedAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_CONVERT_LOG));
     }
     $fileSyncs = array();
     FileSyncPeer::setUseCriteriaFilter(false);
     foreach ($fileSyncKeys as $fileSyncKey) {
         $fileSyncs = array_merge($fileSyncs, FileSyncPeer::retrieveAllByFileSyncKey($fileSyncKey));
     }
     FileSyncPeer::setUseCriteriaFilter(true);
     if (!$this->validateEntryForRestoreDelete($deletedEntry, $fileSyncs, $deletedAssets)) {
         throw new KalturaAPIException(KalturaAdminConsoleErrors::ENTRY_ASSETS_WRONG_STATUS_FOR_RESTORE, $entryId);
     }
     $this->restoreFileSyncs($fileSyncs);
     //restore assets
     foreach ($deletedAssets as $deletedAsset) {
         $deletedAsset->setStatus(asset::ASSET_STATUS_READY);
         $deletedAsset->save();
     }
     //restore entry
     $deletedEntry->setStatusReady();
     $deletedEntry->setThumbnail($deletedEntry->getFromCustomData("deleted_original_thumb"), true);
     $deletedEntry->setData($deletedEntry->getFromCustomData("deleted_original_data"), true);
     //data should be resotred even if it's NULL
     $deletedEntry->save();
     kEventsManager::flushEvents();
     kMemoryManager::clearMemory();
     $entry = KalturaEntryFactory::getInstanceByType($deletedEntry->getType(), true);
     $entry->fromObject($deletedEntry, $this->getResponseProfile());
     return $entry;
 }
示例#16
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)
 }
示例#17
0
 /**
  * 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->getRequestParameter("version", null);
     $width = $this->getRequestParameter("width", -1);
     $height = $this->getRequestParameter("height", -1);
     $type = $this->getRequestParameter("type", 1);
     $crop_provider = $this->getRequestParameter("crop_provider", null);
     $quality = $this->getRequestParameter("quality", 0);
     $src_x = $this->getRequestParameter("src_x", 0);
     $src_y = $this->getRequestParameter("src_y", 0);
     $src_w = $this->getRequestParameter("src_w", 0);
     $src_h = $this->getRequestParameter("src_h", 0);
     $vid_sec = $this->getRequestParameter("vid_sec", -1);
     $vid_slice = $this->getRequestParameter("vid_slice", -1);
     $vid_slices = $this->getRequestParameter("vid_slices", -1);
     // 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->getRequestParameter("rel_width", -1);
     $rel_height = $this->getRequestParameter("rel_height", -1);
     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");
     if ($upload_token_id) {
         $upload_token = UploadTokenPeer::retrieveByPK($upload_token_id);
         if ($upload_token) {
             $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);
                 kFile::dumpFile($thumb_full_path);
             }
         }
     }
     $entry = entryPeer::retrieveByPKNoFilter($entry_id);
     // 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;
     }
     if (!$entry) {
         // 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);
         }
     }
     $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";
         }
         kFile::dumpFile($msgPath, null, 0);
     }
     if (!$file_sync) {
         // if entry type is audio - serve generic thumb:
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             if ($entry->getStatus() == entryStatus::DELETED && $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK) {
                 KalturaLog::log("rejected audio entry - not serving thumbnail");
                 KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED);
             }
             $contentPath = myContentStorage::getFSContentRootPath();
             $msgPath = $contentPath . "content/templates/entry/thumbnail/audio_thumb.jpg";
             $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, $msgPath);
             //kFile::dumpFile($tempThumbPath, null, 0);
         } elseif ($entry->getType() == entryType::LIVE_STREAM) {
             if ($entry->getStatus() == entryStatus::DELETED && $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK) {
                 KalturaLog::log("rejected live stream entry - not serving thumbnail");
                 KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED);
             }
             $contentPath = myContentStorage::getFSContentRootPath();
             $msgPath = $contentPath . "content/templates/entry/thumbnail/live_thumb.jpg";
             $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, $msgPath);
         } elseif ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_SHOW) {
             $contentPath = myContentStorage::getFSContentRootPath();
             $msgPath = $contentPath . "content/templates/entry/thumbnail/auto_edit.jpg";
             $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, $msgPath);
             //kFile::dumpFile($tempThumbPath, null, 0);
         } elseif ($entry->getType() == entryType::MEDIA_CLIP) {
             // commenting out the new behavior, in this case the thumbnail will be created in resizeEntryImage
             //$contentPath = myContentStorage::getFSContentRootPath();
             //$msgPath = $contentPath."content/templates/entry/thumbnail/broken_thumb.jpg";
             //header("Xkaltura-app: entry [$entry_id] in conversion, returning template broken thumb");
             //KalturaLog::log( "Entry in conversion, no thumbnail yet [$entry_id], created dynamic 1x1 jpg");
             //kFile::dumpFile($msgPath, null, 0);
             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);
             } catch (Exception $ex) {
                 if ($ex->getCode() == kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) {
                     // get original flavor asset
                     $origFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry_id);
                     if ($origFlavorAsset) {
                         $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);
                         }
                         $remote_url = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync, $_SERVER['REQUEST_URI']);
                         KalturaLog::log(__METHOD__ . ": redirecting to [{$remote_url}]");
                         $this->redirect($remote_url);
                     }
                 }
             }
         } else {
             // file does not exist on any DC - die
             KalturaLog::log("Error - no FileSync for entry [{$entry_id}]");
             KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
         }
     }
     if (!$local && !$tempThumbPath) {
         $remote_url = kDataCenterMgr::getRedirectExternalUrl($file_sync, $_SERVER['REQUEST_URI']);
         KalturaLog::log(__METHOD__ . ": redirecting to [{$remote_url}]");
         $this->redirect($remote_url);
     }
     // 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);
         } catch (Exception $ex) {
             if ($ex->getCode() == kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) {
                 // get original flavor asset
                 $origFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry_id);
                 if ($origFlavorAsset) {
                     $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);
                     }
                     $remote_url = kDataCenterMgr::getRedirectExternalUrl($remoteFileSync, $_SERVER['REQUEST_URI']);
                     KalturaLog::log(__METHOD__ . ": redirecting to [{$remote_url}]");
                     $this->redirect($remote_url);
                 }
             }
         }
     }
     $nocache = strpos($tempThumbPath, "_NOCACHE_") !== false;
     // 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)
 }
示例#18
0
 public static function initPartnerByEntryId($entryId)
 {
     $entry = entryPeer::retrieveByPKNoFilter($entryId);
     if (!$entry) {
         return null;
     }
     kCurrentContext::$ks = null;
     kCurrentContext::$ks_object = null;
     kCurrentContext::$ks_hash = null;
     kCurrentContext::$ks_partner_id = $entry->getPartnerId();
     kCurrentContext::$ks_uid = null;
     kCurrentContext::$master_partner_id = null;
     kCurrentContext::$partner_id = $entry->getPartnerId();
     kCurrentContext::$uid = null;
     kCurrentContext::$is_admin_session = false;
     return $entry;
 }
示例#19
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kExtractMediaJobData $data
  * @return BatchJob
  */
 public static function handleExtractMediaClosed(BatchJob $dbBatchJob, kExtractMediaJobData $data)
 {
     if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) {
         return $dbBatchJob;
     }
     $rootBatchJob = $dbBatchJob->getRootJob();
     if (!$rootBatchJob) {
         return $dbBatchJob;
     }
     /*
      * Fix web-cam sources with bad timestamps
      */
     $dbBatchJobAux = self::fixWebCamSources($rootBatchJob, $dbBatchJob, $data);
     if ($dbBatchJobAux != null) {
         return $dbBatchJobAux;
     }
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) {
         $entry = entryPeer::retrieveByPKNoFilter($dbBatchJob->getEntryId());
         if ($entry->getStatus() != entryStatus::READY && $entry->getStatus() != entryStatus::DELETED) {
             kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::PRECONVERT);
         }
     }
     if ($rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
         try {
             kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $rootBatchJob, $data->getMediaInfoId());
         } catch (Exception $ex) {
             $code = $ex->getCode();
             if ($code == KDLErrors::SanityInvalidFrameDim || $code == KDLErrors::NoValidMediaStream) {
                 kBusinessPostConvertDL::handleConvertFailed($dbBatchJob, null, $data->getFlavorAssetId(), null, null);
                 return $dbBatchJob;
             }
             //This was added so the all the assets prior to reaching the limit would still be created
             if ($code != kCoreException::MAX_ASSETS_PER_ENTRY) {
                 throw $ex;
             }
             KalturaLog::err("Max assets per entry was reached continuing with normal flow");
         }
         // handle the source flavor as if it was converted, makes the entry ready according to ready behavior rules
         $currentFlavorAsset = assetPeer::retrieveById($data->getFlavorAssetId());
         if ($currentFlavorAsset && $currentFlavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_READY) {
             $dbBatchJob = kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset);
         }
     }
     return $dbBatchJob;
 }
示例#20
0
 /**
  * Get MRSS by entry id
  * XML will return as an escaped string
  *
  * @action getMrss
  * @param string $entryId Entry id
  * @param KalturaExtendingItemMrssParameterArray $extendingItemsArray
  * @return string
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  */
 function getMrssAction($entryId, KalturaExtendingItemMrssParameterArray $extendingItemsArray = null)
 {
     $dbEntry = entryPeer::retrieveByPKNoFilter($entryId);
     if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $mrssParams = new kMrssParameters();
     if ($extendingItemsArray) {
         $coreExtendingItemArray = $extendingItemsArray->toObjectsArray();
         $mrssParams->setItemXpathsToExtend($coreExtendingItemArray);
     }
     /* @var $mrss SimpleXMLElement */
     $mrss = kMrssManager::getEntryMrssXml($dbEntry, null, $mrssParams);
     return $mrss->asXML();
 }
 public function loadProperties(KalturaDistributionJobData $distributionJobData, KalturaGenericDistributionProfile $distributionProfile, $action)
 {
     $actionName = self::$actionAttributes[$action];
     $genericProviderAction = GenericDistributionProviderActionPeer::retrieveByProviderAndAction($distributionProfile->genericProviderId, $action);
     if (!$genericProviderAction) {
         KalturaLog::err("Generic provider [{$distributionProfile->genericProviderId}] action [{$actionName}] not found");
         return;
     }
     if (!$distributionJobData->entryDistribution) {
         KalturaLog::err("Entry Distribution object not provided");
         return;
     }
     if (!$distributionProfile->{$actionName}->protocol) {
         $distributionProfile->{$actionName}->protocol = $genericProviderAction->getProtocol();
     }
     if (!$distributionProfile->{$actionName}->serverUrl) {
         $distributionProfile->{$actionName}->serverUrl = $genericProviderAction->getServerAddress();
     }
     if (!$distributionProfile->{$actionName}->serverPath) {
         $distributionProfile->{$actionName}->serverPath = $genericProviderAction->getRemotePath();
     }
     if (!$distributionProfile->{$actionName}->username) {
         $distributionProfile->{$actionName}->username = $genericProviderAction->getRemoteUsername();
     }
     if (!$distributionProfile->{$actionName}->password) {
         $distributionProfile->{$actionName}->password = $genericProviderAction->getRemotePassword();
     }
     if (!$distributionProfile->{$actionName}->ftpPassiveMode) {
         $distributionProfile->{$actionName}->ftpPassiveMode = $genericProviderAction->getFtpPassiveMode();
     }
     if (!$distributionProfile->{$actionName}->httpFieldName) {
         $distributionProfile->{$actionName}->httpFieldName = $genericProviderAction->getHttpFieldName();
     }
     if (!$distributionProfile->{$actionName}->httpFileName) {
         $distributionProfile->{$actionName}->httpFileName = $genericProviderAction->getHttpFileName();
     }
     $entry = entryPeer::retrieveByPKNoFilter($distributionJobData->entryDistribution->entryId);
     if (!$entry) {
         KalturaLog::err("Entry [" . $distributionJobData->entryDistribution->entryId . "] not found");
         return;
     }
     $mrss = kMrssManager::getEntryMrss($entry);
     if (!$mrss) {
         KalturaLog::err("MRSS not returned for entry [" . $entry->getId() . "]");
         return;
     }
     $xml = new KDOMDocument();
     if (!$xml->loadXML($mrss)) {
         KalturaLog::err("MRSS not is not valid XML:\n{$mrss}\n");
         return;
     }
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_MRSS_TRANSFORMER);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $xslPath = kFileSyncUtils::getLocalFilePathForKey($key);
         if ($xslPath) {
             $xsl = new KDOMDocument();
             $xsl->load($xslPath);
             // set variables in the xsl
             $varNodes = $xsl->getElementsByTagName('variable');
             foreach ($varNodes as $varNode) {
                 $nameAttr = $varNode->attributes->getNamedItem('name');
                 if (!$nameAttr) {
                     continue;
                 }
                 $name = $nameAttr->value;
                 if ($name && $distributionJobData->{$name}) {
                     $varNode->textContent = $distributionJobData->{$name};
                     $varNode->appendChild($xsl->createTextNode($distributionJobData->{$name}));
                 }
             }
             $proc = new XSLTProcessor();
             $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
             $proc->importStyleSheet($xsl);
             $xml = $proc->transformToDoc($xml);
             if (!$xml) {
                 KalturaLog::err("Transform returned false");
                 return;
             }
         }
     }
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_MRSS_VALIDATOR);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $xsdPath = kFileSyncUtils::getLocalFilePathForKey($key);
         if ($xsdPath && !$xml->schemaValidate($xsdPath)) {
             KalturaLog::err("Inavlid XML:\n" . $xml->saveXML());
             KalturaLog::err("Schema [{$xsdPath}]:\n" . file_get_contents($xsdPath));
             return;
         }
     }
     $this->xml = $xml->saveXML();
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_RESULTS_TRANSFORMER);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $this->resultParseData = kFileSyncUtils::file_get_contents($key, true, false);
     }
     $this->resultParserType = $genericProviderAction->getResultsParser();
 }
示例#22
0
文件: test.php 项目: DBezemer/server
	{
		$field = $matches[1];
//		$providerData->$field = $matches[2];
	}
}

		$fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP);
		if(!$fileTransferMgr)
			throw new Exception("SFTP manager not loaded");
			
		$fileTransferMgr->login('ftp-int.vzw.real.com', 'vp_foxsports', 'X4ul3ap');
		print_r($fileTransferMgr->listDir("/pub/in"));
//		$fileTransferMgr->putFile($destFile, $srcFile, true);

		return;*/
$entry = entryPeer::retrieveByPKNoFilter($entryId);
$mrss = kMrssManager::getEntryMrss($entry);
file_put_contents('mrss.xml', $mrss);
KalturaLog::debug("MRSS [{$mrss}]");
$distributionJobData = new KalturaDistributionSubmitJobData();
$dbDistributionProfile = DistributionProfilePeer::retrieveByPK(3);
$distributionProfile = new KalturaDailymotionDistributionProfile();
$distributionProfile->fromObject($dbDistributionProfile);
$distributionJobData->distributionProfileId = $distributionProfile->id;
$distributionJobData->distributionProfile = $distributionProfile;
$dbEntryDistribution = EntryDistributionPeer::retrieveByPK(24);
$entryDistribution = new KalturaEntryDistribution();
$entryDistribution->fromObject($dbEntryDistribution);
$distributionJobData->entryDistributionId = $entryDistribution->id;
$distributionJobData->entryDistribution = $entryDistribution;
$myp = new DailymotionDistributionProfile();
 /**
  * @param string $entryId
  * @param KalturaIdeticDistributionJobProviderData $providerData
  * @return DOMDocument
  */
 public static function generateXML($entryId, KalturaIdeticDistributionJobProviderData $providerData)
 {
     $entry = entryPeer::retrieveByPKNoFilter($entryId);
     $mrss = kMrssManager::getEntryMrss($entry);
     if (!$mrss) {
         KalturaLog::err("No MRSS returned for entry [{$entryId}]");
         return null;
     }
     $xml = new KDOMDocument();
     if (!$xml->loadXML($mrss)) {
         KalturaLog::err("Could not load MRSS as XML for entry [{$entryId}]");
         return null;
     }
     $xslPath = realpath(dirname(__FILE__) . '/../') . '/xml/submit.xsl';
     if (!file_exists($xslPath)) {
         KalturaLog::err("XSL file not found [{$xslPath}]");
         return null;
     }
     $xsl = new KDOMDocument();
     $xsl->load($xslPath);
     // set variables in the xsl
     $varNodes = $xsl->getElementsByTagName('variable');
     foreach ($varNodes as $varNode) {
         $nameAttr = $varNode->attributes->getNamedItem('name');
         if (!$nameAttr) {
             continue;
         }
         $name = $nameAttr->value;
         if ($name && $providerData->{$name}) {
             $varNode->textContent = $providerData->{$name};
             $varNode->appendChild($xsl->createTextNode($providerData->{$name}));
             KalturaLog::debug("Set variable [{$name}] to [{$providerData->{$name}}]");
         }
     }
     $proc = new XSLTProcessor();
     $proc->registerPHPFunctions();
     $proc->importStyleSheet($xsl);
     $xml = $proc->transformToDoc($xml);
     if (!$xml) {
         KalturaLog::err("XML Transformation failed");
         return null;
     }
     // TODO create validation XSD
     $xsdPath = realpath(dirname(__FILE__) . '/../') . '/xml/submit.xsd';
     if (file_exists($xsdPath) && !$xml->schemaValidate($xsdPath)) {
         KalturaLog::err("Schema validation failed");
         return null;
     }
     return $xml;
 }
示例#24
0
 public function execute()
 {
     requestUtils::handleConditionalGet();
     $entry_id = $this->getRequestParameter("entry_id");
     $ks_str = $this->getRequestParameter("ks");
     $base64_referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($base64_referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     $clip_from = $this->getRequestParameter("clip_from", 0);
     // milliseconds
     $clip_to = $this->getRequestParameter("clip_to", 2147483647);
     // milliseconds
     if ($clip_to == 0) {
         $clip_to = 2147483647;
     }
     $request = $_SERVER["REQUEST_URI"];
     // remove dynamic fields from the url so we'll request a single url from the cdn
     $request = str_replace("/referrer/{$base64_referrer}", "", $request);
     $request = str_replace("/ks/{$ks_str}", "", $request);
     // workaround the filter which hides all the deleted entries -
     // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here
     $entry = entryPeer::retrieveByPKNoFilter($entry_id);
     if (!$entry) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     // set the memory size to be able to serve big files in a single chunk
     ini_set("memory_limit", "64M");
     // set the execution time to be able to serve big files in a single chunk
     ini_set("max_execution_time", 240);
     if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) {
         // because the fiter was turned off - a manual check for deleted entries must be done.
         die;
     } else {
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
             $version = $this->getRequestParameter("version", null);
             $width = $this->getRequestParameter("width", -1);
             $height = $this->getRequestParameter("height", -1);
             $crop_provider = $this->getRequestParameter("crop_provider", null);
             $bgcolor = $this->getRequestParameter("bgcolor", "ffffff");
             $type = $this->getRequestParameter("type", 1);
             $quality = $this->getRequestParameter("quality", 0);
             $src_x = $this->getRequestParameter("src_x", 0);
             $src_y = $this->getRequestParameter("src_y", 0);
             $src_w = $this->getRequestParameter("src_w", 0);
             $src_h = $this->getRequestParameter("src_h", 0);
             $vid_sec = $this->getRequestParameter("vid_sec", -1);
             $vid_slice = $this->getRequestParameter("vid_slice", -1);
             $vid_slices = $this->getRequestParameter("vid_slices", -1);
             if ($width == -1 && $height == -1) {
                 $width = 640;
                 $height = 480;
             } 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;
                     }
                 }
             }
             $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);
             kFile::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0);
         }
     }
     $audio_only = $this->getRequestParameter("audio_only");
     // milliseconds
     $flavor = $this->getRequestParameter("flavor", 1);
     //
     $flavor_param_id = $this->getRequestParameter("flavor_param_id", null);
     //
     $streamer = $this->getRequestParameter("streamer");
     //
     if (substr($streamer, 0, 4) == "rtmp") {
         // the fms may add .mp4 to the end of the url
         $streamer = "rtmp";
     }
     // grab seek_from_bytes parameter and normalize url
     $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1);
     $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request);
     if ($seek_from_bytes <= 0) {
         $seek_from_bytes = -1;
     }
     // grab seek_from parameter and normalize url
     $seek_from = $this->getRequestParameter("seek_from", -1);
     $request = str_replace("/seek_from/{$seek_from}", "", $request);
     if ($seek_from <= 0) {
         $seek_from = -1;
     }
     $this->dump_from_byte = 0;
     // reset accurate seek from timestamp
     $seek_from_timestamp = -1;
     // backward compatibility
     if ($flavor === "0") {
         // for edit version
         $flavor = "edit";
     }
     if ($flavor === "1" || $flavor === 1) {
         // for play version
         $flavor = null;
     }
     // when flavor is null, we will get a default flavor
     if ($flavor == "edit") {
         $flavorAsset = flavorAssetPeer::retrieveBestEditByEntryId($entry->getId());
     } elseif (!is_null($flavor)) {
         $flavorAsset = flavorAssetPeer::retrieveById($flavor);
         // when specific asset was request, we don't validate its tags
         if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) {
             $flavorAsset = null;
         }
         // we will throw an error later
     } elseif (is_null($flavor) && !is_null($flavor_param_id)) {
         $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entry->getId(), $flavor_param_id);
         if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             $flavorAsset = null;
         }
         // we will throw an error later
     } else {
         if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
             $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId());
         } else {
             $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($entry->getId());
         }
         if (!$flavorAsset) {
             $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB);
             if (count($flavorAssets) > 0) {
                 $flavorAsset = $flavorAssets[0];
             }
         }
     }
     if (is_null($flavorAsset)) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::file_exists($syncKey, false)) {
         $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     } else {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if (is_null($fileSync)) {
             KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
             KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         $this->redirect($remoteUrl);
     }
     $flv_wrapper = new myFlvHandler($path);
     $isFlv = $flv_wrapper->isFlv();
     // scrubbing is not allowed within mp4 files
     if (!$isFlv) {
         $seek_from = $seek_from_bytes = -1;
     }
     if ($seek_from !== -1 && $seek_from !== 0) {
         if ($audio_only === '0') {
             // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
         } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
             $audio_only = true;
         }
         list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only);
         list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only);
         $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte;
     }
     // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath();
     $extStorageUrl = $entry->getExtStorageUrl();
     if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) {
         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
         if ($seek_from_timestamp == -1) {
             $seek_from_timestamp = $seek_from;
         }
         $request_host = parse_url($extStorageUrl, PHP_URL_HOST);
         $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl);
         $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000);
         header("Location: {$akamai_url}");
         die;
     } elseif ($extStorageUrl) {
         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
         if ($seek_from_timestamp == -1) {
             $seek_from_timestamp = $seek_from;
         }
         $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000);
         header("Location: {$extStorageUrl}");
         die;
     }
     // use headers to detect cdn
     $cdn_name = "";
     $via_header = @$_SERVER["HTTP_VIA"];
     if (strpos($via_header, "llnw.net") !== false) {
         $cdn_name = "limelight";
     } else {
         if (strpos($via_header, "akamai") !== false) {
             $cdn_name = "akamai";
         } else {
             if (strpos($via_header, "Level3") !== false) {
                 $cdn_name = "level3";
             }
         }
     }
     // setting file extension - first trying frrom flavor asset
     $ext = $flavorAsset->getFileExt();
     // if failed, set extension according to file type (isFlv)
     if (!$ext) {
         $ext = $isFlv ? "flv" : "mp4";
     }
     $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0";
     // dont check for rtmp / and for an already redirect url
     if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
         // check security using ks
         $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer);
         if ($securyEntryHelper->shouldPreview()) {
             $this->checkForPreview($securyEntryHelper, $clip_to);
         } else {
             $securyEntryHelper->validateForPlay($entry, $ks_str);
         }
     } else {
         // if needs security check using cdn authentication mechanism
         // for now assume this is a cdn request and don't check for security
     }
     // use limelight mediavault if either security policy requires it or if we're trying to seek within the video
     if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) {
         // we have three options:
         // arrived through limelight mediavault url - the url is secured
         // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url
         // didnt use limelight - enforce ks
         // the cdns are configured to authenticate request for /s/....
         // check if we're already in a redirected secure link using the "/s/" prefix
         $secure_request = substr($request, 0, 3) == "/s/";
         if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) {
             // request was validated by cdn let it through
         } else {
             // extract ks
             $ks_str = $this->getRequestParameter("ks", "");
             if ($entry->getSecurityPolicy()) {
                 if (!$ks_str) {
                     $this->logMessage("flvclipper - no KS");
                     die;
                 }
                 $ks = kSessionUtils::crackKs($ks_str);
                 if (!$ks) {
                     $this->logMessage("flvclipper - invalid ks [{$ks_str}]");
                     die;
                 }
                 $matched_privs = $ks->verifyPrivileges("sview", $entry_id);
                 $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]");
                 if (!$matched_privs) {
                     $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]");
                     die;
                 }
             }
             if ($cdn_name == "limelight") {
                 $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension;
                 $secret = kConf::get("limelight_madiavault_password");
                 $expire = "&e=" . (time() + 120);
                 $ll_url .= $expire;
                 $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}";
                 $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs;
                 //header("Location: $ll_url");
                 $this->redirect($ll_url);
             } else {
                 if ($cdn_name == "level3") {
                     $level3_url = $request . $flv_extension;
                     if ($entry->getSecurityPolicy()) {
                         $level3_url = "/s{$level3_url}";
                         // set expire time in GMT hence the date("Z") offset
                         $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30);
                         $level3_url .= $expire;
                         $secret = kConf::get("level3_authentication_key");
                         $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20);
                         $level3_url .= "&h={$hash}";
                     }
                     $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}";
                     header("Location: {$level3_url}");
                     die;
                 } else {
                     if ($cdn_name == "akamai") {
                         $akamai_url = $request . $flv_extension;
                         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
                         if ($seek_from_timestamp == -1) {
                             $seek_from_timestamp = $seek_from;
                         }
                         $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000);
                         header("Location: {$akamai_url}");
                         die;
                     }
                 }
             }
             // a seek request without a supporting cdn - we need to send the answer from our server
             if ($seek_from_bytes !== -1 && $via_header === null) {
                 $this->dump_from_byte = $seek_from_bytes;
             }
         }
     }
     // always add the file suffix to the request (needed for scrubbing by some cdns,
     // and also breaks without extension on some corporate antivirus).
     // we add the the novar paramter since a leaving a trailing "?" will be trimmed
     // and then the /seek_from request will result in another url which level3
     // will try to refetch from the origin
     // note that for streamer we dont add the file extension
     if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
         // a seek request without a supporting cdn - we need to send the answer from our server
         if ($seek_from_bytes !== -1 && $via_header === null) {
             $request .= "/seek_from_bytes/{$seek_from_bytes}";
         }
         requestUtils::sendCdnHeaders("flv", 0);
         header("Location: {$request}" . $flv_extension);
         die;
     }
     // mp4
     if (!$isFlv) {
         kFile::dumpFile($path);
     }
     $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning");
     if ($audio_only === '0') {
         // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
     } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
         $audio_only = true;
     }
     //$start = microtime(true);
     list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only);
     $metadata_size = $flv_wrapper->getMetadataSize($audio_only);
     $this->from_byte = $from_byte;
     $this->to_byte = $to_byte;
     //$end1 = microtime(true);
     //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
     //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]");
     $data_offset = $metadata_size + myFlvHandler::getHeaderSize();
     // if we're returning a partial file adjust the total size:
     // substract the metadata and bytes which are not delivered
     if ($this->dump_from_byte >= $data_offset && !$audio_only) {
         $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset);
     }
     $this->total_length = $data_offset + $bytes;
     //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die;
     $this->cuepoint_time = 0;
     $this->cuepoint_pos = 0;
     if ($streamer == "chunked" && $clip_to != 2147483647) {
         $this->cuepoint_time = $clip_to - 1;
         $this->cuepoint_pos = $cuepoint_pos;
         $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE;
     }
     //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
     $this->flv_wrapper = $flv_wrapper;
     $this->audio_only = $audio_only;
     try {
         Propel::close();
     } catch (Exception $e) {
         $this->logMessage("flvclipperAction: error closing db {$e}");
     }
     return sfView::SUCCESS;
 }
示例#25
0
 protected function duplicateTemplateEntry($conversionProfileId)
 {
     $dbEntry = null;
     $conversionProfile = myPartnerUtils::getConversionProfile2ForPartner($this->getPartnerId(), $conversionProfileId);
     if ($conversionProfile && $conversionProfile->getDefaultEntryId()) {
         $templateEntry = entryPeer::retrieveByPKNoFilter($conversionProfile->getDefaultEntryId(), null, false);
         if ($templateEntry) {
             $dbEntry = $templateEntry->copyTemplate(true);
         }
     }
     return $dbEntry;
 }
示例#26
0
 protected function initEntry()
 {
     $this->entryId = $this->getRequestParameter("entryId", null);
     // look for a valid token
     $expiry = $this->getRequestParameter("expiry");
     if ($expiry && $expiry <= time()) {
         KExternalErrors::dieError(KExternalErrors::EXPIRED_TOKEN);
     }
     $urlToken = $this->getRequestParameter("kt");
     if ($urlToken) {
         if ($_SERVER["REQUEST_METHOD"] != "GET" || !self::validateKalturaToken($_SERVER["REQUEST_URI"], $urlToken)) {
             KExternalErrors::dieError(KExternalErrors::INVALID_TOKEN);
         }
     }
     // initalize the context
     $ksStr = $this->getRequestParameter("ks");
     if ($ksStr && !$urlToken) {
         try {
             kCurrentContext::initKsPartnerUser($ksStr);
         } catch (Exception $ex) {
             KExternalErrors::dieError(KExternalErrors::INVALID_KS);
         }
     } else {
         $this->entry = kCurrentContext::initPartnerByEntryId($this->entryId);
         if (!$this->entry || $this->entry->getStatus() == entryStatus::DELETED) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     // no need for any further check if a token was used
     if ($urlToken) {
         return;
     }
     // enforce entitlement
     kEntitlementUtils::initEntitlementEnforcement();
     if (!$this->entry) {
         $this->entry = entryPeer::retrieveByPKNoFilter($this->entryId);
         if (!$this->entry || $this->entry->getStatus() == entryStatus::DELETED) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     } else {
         if (!kEntitlementUtils::isEntryEntitled($this->entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     myPartnerUtils::blockInactivePartner($this->entry->getPartnerId());
     // enforce access control
     $base64Referrer = $this->getRequestParameter("referrer");
     $hashes = $this->getRequestParameter("hashes");
     $keyValueHashes = array();
     if ($hashes) {
         $hashes = urldecode($hashes);
         $hashes = explode(",", $hashes);
         foreach ($hashes as $keyValueHashString) {
             list($key, $value) = explode('=', $keyValueHashString);
             $keyValueHashes[$key] = $value;
         }
     }
     // replace space in the base64 string with + as space is invalid in base64 strings and caused
     // by symfony calling str_parse to replace + with spaces.
     // this happens only with params passed in the url path and not the query strings. specifically the ~ char at
     // a columns divided by 3 causes this issue (e.g. http://www.xyzw.com/~xxx)
     //replace also any - with + and _ with /
     $referrer = base64_decode(str_replace(array('-', '_', ' '), array('+', '/', '+'), $base64Referrer));
     if (!is_string($referrer)) {
         $referrer = "";
     }
     // base64_decode can return binary data
     $this->secureEntryHelper = new KSecureEntryHelper($this->entry, $ksStr, $referrer, ContextType::PLAY, $keyValueHashes);
     if ($this->secureEntryHelper->shouldPreview()) {
         $previewLengthInMsecs = $this->secureEntryHelper->getPreviewLength() * 1000;
         $entryLengthInMsecs = $this->entry->getLengthInMsecs();
         if ($previewLengthInMsecs < $entryLengthInMsecs) {
             $this->deliveryAttributes->setClipTo($previewLengthInMsecs);
         }
     } else {
         $this->secureEntryHelper->validateForPlay();
     }
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENTITLEMENT, $this->entry->getPartnerId()) || $this->secureEntryHelper->hasRules()) {
         $this->forceUrlTokenization = true;
     }
 }
 /**
  * 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)
 }
示例#28
0
 public static function checkForPendingLiveClips(entry $entry)
 {
     if ($entry->getSource() != EntrySourceType::RECORDED_LIVE) {
         KalturaLog::notice("Entry [" . $entry->getId() . "] is not a recorded live");
         return;
     }
     $liveEntry = entryPeer::retrieveByPKNoFilter($entry->getRootEntryId());
     if (!$liveEntry || $liveEntry->getStatus() == entryStatus::DELETED || !$liveEntry instanceof LiveEntry) {
         KalturaLog::notice("Entry root [" . $entry->getRootEntryId() . "] is not a valid live entry");
         return;
     }
     /* @var $liveEntry LiveEntry */
     $pendingMediaEntries = $liveEntry->getAttachedPendingMediaEntries();
     foreach ($pendingMediaEntries as $pendingMediaEntry) {
         /* @var $pendingMediaEntry kPendingMediaEntry */
         if ($pendingMediaEntry->getRequiredDuration() && $pendingMediaEntry->getRequiredDuration() > $entry->getLengthInMsecs()) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] required duration [" . $pendingMediaEntry->getRequiredDuration() . "] while entry duration [" . $entry->getLengthInMsecs() . "] is too short");
             continue;
         }
         $liveEntry->dettachPendingMediaEntry($pendingMediaEntry->getEntryId());
         $pendingEntry = entryPeer::retrieveByPK($pendingMediaEntry->getEntryId());
         if (!$pendingEntry) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] not found");
             continue;
         }
         $sourceAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
         if (!$sourceAsset) {
             $sourceAssets = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId());
             $sourceAsset = array_pop($sourceAssets);
         }
         if (!$sourceAsset) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] source asset not found");
             continue;
         }
         /* @var $sourceAsset flavorAsset */
         $operationAttributes = new kClipAttributes();
         $operationAttributes->setOffset($pendingMediaEntry->getOffset());
         $operationAttributes->setDuration($pendingMediaEntry->getDuration());
         $targetAsset = assetPeer::retrieveOriginalByEntryId($pendingMediaEntry->getEntryId());
         if (!$targetAsset) {
             $targetAsset = kFlowHelper::createOriginalFlavorAsset($entry->getPartnerId(), $pendingMediaEntry->getEntryId());
         }
         $targetAsset->setFileExt($sourceAsset->getFileExt());
         $targetAsset->save();
         $sourceSyncKey = $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         $targetSyncKey = $targetAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         kFileSyncUtils::createSyncFileLinkForKey($targetSyncKey, $sourceSyncKey);
         $errDescription = '';
         kBusinessPreConvertDL::decideAddEntryFlavor(null, $pendingMediaEntry->getEntryId(), $operationAttributes->getAssetParamsId(), $errDescription, $targetAsset->getId(), array($operationAttributes));
     }
     $liveEntry->save();
 }
示例#29
0
文件: entry.php 项目: AdiTal/server
 public function getRootEntryId($deep = false)
 {
     $rootEntryId = $this->getFromCustomData("rootEntryId", null, null);
     if (is_null($rootEntryId)) {
         return $this->getId();
     }
     if (!$deep) {
         return $rootEntryId;
     }
     $rootEntry = entryPeer::retrieveByPKNoFilter($rootEntryId);
     if ($rootEntry) {
         $rootEntryId = $rootEntry->getRootEntryId($deep);
     }
     return $rootEntryId;
 }
 protected function archiveFile($file_name)
 {
     KalturaLog::debug("Archiving file [" . $file_name . "]");
     $id = self::getEntryIdFromFileName($file_name);
     $entry = entryPeer::retrieveByPKNoFilter($id);
     $entry->setArchiveExtension(pathinfo($file_name, PATHINFO_EXTENSION));
     $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ARCHIVE);
     $file_sync = kFileSyncUtils::createSyncFileForKey($sync_key, false, false);
     $target = kFileSyncUtils::getLocalFilePathForKey($sync_key, false);
     KalturaLog::debug("Archiving file [" . $file_name . "] to [" . $target . "]}");
     // MOVE - there is no need to copy because we the ConvCommand will include the file path anyway
     if ($file_name == $target) {
         KalturaLog::debug("File [{$file_name}] already archived");
         return $file_sync;
     }
     // there is a file in the archive but the current file does not exist
     if (!file_exists($file_name) && file_exists($target)) {
         return $file_sync;
     }
     if (file_exists($target) && filesize($target) == filesize($file_name)) {
         return $file_sync;
     } else {
         // move to archive and override if exists
         myContentStorage::moveFile($file_name, $target, true, false);
     }
     kFileSyncUtils::markLocalFileSyncAsReady($sync_key);
     return $file_sync;
 }