Ejemplo n.º 1
0
 public function getAllCategoriesIds($includePending = false)
 {
     if (!$includePending) {
         $categoriesEntry = categoryEntryPeer::retrieveActiveByEntryId($this->getId());
     } else {
         $categoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($this->getId());
     }
     $categoriesIds = array();
     foreach ($categoriesEntry as $categoryEntry) {
         $categoriesIds[] = $categoryEntry->getCategoryId();
     }
     return $categoriesIds;
 }
Ejemplo n.º 2
0
 /**
  * Index CategoryEntry by Id
  * 
  * @action index
  * @param string $entryId
  * @param int $categoryId
  * @param bool $shouldUpdate
  * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY
  * @return int
  */
 function indexAction($entryId, $categoryId, $shouldUpdate = true)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE);
     }
     $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId);
     if (!$dbCategoryEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY);
     }
     if (!$shouldUpdate) {
         $dbCategoryEntry->setUpdatedAt(time());
         $dbCategoryEntry->save();
         return $dbCategoryEntry->getIntId();
     }
     $dbCategoryEntry->reSetCategoryFullIds();
     $dbCategoryEntry->save();
     $entry = entryPeer::retrieveByPK($dbCategoryEntry->getEntryId());
     if ($entry) {
         $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entryId);
         $categoriesIds = array();
         foreach ($categoryEntries as $categoryEntry) {
             $categoriesIds[] = $categoryEntry->getCategoryId();
         }
         $categories = categoryPeer::retrieveByPKs($categoriesIds);
         $isCategoriesModified = false;
         $categoriesFullName = array();
         foreach ($categories as $category) {
             if ($category->getPrivacyContexts() == null) {
                 $categoriesFullName[] = $category->getFullName();
                 $isCategoriesModified = true;
             }
         }
         $entry->setCategories(implode(',', $categoriesFullName));
         categoryEntryPeer::syncEntriesCategories($entry, $isCategoriesModified);
         $entry->save();
     }
     return $dbCategoryEntry->getId();
 }
 /**
  * Returns true if kuser or current kuser is entitled to entryId
  * @param entry $entry
  * @param int $kuser
  * @return bool
  */
 public static function isEntryEntitled(entry $entry, $kuserId = null)
 {
     $ks = ks::fromSecureString(kCurrentContext::$ks);
     // entry is entitled when entitlement is disable
     // for actions with no ks - need to check if partner have default entitlement feature enable.
     if (!self::getEntitlementEnforcement() && $ks) {
         KalturaLog::debug('Entry entitled: entitlement disabled');
         return true;
     }
     $partner = $entry->getPartner();
     if (!$ks && !$partner->getDefaultEntitlementEnforcement()) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: no ks and default is with no enforcement');
         return true;
     }
     if ($ks && $ks->isWidgetSession() && $ks->getDisableEntitlementForEntry() == $entry->getId()) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: widget session that disble entitlement for this entry');
         return true;
     }
     $allCategoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($entry->getId());
     $categories = array();
     foreach ($allCategoriesEntry as $categoryEntry) {
         $categories[] = $categoryEntry->getCategoryId();
     }
     //if entry doesn't belong to any category.
     $categories[] = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $categories, Criteria::IN);
     $privacy = array(PrivacyType::ALL);
     if ($ks && !$ks->isWidgetSession()) {
         $privacy[] = PrivacyType::AUTHENTICATED_USERS;
     }
     $crit = $c->getNewCriterion(categoryPeer::PRIVACY, $privacy, Criteria::IN);
     $ksPrivacyContexts = null;
     // entry that doesn't belong to any category is public
     //when ks is not provided - the entry is still public (for example - download action)
     $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entry->getId());
     if (!count($categoryEntries) && !$ks) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category');
         return true;
     }
     if ($ks) {
         $ksPrivacyContexts = $ks->getPrivacyContext();
         if (!$ksPrivacyContexts || trim($ksPrivacyContexts) == '') {
             $ksPrivacyContexts = self::DEFAULT_CONTEXT . $partner->getId();
             if (!count($allCategoriesEntry)) {
                 // entry that doesn't belong to any category is public
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category and privacy context on the ks is not set');
                 return true;
             }
         }
         $c->add(categoryPeer::PRIVACY_CONTEXTS, $ksPrivacyContexts, KalturaCriteria::IN_LIKE);
         if (!$kuserId) {
             $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
             $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid, true);
             if ($kuser) {
                 $kuserId = $kuser->getId();
             }
         }
         if ($kuserId) {
             // kuser is set on the entry as creator or uploader
             if ($kuserId != '' && $entry->getKuserId() == $kuserId) {
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->kuserId or entry->creatorKuserId [' . $kuserId . ']');
                 return true;
             }
             // kuser is set on the entry entitled users edit or publish
             $entitledKusers = array_merge(explode(',', $entry->getEntitledKusersEdit()), explode(',', $entry->getEntitledKusersPublish()));
             if (in_array($kuserId, $entitledKusers)) {
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->entitledKusersEdit or entry->entitledKusersPublish');
                 return true;
             }
         }
         // kuser is set on the category as member
         // this ugly code is temporery - since we have a bug in sphinxCriteria::getAllCriterionFields
         if ($kuserId) {
             $membersCrit = $c->getNewCriterion(categoryPeer::MEMBERS, $kuserId, Criteria::LIKE);
             $membersCrit->addOr($crit);
             $crit = $membersCrit;
         }
     } else {
         //no ks = set privacy context to default.
         $c->add(categoryPeer::PRIVACY_CONTEXTS, array(self::DEFAULT_CONTEXT . $partner->getId()), KalturaCriteria::IN_LIKE);
     }
     $c->addAnd($crit);
     //remove default FORCED criteria since categories that has display in search = public - doesn't mean that all of their entries are public
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $category = categoryPeer::doSelectOne($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     if ($category) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is a member of this category or category privacy is set to public of authenticated');
         return true;
     }
     KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] not entitled');
     return false;
 }
 private function setEntryOnCategory(category $category, $entry = null)
 {
     if (is_null($this->entryCategoriesAddedIds)) {
         $categoriesEntries = categoryEntryPeer::retrieveActiveByEntryId($this->getEntryId());
         $categoriesIds = array();
         foreach ($categoriesEntries as $categroyEntry) {
             //cannot get directly the full ids - since it might not be updated.
             if ($categroyEntry->getCategoryId() != $this->getCategoryId()) {
                 $categoriesIds[] = $categroyEntry->getCategoryId();
             }
         }
         $categoriesAdded = categoryPeer::retrieveByPKs($categoriesIds);
         $entryCategoriesAddedIds = array();
         foreach ($categoriesAdded as $categoryAdded) {
             $fullIds = explode(categoryPeer::CATEGORY_SEPARATOR, $categoryAdded->getFullIds());
             $entryCategoriesAddedIds = array_merge($entryCategoriesAddedIds, $fullIds);
         }
         $this->entryCategoriesAddedIds = $entryCategoriesAddedIds;
     }
     $category->incrementEntriesCount(1, $this->entryCategoriesAddedIds);
     $category->incrementDirectEntriesCount();
     //if was pending - decrease pending entries count!
     if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) {
         $category->decrementPendingEntriesCount();
     }
     $category->save();
     //only categories with no context are saved on entry - this is only for Backward compatible
     if ($entry && !categoryEntryPeer::getSkipSave() && (trim($category->getPrivacyContexts()) == '' || $category->getPrivacyContexts() == null)) {
         $categories = array();
         if (trim($entry->getCategories()) != '') {
             $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories());
         }
         $categories[] = $category->getFullName();
         $categoriesIds = array();
         if (trim($entry->getCategoriesIds()) != '') {
             $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds());
         }
         $categoriesIds[] = $category->getId();
         $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories));
         $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds));
         $entry->justSave();
     }
     return $entry;
 }
