/** * This action delivers entry-related data, based on the user's context: access control, restriction, playback format and storage information. * @action getContextData * @param string $entryId * @param KalturaEntryContextDataParams $contextDataParams * @return KalturaEntryContextDataResult */ public function getContextData($entryId, KalturaEntryContextDataParams $contextDataParams) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $asset = null; if ($contextDataParams->flavorAssetId) { $asset = assetPeer::retrieveById($contextDataParams->flavorAssetId); if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $contextDataParams->flavorAssetId); } } $contextDataHelper = new kContextDataHelper($dbEntry, $this->getPartner(), $asset); if ($dbEntry->getAccessControl() && $dbEntry->getAccessControl()->hasRules()) { $accessControlScope = $dbEntry->getAccessControl()->getScope(); } else { $accessControlScope = new accessControlScope(); } $contextDataParams->toObject($accessControlScope); $contextDataHelper->buildContextDataResult($accessControlScope, $contextDataParams->flavorTags, $contextDataParams->streamerType, $contextDataParams->mediaProtocol); if ($contextDataHelper->getDisableCache()) { KalturaResponseCacher::disableCache(); } $result = new KalturaEntryContextDataResult(); $result->fromObject($contextDataHelper->getContextDataResult()); $result->flavorAssets = KalturaFlavorAssetArray::fromDbArray($contextDataHelper->getAllowedFlavorAssets()); $result->streamerType = $contextDataHelper->getStreamerType(); $result->mediaProtocol = $contextDataHelper->getMediaProtocol(); $result->storageProfilesXML = $contextDataHelper->getStorageProfilesXML(); $result->isAdmin = $contextDataHelper->getIsAdmin(); $parentEntryId = $dbEntry->getParentEntryId(); if ($parentEntryId) { $dbEntry = $dbEntry->getParentEntry(); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $parentEntryId); } } $result->isScheduledNow = $dbEntry->isScheduledNow($contextDataParams->time); $result->pluginData = new KalturaPluginDataArray(); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaEntryContextDataContributor'); foreach ($pluginInstances as $pluginInstance) { $pluginInstance->contributeToEntryContextDataResult($entryId, $contextDataParams, $result); } return $result; }
/** * This action delivers entry-related data, based on the user's context: access control, restriction, playback format and storage information. * @action getContextData * @param string $entryId * @param KalturaEntryContextDataParams $contextDataParams * @return KalturaEntryContextDataResult */ public function getContextData($entryId, KalturaEntryContextDataParams $contextDataParams) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $ks = $this->getKs(); $isAdmin = false; if ($ks) { $isAdmin = $ks->isAdmin(); } $accessControl = $dbEntry->getAccessControl(); /* @var $accessControl accessControl */ $result = new KalturaEntryContextDataResult(); $result->isAdmin = $isAdmin; $result->isScheduledNow = $dbEntry->isScheduledNow($contextDataParams->time); if ($dbEntry->getStartDate() && abs($dbEntry->getStartDate(null) - time()) <= 86400 || $dbEntry->getEndDate() && abs($dbEntry->getEndDate(null) - time()) <= 86400) { KalturaResponseCacher::setConditionalCacheExpiry(600); } if ($accessControl && $accessControl->hasRules()) { $disableCache = true; if (kConf::hasMap("optimized_playback")) { $partnerId = $accessControl->getPartnerId(); $optimizedPlayback = kConf::getMap("optimized_playback"); if (array_key_exists($partnerId, $optimizedPlayback)) { $params = $optimizedPlayback[$partnerId]; if (array_key_exists('cache_kdp_acccess_control', $params) && $params['cache_kdp_acccess_control']) { $disableCache = false; } } } $accessControlScope = $accessControl->getScope(); $contextDataParams->toObject($accessControlScope); $accessControlScope->setEntryId($entryId); $result->isAdmin = $accessControlScope->getKs() && $accessControlScope->getKs()->isAdmin(); $dbResult = new kEntryContextDataResult(); if ($accessControl->applyContext($dbResult) && $disableCache) { KalturaResponseCacher::disableCache(); } $result->fromObject($dbResult); } $partner = PartnerPeer::retrieveByPK($dbEntry->getPartnerId()); if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_REMOTE_STORAGE_DELIVERY_PRIORITY, $dbEntry->getPartnerId()) && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { if (is_null($contextDataParams->flavorAssetId)) { if ($contextDataParams->flavorTags) { $assets = assetPeer::retrieveReadyByEntryIdAndTag($entryId, $contextDataParams->flavorTags); $asset = reset($assets); } else { $asset = assetPeer::retrieveBestPlayByEntryId($entryId); } if (!$asset) { throw new KalturaAPIException(KalturaErrors::NO_FLAVORS_FOUND, $entryId); } } else { $asset = assetPeer::retrieveByPK($contextDataParams->flavorAssetId); if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $contextDataParams->flavorAssetId); } } if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $entryId); } $assetSyncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $fileSyncs = kFileSyncUtils::getAllReadyExternalFileSyncsForKey($assetSyncKey); $storageProfilesXML = new SimpleXMLElement("<StorageProfiles/>"); foreach ($fileSyncs as $fileSync) { $storageProfileId = $fileSync->getDc(); $storageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$storageProfile->getDeliveryRmpBaseUrl() && (!$contextDataParams->streamerType || $contextDataParams->streamerType == StorageProfile::PLAY_FORMAT_AUTO)) { $contextDataParams->streamerType = StorageProfile::PLAY_FORMAT_HTTP; $contextDataParams->mediaProtocol = StorageProfile::PLAY_FORMAT_HTTP; } $storageProfileXML = $storageProfilesXML->addChild("StorageProfile"); $storageProfileXML->addAttribute("storageProfileId", $storageProfileId); $storageProfileXML->addChild("Name", $storageProfile->getName()); $storageProfileXML->addChild("SystemName", $storageProfile->getSystemName()); } $result->storageProfilesXML = $storageProfilesXML->saveXML(); } if ($contextDataParams->streamerType && $contextDataParams->streamerType != StorageProfile::PLAY_FORMAT_AUTO) { $result->streamerType = $contextDataParams->streamerType; $result->mediaProtocol = $contextDataParams->mediaProtocol ? $contextDataParams->mediaProtocol : $contextDataParams->streamerType; } else { $result->streamerType = $this->getPartner()->getStreamerType(); if (!$result->streamerType) { $result->streamerType = StorageProfile::PLAY_FORMAT_HTTP; } $result->mediaProtocol = $this->getPartner()->getMediaProtocol(); if (!$result->mediaProtocol) { $result->mediaProtocol = StorageProfile::PLAY_FORMAT_HTTP; } } return $result; }
/** * This action delivers entry-related data, based on the user's context: access control, restriction, playback format and storage information. * @action getContextData * @param string $entryId * @param KalturaEntryContextDataParams $contextDataParams * @return KalturaEntryContextDataResult */ public function getContextData($entryId, KalturaEntryContextDataParams $contextDataParams) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } if ($dbEntry->getStatus() != entryStatus::READY) { // the purpose of this is to solve a case in which a player attempts to play a non-ready entry, // and the request becomes cached for a long time, preventing playback even after the entry // becomes ready kApiCache::setExpiry(60); } $asset = null; if ($contextDataParams->flavorAssetId) { $asset = assetPeer::retrieveById($contextDataParams->flavorAssetId); if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $contextDataParams->flavorAssetId); } } $contextDataHelper = new kContextDataHelper($dbEntry, $this->getPartner(), $asset); if ($dbEntry->getAccessControl() && $dbEntry->getAccessControl()->hasRules()) { $accessControlScope = $dbEntry->getAccessControl()->getScope(); } else { $accessControlScope = new accessControlScope(); } $contextDataParams->toObject($accessControlScope); $contextDataHelper->buildContextDataResult($accessControlScope, $contextDataParams->flavorTags, $contextDataParams->streamerType, $contextDataParams->mediaProtocol); if ($contextDataHelper->getDisableCache()) { KalturaResponseCacher::disableCache(); } $result = new KalturaEntryContextDataResult(); $result->fromObject($contextDataHelper->getContextDataResult()); $result->flavorAssets = KalturaFlavorAssetArray::fromDbArray($contextDataHelper->getAllowedFlavorAssets()); $result->streamerType = $contextDataHelper->getStreamerType(); $result->mediaProtocol = $contextDataHelper->getMediaProtocol(); $result->storageProfilesXML = $contextDataHelper->getStorageProfilesXML(); $result->isAdmin = $contextDataHelper->getIsAdmin(); $parentEntryId = $dbEntry->getParentEntryId(); if ($parentEntryId) { $dbEntry = $dbEntry->getParentEntry(); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $parentEntryId); } } $result->isScheduledNow = $dbEntry->isScheduledNow($contextDataParams->time); if (!$result->isScheduledNow && $this->getKs()) { // in case the sview is defined in the ks simulate schedule now true to allow player to pass verification if ($this->getKs()->verifyPrivileges(ks::PRIVILEGE_VIEW, ks::PRIVILEGE_WILDCARD) || $this->getKs()->verifyPrivileges(ks::PRIVILEGE_VIEW, $entryId)) { $result->isScheduledNow = true; } } $result->pluginData = new KalturaPluginDataArray(); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaEntryContextDataContributor'); foreach ($pluginInstances as $pluginInstance) { $pluginInstance->contributeToEntryContextDataResult($dbEntry, $contextDataParams, $result); } return $result; }