Exemple #1
0
 function getEntryResultFromApi()
 {
     global $wgKalturaApiFeatures;
     global $wgKalturaEnableProxyData;
     // Check if the API supports entryRedirect feature
     $supportsEntryRedirect = isset($wgKalturaApiFeatures['entryRedirect']) ? $wgKalturaApiFeatures['entryRedirect'] : false;
     $client = $this->client->getClient();
     // define resultObject prior to try catch call
     $resultObject = array();
     try {
         // NOTE this should probably be wrapped in a service class
         $params = array();
         // If no cache flag is on, ask the client to get request without cache
         if ($this->request->noCache) {
             $client->addParam($params, "nocache", true);
         }
         $namedMultiRequest = new KalturaNamedMultiRequest($client, $params);
         $filter = new KalturaBaseEntryFilter();
         if (!$this->request->getEntryId() && $this->request->getReferenceId()) {
             $filter->referenceIdEqual = $this->request->getReferenceId();
         } else {
             if ($supportsEntryRedirect && $this->request->getFlashVars('disableEntryRedirect') !== true) {
                 $filter->redirectFromEntryId = $this->request->getEntryId();
             } else {
                 $filter->idEqual = $this->request->getEntryId();
             }
         }
         if ($wgKalturaEnableProxyData && $this->request->getFlashVars("proxyData")) {
             $filter->freeText = urlencode(json_encode($this->request->getFlashVars("proxyData")));
         }
         $baseEntryIdx = $namedMultiRequest->addNamedRequest('meta', 'baseEntry', 'list', array('filter' => $filter));
         // Get entryId from the baseEntry request response
         $entryId = '{' . $baseEntryIdx . ':result:objects:0:id}';
         // ------- Disabled AC from iframe. -----
         // Access control NOTE: kaltura does not use http header spelling of Referer instead kaltura uses: "referrer"
         $filter = $this->getACFilter();
         $params = array("contextDataParams" => $filter, "entryId" => $entryId);
         $namedMultiRequest->addNamedRequest('contextData', 'baseEntry', 'getContextData', $params);
         // Entry Custom Metadata
         // Always get custom metadata for now
         //if( $this->uiconf->getPlayerConfig(false, 'requiredMetadataFields') ) {
         $filter = new KalturaMetadataFilter();
         $filter->orderBy = KalturaMetadataOrderBy::CREATED_AT_ASC;
         $filter->objectIdEqual = $entryId;
         $filter->metadataObjectTypeEqual = KalturaMetadataObjectType::ENTRY;
         // Check if metadataProfileId is defined
         $metadataProfileId = $this->uiconf->getPlayerConfig(false, 'metadataProfileId');
         if ($metadataProfileId) {
             $filter->metadataProfileIdEqual = $metadataProfileId;
         }
         $metadataPager = new KalturaFilterPager();
         $metadataPager->pageSize = 1;
         $params = array('filter' => $filter, 'metadataPager', $metadataPager);
         $namedMultiRequest->addNamedRequest('entryMeta', 'metadata_metadata', 'list', $params);
         //}
         // Entry Cue Points
         // Always get Cue Points for now
         //if( $this->uiconf->getPlayerConfig(false, 'getCuePointsData') !== false ) {
         $filter = new KalturaCuePointFilter();
         $filter->orderBy = KalturaAdCuePointOrderBy::START_TIME_ASC;
         $filter->entryIdEqual = $entryId;
         $params = array('filter' => $filter);
         $namedMultiRequest->addNamedRequest('entryCuePoints', "cuepoint_cuepoint", "list", $params);
         //}
         // Get the result object as a combination of baseResult and multiRequest
         $resultObject = $namedMultiRequest->doQueue();
         //print_r($resultObject);exit();
         $this->responseHeaders = $client->getResponseHeaders();
     } catch (Exception $e) {
         // Update the Exception and pass it upward
         throw new Exception(KALTURA_GENERIC_SERVER_ERROR . "\n" . $e->getMessage());
         return array();
     }
     if (is_object($resultObject['meta']) && isset($resultObject['meta']->objects) && count($resultObject['meta']->objects)) {
         $this->request->set('entry_id', $resultObject['meta']->objects[0]->id);
         $resultObject['meta'] = $resultObject['meta']->objects[0];
     } else {
         $resultObject['meta'] = array();
     }
     // Check that the ks was valid on the first response ( flavors )
     if (is_array($resultObject['meta']) && isset($resultObject['meta']['code']) && $resultObject['meta']['code'] == 'INVALID_KS') {
         $this->error = 'Error invalid KS';
         return array();
     }
     // Set partner id from entry meta data
     if (is_object($resultObject['meta']) && isset($resultObject['meta']->partnerId)) {
         $this->partnerId = $resultObject['meta']->partnerId;
     }
     // Convert entryMeta to entryMeta XML
     if (isset($resultObject['entryMeta']) && isset($resultObject['entryMeta']->objects[0]) && isset($resultObject['entryMeta']->objects[0]->xml)) {
         $resultObject['entryMeta'] = $this->xmlToArray(new SimpleXMLElement($resultObject['entryMeta']->objects[0]->xml));
     }
     // Add Cue Point data. Also check for 'code' error
     if (isset($resultObject['entryCuePoints']) && is_object($resultObject['entryCuePoints']) && $resultObject['entryCuePoints']->totalCount > 0) {
         $resultObject['entryCuePoints'] = $resultObject['entryCuePoints']->objects;
     }
     // Check access control and flavorAssets and throw an exception if not allowed:
     if (isset($resultObject['contextData'])) {
         $acStatus = $this->isAccessControlAllowed($resultObject);
         if ($acStatus !== true) {
             $this->error = $acStatus;
         }
     }
     return $resultObject;
 }