Ejemplo n.º 5
0
 /**
  * @param entry $entry
  * @param SimpleXMLElement $mrss
  * @param kMrssParameters $mrssParams
  * @params string $features
  * @return SimpleXMLElement
  */
 public static function getEntryMrssXml(entry $entry, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null, $features = null)
 {
     $instanceKey = self::generateInstanceKey($entry->getId(), $mrssParams, $features);
     if (is_null($mrss)) {
         $mrss = self::getInstanceFromPool($instanceKey);
         if ($mrss) {
             return $mrss;
         }
         $encoding = 'UTF-8';
         if ($mrssParams && !is_null($mrssParams->getEncoding())) {
             $encoding = $mrssParams->getEncoding();
         }
         if ($encoding) {
             $mrss = new SimpleXMLElement('<?xml version="1.0" encoding="' . $encoding . '"?><item/>');
         } else {
             $mrss = new SimpleXMLElement('<item/>');
         }
     }
     $mrss->addChild('entryId', $entry->getId());
     if ($entry->getReferenceID()) {
         $mrss->addChild('referenceID', self::stringToSafeXml($entry->getReferenceID()));
     }
     $mrss->addChild('createdAt', $entry->getCreatedAt(null));
     $mrss->addChild('updatedAt', $entry->getUpdatedAt(null));
     $mrss->addChild('title', self::stringToSafeXml($entry->getName()));
     if ($mrssParams && !is_null($mrssParams->getLink())) {
         $mrss->addChild('link', $mrssParams->getLink() . $entry->getId());
     }
     $mrss->addChild('type', $entry->getType());
     $mrss->addChild('licenseType', $entry->getLicenseType());
     $mrss->addChild('userId', $entry->getPuserId());
     $mrss->addChild('name', self::stringToSafeXml($entry->getName()));
     $mrss->addChild('status', self::stringToSafeXml($entry->getStatus()));
     $mrss->addChild('description', self::stringToSafeXml($entry->getDescription()));
     $thumbnailUrl = $mrss->addChild('thumbnailUrl');
     $thumbnailUrl->addAttribute('url', $entry->getThumbnailUrl());
     if (trim($entry->getTags(), " \r\n\t")) {
         $tags = $mrss->addChild('tags');
         foreach (explode(',', $entry->getTags()) as $tag) {
             $tags->addChild('tag', self::stringToSafeXml($tag));
         }
     }
     $categories = explode(',', $entry->getCategories());
     if (count($features) && in_array(ObjectFeatureType::CATEGORY_ENTRIES, $features)) {
         $partner = PartnerPeer::retrieveByPK(kCurrentContext::getCurrentPartnerId());
         $partnerEntitlement = $partner->getDefaultEntitlementEnforcement();
         kEntitlementUtils::initEntitlementEnforcement($partner->getId(), false);
         $categories = array();
         $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entry->getId());
         $categoryIds = array();
         foreach ($categoryEntries as $categoryEntry) {
             $categoryIds[] = $categoryEntry->getCategoryId();
         }
         $entryCats = categoryPeer::retrieveByPKs($categoryIds);
         foreach ($entryCats as $entryCat) {
             $categories[] = $entryCat->getFullName();
         }
         if ($partnerEntitlement) {
             kEntitlementUtils::initEntitlementEnforcement($partner->getId(), true);
         }
         $keyToDelete = array_search(ObjectFeatureType::CATEGORY_ENTRIES, $features);
         unset($features[$keyToDelete]);
     }
     foreach ($categories as $category) {
         $category = trim($category);
         if ($category) {
             $categoryNode = $mrss->addChild('category', self::stringToSafeXml($category));
             if (strrpos($category, '>') > 0) {
                 $categoryNode->addAttribute('name', self::stringToSafeXml(substr($category, strrpos($category, '>') + 1)));
             } else {
                 $categoryNode->addAttribute('name', self::stringToSafeXml($category));
             }
         }
     }
     $mrss->addChild('partnerData', self::stringToSafeXml($entry->getPartnerData()));
     if ($entry->getAccessControlId()) {
         $mrss->addChild('accessControlId', $entry->getAccessControlId());
     }
     if ($entry->getConversionProfileId()) {
         $mrss->addChild('conversionProfileId', $entry->getConversionProfileId());
     }
     if ($entry->getStartDate(null)) {
         $mrss->addChild('startDate', $entry->getStartDate(null));
     }
     if ($entry->getEndDate(null)) {
         $mrss->addChild('endDate', $entry->getEndDate(null));
     }
     switch ($entry->getType()) {
         case entryType::MEDIA_CLIP:
             self::appendMediaEntryMrss($entry, $mrss);
             break;
         case entryType::MIX:
             self::appendMixEntryMrss($entry, $mrss);
             break;
         case entryType::PLAYLIST:
             self::appendPlaylistEntryMrss($entry, $mrss);
             break;
         case entryType::DATA:
             self::appendDataEntryMrss($entry, $mrss);
             break;
         case entryType::LIVE_STREAM:
             self::appendLiveStreamEntryMrss($entry, $mrss);
             break;
         default:
             break;
     }
     $assetsStatuses = array(asset::ASSET_STATUS_READY);
     if ($mrssParams && $mrssParams->getStatuses()) {
         $assetsStatuses = $mrssParams->getStatuses();
     }
     $assets = assetPeer::retrieveReadyByEntryId($entry->getId(), null, $assetsStatuses);
     foreach ($assets as $asset) {
         if ($mrssParams && !is_null($mrssParams->getFilterByFlavorParams()) && $asset->getFlavorParamsId() != $mrssParams->getFilterByFlavorParams()) {
             continue;
         }
         if ($asset instanceof flavorAsset) {
             self::appendFlavorAssetMrss($asset, $mrss, $mrssParams);
         }
         if ($asset instanceof thumbAsset) {
             self::appendThumbAssetMrss($asset, $mrss);
         }
     }
     $mrssContributors = self::getMrssContributors();
     if (count($mrssContributors)) {
         foreach ($mrssContributors as $mrssContributor) {
             try {
                 if (!count($features) || in_array($mrssContributor->getObjectFeatureType(), $features)) {
                     $mrssContributor->contribute($entry, $mrss, $mrssParams);
                 }
             } catch (kCoreException $ex) {
                 KalturaLog::err("Unable to add MRSS element for contributor [" . get_class($mrssContributor) . "] message [" . $ex->getMessage() . "]");
             }
         }
     }
     if ($mrssParams && $mrssParams->getIncludePlayerTag()) {
         $uiconfId = !is_null($mrssParams->getPlayerUiconfId()) ? '/ui_conf_id/' . $mrssParams->getPlayerUiconfId() : '';
         $playerUrl = kConf::get('apphome_url') . '/kwidget/wid/_' . $entry->getPartnerId() . '/entry_id/' . $entry->getId() . '/ui_conf' . ($uiconfId ? "/{$uiconfId}" : '');
         $player = $mrss->addChild('player');
         $player->addAttribute('url', $playerUrl);
     }
     if ($mrssParams && $mrssParams->getItemXpathsToExtend()) {
         self::addExtendingItemsToMrss($mrss, $mrssParams);
     }
     self::addInstanceToPool($instanceKey, $mrss);
     return $mrss;
 }
