/** * return the flavor params the best fits the fileFormat for a given partner_id * * @param int $partnerId * @param string $fileFormat * @return FlavorParams */ public static function getFlavorParamsFromFileFormat($partnerId, $fileFormat, $ignoreSourceTag = true) { $defaultCriteria = assetParamsPeer::getCriteriaFilter()->getFilter(); $defaultCriteria->remove(assetParamsPeer::PARTNER_ID); // assetParamsPeer::allowAccessToPartner0AndPartnerX($partnerId); // the flavor params can be from partner 0 too $c = new Criteria(); $c->addAnd(assetParamsPeer::PARTNER_ID, array($partnerId, 0), Criteria::IN); // $c->add ( assetParamsPeer::FORMAT , $fileFormat ); $possible_flavor_params = assetParamsPeer::doSelect($c); myPartnerUtils::resetPartnerFilter('assetParams'); $best_fp = null; foreach ($possible_flavor_params as $fp) { if ($fileFormat != $fp->getFormat()) { continue; } if ($ignoreSourceTag && $fp->hasTag(flavorParams::TAG_SOURCE)) { continue; } if (!$best_fp) { $best_fp = $fp; } if ($fp->getPartnerId() != $partnerId) { continue; } // same format for the partner $best_fp = $fp; break; } // if not fount any - choose the first flavor params from the list if (!$best_fp) { $best_fp = $possible_flavor_params[0]; } return $best_fp; }
public function initService($serviceId, $serviceName, $actionName) { parent::initService($serviceId, $serviceName, $actionName); // KAsyncValidateLiveMediaServers lists all live entries of all partners if ($this->getPartnerId() == Partner::BATCH_PARTNER_ID && $actionName == 'list') { myPartnerUtils::resetPartnerFilter('entry'); } if (in_array($this->getPartner()->getStatus(), array(Partner::PARTNER_STATUS_CONTENT_BLOCK, Partner::PARTNER_STATUS_FULL_BLOCK))) { throw new kCoreException("Partner blocked", kCoreException::PARTNER_BLOCKED); } }
public function initService($serviceId, $serviceName, $actionName) { parent::initService($serviceId, $serviceName, $actionName); // Play-Server and Media-Server list entries of all partners // This is not too expensive as the requests are cached conditionally and performed on sphinx $allowedSystemPartners = array(Partner::MEDIA_SERVER_PARTNER_ID, Partner::PLAY_SERVER_PARTNER_ID); if (in_array($this->getPartnerId(), $allowedSystemPartners) && $actionName == 'list') { myPartnerUtils::resetPartnerFilter('entry'); } else { $this->applyPartnerFilterForClass('CuePoint'); } // when session is not admin, allow access to user entries only if (!$this->getKs() || !$this->getKs()->isAdmin()) { KalturaCriterion::enableTag(KalturaCriterion::TAG_USER_SESSION); CuePointPeer::setUserContentOnly(true); } if (!CuePointPlugin::isAllowedPartner($this->getPartnerId())) { throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, CuePointPlugin::PLUGIN_NAME); } }
/** * @return string path value * @param entry $entry * @param string $xslStr */ protected function getPathValue(entry $entry, $xslStr) { // 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', $entry->getPartnerId(), true); $mrss = null; $mrssParams = new kMrssParameters(); $mrssParams->setStatuses(array(flavorAsset::ASSET_STATUS_READY, flavorAsset::ASSET_STATUS_EXPORTING)); $mrss = kMrssManager::getEntryMrssXml($entry, $mrss, $mrssParams); $mrssStr = $mrss->asXML(); // 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 = trim($xslStr); if (!$xslObj->loadXML($xslStr)) { KalturaLog::err('Error loading XSL'); return null; } $proc = new XSLTProcessor(); $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions()); $proc->importStyleSheet($xslObj); $resultXmlObj = $proc->transformToDoc($mrssObj); if (!$resultXmlObj) { KalturaLog::err('Error transforming XML for entry id [' . $entry->getId() . ']'); return null; } /* DEBUG logs KalturaLog::log('entry mrss = '.$mrssStr); KalturaLog::log('profile xslt = '.$xslStr); */ KalturaLog::debug('Result XML: ' . $resultXmlObj->saveXML()); $xpath = new DOMXPath($resultXmlObj); $fieldElement = $xpath->query("//path_value")->item(0); if (!$fieldElement) { KalturaLog::err('Cannot find element <path_value> in XML'); return null; } $fieldValue = $fieldElement->nodeValue; return $fieldValue; }
public function getEntryMrssDoc(EntryDistribution $entryDistribution) { $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId()); // 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'); entryPeer::addPartnerToCriteria($this->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); $mrssObj = new DOMDocument(); if (!$mrssObj->loadXML($mrssStr)) { throw new Exception('Entry mrss xml is not valid'); } return $mrssObj; }
public function __construct($feedId, $feedProcessingKey = null, $ks = null) { $this->feedProcessingKey = $feedProcessingKey; myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3; $microTimeStart = microtime(true); KalturaLog::info("syndicationFeedRenderer- initialize "); $this->syndicationFeedDb = $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($feedId); if (!$syndicationFeedDB) { throw new Exception("Feed Id not found"); } kCurrentContext::initKsPartnerUser($ks, $syndicationFeedDB->getPartnerId(), ''); kPermissionManager::init(); kEntitlementUtils::initEntitlementEnforcement($syndicationFeedDB->getPartnerId(), $syndicationFeedDB->getEnforceEntitlement()); if (!is_null($syndicationFeedDB->getPrivacyContext()) && $syndicationFeedDB->getPrivacyContext() != '') { kEntitlementUtils::setPrivacyContextSearch($syndicationFeedDB->getPrivacyContext()); } $tmpSyndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType()); $tmpSyndicationFeed->fromObject($syndicationFeedDB); $this->syndicationFeed = $tmpSyndicationFeed; // add partner to default criteria myPartnerUtils::addPartnerToCriteria('category', $this->syndicationFeed->partnerId, true); myPartnerUtils::addPartnerToCriteria('asset', $this->syndicationFeed->partnerId, true); myPartnerUtils::resetPartnerFilter('entry'); $this->baseCriteria = clone entryPeer::getDefaultCriteriaFilter(); $startDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::START_DATE, time(), Criteria::LESS_EQUAL); $startDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::START_DATE, null)); $this->baseCriteria->addAnd($startDateCriterion); $endDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::END_DATE, time(), Criteria::GREATER_EQUAL); $endDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::END_DATE, null)); $this->baseCriteria->addAnd($endDateCriterion); $this->baseCriteria->addAnd(entryPeer::PARTNER_ID, $this->syndicationFeed->partnerId); $this->baseCriteria->addAnd(entryPeer::STATUS, entryStatus::READY); $this->baseCriteria->addAnd(entryPeer::TYPE, array(entryType::MEDIA_CLIP, entryType::MIX), Criteria::IN); $this->baseCriteria->addAnd(entryPeer::MODERATION_STATUS, array(entry::ENTRY_MODERATION_STATUS_REJECTED, entry::ENTRY_MODERATION_STATUS_PENDING_MODERATION), Criteria::NOT_IN); if ($this->syndicationFeed->playlistId) { $this->entryFilters = myPlaylistUtils::getPlaylistFiltersById($this->syndicationFeed->playlistId); foreach ($this->entryFilters as $entryFilter) { $entryFilter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE); // partner scope already attached } $playlist = entryPeer::retrieveByPK($this->syndicationFeed->playlistId); if ($playlist) { if ($playlist->getMediaType() != entry::ENTRY_MEDIA_TYPE_XML) { $this->staticPlaylist = true; $this->staticPlaylistEntriesIdsOrder = explode(',', $playlist->getDataContent()); } } } else { $this->entryFilters = array(); } $microTimeEnd = microtime(true); KalturaLog::info("syndicationFeedRenderer- initialization done [" . ($microTimeEnd - $microTimeStart) . "]"); }
/** * Serves the file content * * @action serveByFlavorParamsId * @param string $entryId Document entry id * @param string $flavorParamsId Flavor params id * @param bool $forceProxy force to get the content without redirect * @return file * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND */ public function serveByFlavorParamsIdAction($entryId, $flavorParamsId = null, $forceProxy = false) { // temporary workaround for getting the referrer from a url with the format ....&forceProxy/true/referrer/... $referrer = null; if (isset($_GET["forceProxy"]) && kString::beginsWith($_GET["forceProxy"], "true/referrer/")) { $referrer = substr($_GET["forceProxy"], strlen("true/referrer/")); $referrer = base64_decode($referrer); } KalturaResponseCacher::disableCache(); myPartnerUtils::resetPartnerFilter('entry'); $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != entryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $ksObj = $this->getKs(); $ks = $ksObj ? $ksObj->getOriginalString() : null; $securyEntryHelper = new KSecureEntryHelper($dbEntry, $ks, $referrer, ContextType::DOWNLOAD); $securyEntryHelper->validateForDownload(); $flavorAsset = null; if ($flavorParamsId) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorParamsId); } } else { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId); } } if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId); } $fileName = $dbEntry->getName() . '.' . $flavorAsset->getFileExt(); return $this->serveFlavorAsset($flavorAsset, $fileName, $forceProxy); }
/** * Get a session using user email and password * * @param string $puserId * @param string $loginEmail * @param string $password * @param int $partnerId * @param int $expiry * @param string $privileges * * @return string KS * * @throws KalturaErrors::USER_NOT_FOUND * @thrown KalturaErrors::LOGIN_RETRIES_EXCEEDED * @thrown KalturaErrors::LOGIN_BLOCKED * @thrown KalturaErrors::PASSWORD_EXPIRED * @thrown KalturaErrors::INVALID_PARTNER_ID * @thrown KalturaErrors::INTERNAL_SERVERL_ERROR * @throws KalturaErrors::USER_IS_BLOCKED */ protected function loginImpl($puserId, $loginEmail, $password, $partnerId = null, $expiry = 86400, $privileges = '*') { KalturaResponseCacher::disableCache(); myPartnerUtils::resetPartnerFilter('kuser'); kuserPeer::setUseCriteriaFilter(true); // if a KS of a specific partner is used, don't allow logging in to a different partner if ($this->getPartnerId() && $partnerId && $this->getPartnerId() != $partnerId) { throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $partnerId); } if ($loginEmail && !$partnerId) { $this->validateApiAccessControlByEmail($loginEmail); } try { if ($loginEmail) { $user = UserLoginDataPeer::userLoginByEmail($loginEmail, $password, $partnerId); } else { $user = kuserPeer::userLogin($puserId, $password, $partnerId); } } catch (kUserException $e) { $code = $e->getCode(); if ($code == kUserException::LOGIN_DATA_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::USER_NOT_FOUND); } if ($code == kUserException::USER_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::USER_NOT_FOUND); } else { if ($code == kUserException::LOGIN_RETRIES_EXCEEDED) { throw new KalturaAPIException(KalturaErrors::LOGIN_RETRIES_EXCEEDED); } else { if ($code == kUserException::LOGIN_BLOCKED) { throw new KalturaAPIException(KalturaErrors::LOGIN_BLOCKED); } else { if ($code == kUserException::PASSWORD_EXPIRED) { throw new KalturaAPIException(KalturaErrors::PASSWORD_EXPIRED); } else { if ($code == kUserException::WRONG_PASSWORD) { throw new KalturaAPIException(KalturaErrors::USER_WRONG_PASSWORD); } else { if ($code == kUserException::USER_IS_BLOCKED) { throw new KalturaAPIException(KalturaErrors::USER_IS_BLOCKED); } } } } } } throw new $e(); } if (!$user) { throw new KalturaAPIException(KalturaErrors::LOGIN_DATA_NOT_FOUND); } if ($partnerId && $user->getPartnerId() != $partnerId || $this->getPartnerId() && !$partnerId && $user->getPartnerId() != $this->getPartnerId()) { throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $partnerId); } $partner = PartnerPeer::retrieveByPK($user->getPartnerId()); if (!$partner || $partner->getStatus() == Partner::PARTNER_STATUS_FULL_BLOCK) { throw new KalturaAPIException(KalturaErrors::INVALID_PARTNER_ID, $user->getPartnerId()); } $ks = null; $admin = $user->getIsAdmin() ? KalturaSessionType::ADMIN : KalturaSessionType::USER; // create a ks for this admin_kuser as if entered the admin_secret using the API kSessionUtils::createKSessionNoValidations($partner->getId(), $user->getPuserId(), $ks, $expiry, $admin, "", $privileges); return $ks; }
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; }
<?php require_once dirname(__FILE__) . '/../bootstrap.php'; $f = fopen("php://stdin", "r"); $count = 0; $sphinxMgr = new kSphinxSearchManager(); $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $connection = Propel::getConnection(); while ($s = trim(fgets($f))) { $sep = strpos($s, "\t") ? "\t" : " "; list($entryId, $plays, $views) = explode($sep, $s); myPartnerUtils::resetAllFilters(); myPartnerUtils::resetPartnerFilter('entry'); $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { KalturaLog::err('Couldn\'t find entry [' . $entryId . ']'); continue; } if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $plays = $views; } if ($entry->getViews() != $views || $entry->getPlays() != $plays) { $entry->setViews($views); $entry->setPlays($plays); try { // Update last_played_at date/time to NOW $now = time(); $entry->setLastPlayedAt($now); // update entry without setting the updated at