Exemple #2
0
 /**
  * Filters the playlist object based on AC for current user request, purges cache for page. 
  */
 function filterPlaylistEntriesAc()
 {
     // build multi-request:
     $client = $this->client->getClient();
     $client->startMultiRequest();
     $namedMultiRequest = new KalturaNamedMultiRequest($client);
     // get AC filter from entry class:
     $filter = $this->entry->getACFilter();
     $aPerPlaylist = array();
     $resultObject = array();
     $acList = array();
     foreach ($this->playlistObject as $playlistId => $playlistObject) {
         foreach ($playlistObject['items'] as $entry) {
             // collect ac ids
             if (!isset($acList[$entry->accessControlId])) {
                 $acList[$entry->accessControlId] = $entry->id;
             }
         }
     }
     foreach ($acList as $acId => $entryId) {
         $params = array("contextDataParams" => $filter, "entryId" => $entryId);
         $namedMultiRequest->addNamedRequest($acId, 'baseEntry', 'getContextData', $params);
     }
     $acResultObject = $namedMultiRequest->doQueue();
     // update the response headers
     $this->responseHeaders = $client->getResponseHeaders();
     foreach ($this->playlistObject as $playlistId => $playlistObject) {
         // update entry list:
         $contentEntryList = '';
         $coma = '';
         foreach ($playlistObject['items'] as $entryInx => $entry) {
             //echo " looking at: " . $entry->id . ' ac:' . $entry->accessControlId . " ";
             if (isset($entry->accessControlId)) {
                 $acStatus = $this->entry->isAccessControlAllowed(array('contextData' => $acResultObject[$entry->accessControlId]));
                 if ($acStatus !== true) {
                     //echo "remove: " . $entryInx . "\n";
                     // remove from playlist
                     unset($this->playlistObject[$playlistId]['items'][$entryInx]);
                     continue;
                 }
             }
             //echo "keep: " . $entryInx . "\n";
             $contentEntryList .= $coma . $entryId;
             $coma = ',';
         }
         // re-index items:
         $this->playlistObject[$playlistId]['items'] = array_values($this->playlistObject[$playlistId]['items']);
         // update content list
         $this->playlistObject[$playlistId]['content'] = $contentEntryList;
     }
 }
 function getEntryResult()
 {
     $client = $this->getClient();
     // define resultObject prior to try catch call
     $resultObject = array();
     try {
         // NOTE this should probably be wrapped in a service class
         $kparams = array();
         // If no cache flag is on, ask the client to get request without cache
         if ($this->noCache) {
             $client->addParam($kparams, "nocache", true);
             $default_params = $kparams;
         } else {
             $default_params = array();
         }
         $namedMultiRequest = new KalturaNamedMultiRequest($client, $default_params);
         // Added support for passing referenceId instead of entryId
         $useReferenceId = false;
         if (!$this->urlParameters['entry_id'] && isset($this->urlParameters['flashvars']['referenceId'])) {
             // Use baseEntry->listByReferenceId
             $useReferenceId = true;
             $refIndex = $namedMultiRequest->addNamedRequest('referenceResult', 'baseEntry', 'listByReferenceId', array('refId' => $this->urlParameters['flashvars']['referenceId']));
             $entryIdParamValue = '{' . $refIndex . ':result:objects:0:id}';
         } else {
             // Use normal baseEntry->get
             $namedMultiRequest->addNamedRequest('meta', 'baseEntry', 'get', array('entryId' => $this->urlParameters['entry_id']));
             // Set entry id param value for other requests
             $entryIdParamValue = $this->urlParameters['entry_id'];
         }
         // Set entry parameter
         $entryParam = array('entryId' => $entryIdParamValue);
         // getByEntryId is deprecated - Use list instead
         $filter = new KalturaAssetFilter();
         $filter->entryIdEqual = $entryIdParamValue;
         $params = array('filter' => $filter);
         // Flavors:
         $namedMultiRequest->addNamedRequest('flavors', 'flavorAsset', 'list', $params);
         // Access control NOTE: kaltura does not use http header spelling of Referer instead kaltura uses: "referrer"
         $params = array_merge($entryParam, array("contextDataParams" => array('referrer' => $this->getReferer())));
         $namedMultiRequest->addNamedRequest('accessControl', 'baseEntry', 'getContextData', $params);
         // Entry Custom Metadata
         // Always get custom metadata for now
         //if( $this->getPlayerConfig(false, 'requiredMetadataFields') ) {
         $filter = new KalturaMetadataFilter();
         $filter->orderBy = KalturaMetadataOrderBy::CREATED_AT_ASC;
         $filter->objectIdEqual = $entryIdParamValue;
         $filter->metadataObjectTypeEqual = KalturaMetadataObjectType::ENTRY;
         $metadataPager = new KalturaFilterPager();
         $metadataPager->pageSize = 1;
         $params = array('filter' => $filter, 'metadataPager', $metadataPager);
         $namedMultiRequest->addNamedRequest('entryMeta', 'metadata_metadata', 'list', $params);
         //}
         // Entry Cue Points
         if ($this->getPlayerConfig(false, 'getCuePointsData') !== false) {
             $filter = new KalturaCuePointFilter();
             $filter->orderBy = KalturaAdCuePointOrderBy::START_TIME_ASC;
             $filter->entryIdEqual = $entryIdParamValue;
             $params = array('filter' => $filter);
             $namedMultiRequest->addNamedRequest('entryCuePoints', "cuepoint_cuepoint", "list", $params);
         }
         // Get the result object as a combination of baseResult and multiRequest
         $resultObject = $namedMultiRequest->doQueue();
         // merge in the base result object:
         $resultObject = array_merge($this->getBaseResultObject(), $resultObject);
         // If flavors are fetched, list contains a secondary 'objects' array
         if (isset($resultObject['flavors']->objects)) {
             $resultObject['flavors'] = $resultObject['flavors']->objects;
         }
         // Check if the server cached the result by search for "cached-dispatcher" in the request headers
         // If not, do not cache the request (Used for Access control cache issue)
         $requestCached = in_array("X-Kaltura: cached-dispatcher", $client->getResponseHeaders());
         if ($requestCached === false) {
             $this->noCache = true;
         }
     } catch (Exception $e) {
         // Update the Exception and pass it upward
         throw new Exception(KALTURA_GENERIC_SERVER_ERROR . "\n" . $e->getMessage());
         return array();
     }
     if ($useReferenceId) {
         if ($resultObject['referenceResult'] && $resultObject['referenceResult']->objects) {
             $this->urlParameters['entry_id'] = $resultObject['referenceResult']->objects[0]->id;
             $resultObject['meta'] = $resultObject['referenceResult']->objects[0];
         } else {
             $resultObject['meta'] = array();
         }
     }
     // Check that the ks was valid on the first response ( flavors )
     if (is_array($resultObject['meta']) && isset($resultObject['meta']['code']) && $resultObject['meta']['code'] == 'INVALID_KS') {
         $this->error = 'Error invalid KS';
         return array();
     }
     // Convert entryMeta to entryMeta XML
     if (isset($resultObject['entryMeta']) && isset($resultObject['entryMeta']->objects[0]) && isset($resultObject['entryMeta']->objects[0]->xml)) {
         $resultObject['entryMeta'] = $this->xmlToArray(new SimpleXMLElement($resultObject['entryMeta']->objects[0]->xml));
     }
     // Add uiConf file to our object
     if ($this->uiConfFile) {
         $resultObject['uiconf_id'] = $this->urlParameters['uiconf_id'];
         $resultObject['uiConf'] = $this->uiConfFile;
     }
     // Set the partner id
     if ($resultObject['meta']->partnerId) {
         $this->partnerId = $resultObject['meta']->partnerId;
         $resultObject['partner_id'] = $resultObject['meta']->partnerId;
     }
     // Add Cue Point data. Also check for 'code' error
     if (isset($resultObject['entryCuePoints']) && is_object($resultObject['entryCuePoints']) && $resultObject['entryCuePoints']->totalCount > 0) {
         $resultObject['entryCuePoints'] = $resultObject['entryCuePoints']->objects;
     }
     // Check access control and throw an exception if not allowed:
     if (isset($resultObject['accessControl'])) {
         $acStatus = $this->isAccessControlAllowed($resultObject);
         if ($acStatus !== true) {
             $this->error = $acStatus;
         }
     }
     return $resultObject;
 }