Ejemplo n.º 6
0
 public function objectCopied(BaseObject $fromObject, BaseObject $toObject)
 {
     if ($fromObject instanceof asset) {
         self::mapIds('asset', $fromObject->getId(), $toObject->getId());
         $flavorParamsId = self::getMappedId('assetParams', $fromObject->getFlavorParamsId());
         if ($flavorParamsId) {
             $toObject->setFlavorParamsId($flavorParamsId);
             $toObject->save();
         }
     } elseif ($fromObject instanceof assetParams) {
         self::mapIds('assetParams', $fromObject->getId(), $toObject->getId());
     } elseif ($fromObject instanceof assetParamsOutput) {
         self::mapIds('assetParamsOutput', $fromObject->getId(), $toObject->getId());
         $flavorParamsId = self::getMappedId('assetParams', $fromObject->getFlavorParamsId());
         if ($flavorParamsId) {
             $toObject->setFlavorParamsId($flavorParamsId);
             $toObject->save();
         }
     } else {
         self::mapIds(get_class($fromObject), $fromObject->getId(), $toObject->getId());
     }
     if ($fromObject instanceof uiConf) {
         $this->uiConfCopied($fromObject, $toObject);
     }
     if ($fromObject instanceof category && $fromObject->getParentId()) {
         $parentId = self::getMappedId('category', $fromObject->getParentId());
         if ($parentId) {
             $toObject->setParentId($parentId);
             $toObject->save();
         }
     }
     if ($fromObject instanceof entry) {
         $conversionProfileId = self::getMappedId('conversionProfile2', $fromObject->getConversionProfileId());
         if ($conversionProfileId) {
             $toObject->setConversionProfileId($conversionProfileId);
             $toObject->save();
         }
         $accessControlId = self::getMappedId('accessControl', $fromObject->getAccessControlId());
         if ($accessControlId) {
             $toObject->setAccessControlId($accessControlId);
             $toObject->save();
         }
         if ($toObject->getPartnerId() == $fromObject->getPartnerId()) {
             $categoryEntriesObjects = categoryEntryPeer::retrieveActiveByEntryId($fromObject->getId());
             $categoryIds = array();
             foreach ($categoryEntriesObjects as $categoryEntryObject) {
                 /* @var $categoryEntry categoryEntry */
                 $categoryIds[] = $categoryEntryObject->getCategoryId();
             }
             if (count($categoryIds)) {
                 $categories = categoryPeer::retrieveByPKs($categoryIds);
                 //which will return only the entiteled ones
                 foreach ($categories as $category) {
                     /* @var $category category */
                     $categoryEntry = new categoryEntry();
                     $categoryEntry->setEntryId($toObject->getId());
                     $categoryEntry->setCategoryId($category->getId());
                     $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
                     $categoryEntry->setPartnerId($toObject->getPartnerId());
                     $categoryEntry->save();
                 }
             }
         }
     }
     return true;
 }