public function getInstance($interface) { if ($this instanceof $interface) { return $this; } $plugin = KalturaPluginManager::getPluginInstance(MetadataPlugin::getPluginName()); if ($plugin) { return $plugin->getInstance($interface); } return null; }
public function imgAction() { $pluginName = $this->_getParam('plugin'); $imgName = $this->_getParam('img'); $plugin = KalturaPluginManager::getPluginInstance($pluginName); if (!$plugin || !$plugin instanceof IKalturaApplicationImages) { $message = "Plugin [{$pluginName}] is not an application images plugin"; throw new Infra_Exception($message, Infra_Exception::ERROR_CODE_MISSING_PLUGIN); } $imgPath = $plugin->getImagePath($imgName); if (!file_exists($imgPath)) { $message = "File [{$imgPath}] not found"; throw new Infra_Exception($message, Infra_Exception::ERROR_CODE_MISSING_PLUGIN_FILE); } $this->getHelper('layout')->disableLayout(); $this->getHelper('viewRenderer')->setNoRender(); header('Content-type: image/jpg'); readfile($imgPath); }
private function loadChildTypes(KalturaTypeReflector $typeReflector) { if (isset($this->_types[$typeReflector->getType()])) { return; } if (in_array($typeReflector->getType(), $this->_typesToIgnore)) { return; } $this->addType($typeReflector); $cacheTypesClassMap = false; if (!$this->_typesClassMap) { $this->initClassMap(); $this->_typesClassMap = $this->_classMap; $cacheTypesClassMap = true; } foreach ($this->_typesClassMap as $class => $path) { if (strpos($class, 'Kaltura') === 0 && strpos($class, '_') === false && strpos($path, 'api') !== false) { $reflector = new ReflectionClass($class); if ($reflector->isSubclassOf('KalturaObject') && $reflector->isSubclassOf($typeReflector->getType())) { $classTypeReflector = KalturaTypeReflectorCacher::get($class); if (!$classTypeReflector) { throw new Exception("Type [{$class}] reflector not found"); } $pluginName = $classTypeReflector->getPlugin(); if ($pluginName && !KalturaPluginManager::getPluginInstance($pluginName)) { unset($this->_typesClassMap[$class]); continue; } if ($classTypeReflector) { $this->loadTypesRecursive($classTypeReflector); } } } else { unset($this->_typesClassMap[$class]); } } if ($cacheTypesClassMap) { file_put_contents($this->getTypesClassMapPath(), serialize($this->_typesClassMap)); } }
/** * @param DOMElement $item * @param array $captionAssets * @param array $remoteCaptionFileUrls */ public function setCaptionAsset($item, array $captionAssets) { if (is_array($captionAssets)) { foreach ($captionAssets as $captionAsset) { /* @var $additionalAsset asset */ $assetType = $captionAsset->getType(); switch ($assetType) { case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION): /* @var $captionPlugin CaptionPlugin */ $captionPlugin = KalturaPluginManager::getPluginInstance(CaptionPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $captionPlugin->contributeCaptionAssets($captionAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $captionDom = $dummyDom->getElementsByTagName('subTitle'); $captionDom = $this->doc->importNode($captionDom->item(0), true); $captionDom = $item->appendChild($captionDom); break; case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT): /* @var $attachmentPlugin AttachmentPlugin */ $attachmentPlugin = KalturaPluginManager::getPluginInstance(AttachmentPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $attachmentPlugin->contributeAttachmentAssets($captionAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $attachmentDom = $dummyDom->getElementsByTagName('attachment'); $attachmentDom = $this->doc->importNode($attachmentDom->item(0), true); $attachmentDom = $item->appendChild($attachmentDom); break; } } } }
/** * Check which server plugins should be used * @param KalturaCrossKalturaDistributionProfile $distributionProfile * @throws Exception */ protected function initPlugins(KalturaCrossKalturaDistributionProfile $distributionProfile) { // check if should distribute caption assets $this->distributeCaptions = false; if ($distributionProfile->distributeCaptions == true) { if (class_exists('CaptionPlugin') && class_exists('KalturaCaptionClientPlugin') && KalturaPluginManager::getPluginInstance(CaptionPlugin::getPluginName())) { $this->distributeCaptions = true; } else { throw new Exception('Missing CaptionPlugin'); } } // check if should distribute cue points $this->distributeCuePoints = false; if ($distributionProfile->distributeCuePoints == true) { if (class_exists('CuePointPlugin') && class_exists('KalturaCuePointClientPlugin') && KalturaPluginManager::getPluginInstance(CuePointPlugin::getPluginName())) { $this->distributeCuePoints = true; } else { throw new Exception('Missing CuePointPlugin'); } } }
/** * @param array $values */ public function addItem(array $values, flavorAsset $flavorAsset = null, thumbAsset $thumbAsset = null, array $additionalAssets = null) { $item = $this->item->cloneNode(true); $channelNode = $this->xpath->query('/rss/channel', $item)->item(0); $channelNode->appendChild($item); $pubDate = date('c', $values[TVComDistributionField::ITEM_PUB_DATE]); $expDate = date('c', $values[TVComDistributionField::ITEM_EXP_DATE]); $node = $this->setNodeValue('guid', $values[TVComDistributionField::GUID_ID], $item); $node = $this->setNodeValue('pubDate', $pubDate, $item); $node = $this->setNodeValue('expDate', $expDate, $item); $node = $this->setNodeValue('link', $values[TVComDistributionField::ITEM_LINK], $item); $node = $this->setNodeValue('media:group/media:title', $values[TVComDistributionField::MEDIA_TITLE], $item); $node = $this->setNodeValue('media:group/media:description', $values[TVComDistributionField::MEDIA_DESCRIPTION], $item); $node = $this->setNodeValue('media:group/media:keywords', $values[TVComDistributionField::MEDIA_KEYWORDS], $item); $node = $this->setNodeValue('media:group/media:copyright', $values[TVComDistributionField::MEDIA_COPYRIGHT], $item); $node = $this->setNodeValue('media:group/media:rating', $values[TVComDistributionField::MEDIA_RATING], $item); $node = $this->setNodeValue('media:group/media:restriction/@relationship', $values[TVComDistributionField::MEDIA_RESTRICTION_TYPE], $item); $node = $this->setNodeValue('media:group/media:restriction', $values[TVComDistributionField::MEDIA_RESTRICTION_COUNTRIES], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:show-tmsid\']', $values[TVComDistributionField::MEDIA_CATEGORY_SHOW_TMSID], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:show-tmsid\']/@label', $values[TVComDistributionField::MEDIA_CATEGORY_SHOW_TMSID_LABEL], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:episode-tmsid\']', $values[TVComDistributionField::MEDIA_CATEGORY_EPISODE_TMSID], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:episode-tmsid\']/@label', $values[TVComDistributionField::MEDIA_CATEGORY_EPISODE_TMSID_LABEL], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:episodetype\']', $values[TVComDistributionField::MEDIA_CATEGORY_EPISODE_TYPE], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:original_air_date\']', $values[TVComDistributionField::MEDIA_CATEGORY_ORIGINAL_AIR_DATE], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:video_format\']', $values[TVComDistributionField::MEDIA_CATEGORY_VIDEO_FORMAT], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:season_number\']', $values[TVComDistributionField::MEDIA_CATEGORY_SEASON_NUMBER], $item); $node = $this->setNodeValue('media:group/media:category[@scheme=\'urn:tvcom:episode_number\']', $values[TVComDistributionField::MEDIA_CATEGORY_EPISODE_NUMBER], $item); $dcTerms = "start={$pubDate}; end={$expDate}; scheme=W3C-DTF"; $node = $this->setNodeValue('dcterms:valid', $dcTerms, $item); if ($flavorAsset) { $node = $this->setNodeValue('media:group/media:content/@url', $this->getAssetUrl($flavorAsset), $item); $type = ''; switch ($flavorAsset->getFileExt()) { case 'mp4': $type = 'video/mp4'; break; case 'flv': $type = 'video/x-flv'; break; } $node = $this->setNodeValue('media:group/media:content/@type', $type, $item); $node = $this->setNodeValue('media:group/media:content/@fileSize', $flavorAsset->getSize(), $item); $node = $this->setNodeValue('media:group/media:content/@expression', $values[TVComDistributionField::MEDIA_CATEGORY_EPISODE_TYPE], $item); $node = $this->setNodeValue('media:group/media:content/@duration', floor($flavorAsset->getentry()->getDuration()), $item); } if ($thumbAsset) { $node = $this->setNodeValue('media:group/media:thumbnail/@url', $this->getAssetUrl($thumbAsset), $item); $node = $this->setNodeValue('media:group/media:thumbnail/@width', $thumbAsset->getWidth(), $item); $node = $this->setNodeValue('media:group/media:thumbnail/@height', $thumbAsset->getHeight(), $item); } if (is_array($additionalAssets)) { foreach ($additionalAssets as $additionalAsset) { /* @var $additionalAsset asset */ $assetType = $additionalAsset->getType(); switch ($assetType) { case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION): /* @var $captionPlugin CaptionPlugin */ $captionPlugin = KalturaPluginManager::getPluginInstance(CaptionPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $captionPlugin->contributeCaptionAssets($additionalAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $captionDom = $dummyDom->getElementsByTagName('subTitle'); $captionDom = $this->doc->importNode($captionDom->item(0), true); $captionDom = $item->appendChild($captionDom); break; case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT): /* @var $attachmentPlugin AttachmentPlugin */ $attachmentPlugin = KalturaPluginManager::getPluginInstance(AttachmentPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $attachmentPlugin->contributeAttachmentAssets($additionalAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $attachmentDom = $dummyDom->getElementsByTagName('attachment'); $attachmentDom = $this->doc->importNode($attachmentDom->item(0), true); $attachmentDom = $item->appendChild($attachmentDom); break; } } } }
/** * @param string $value * @return IKalturaEnumerator */ public static function getPlugin($value) { $split = explode(IKalturaEnumerator::PLUGIN_VALUE_DELIMITER, $value, 2); if (count($split) == 1) { return null; } list($pluginName, $valueName) = $split; $plugin = KalturaPluginManager::getPluginInstance($pluginName); if ($plugin && $plugin instanceof IKalturaEnumerator) { return $plugin; } return null; }
/** * @param array $values * @param array $flavorAssets * @param array $thumbAssets */ public function getItem(array $values, array $flavorAssets = null, array $thumbAssets = null, array $additionalAssets = null) { $item = $this->item->cloneNode(true); kXml::setNodeValue($this->xpath, 'guid', $values[TimeWarnerDistributionField::GUID], $item); kXml::setNodeValue($this->xpath, 'title', $values[TimeWarnerDistributionField::TITLE], $item); kXml::setNodeValue($this->xpath, 'description', $values[TimeWarnerDistributionField::DESCRIPTION], $item); kXml::setNodeValue($this->xpath, 'author', $values[TimeWarnerDistributionField::AUTHOR], $item); kXml::setNodeValue($this->xpath, 'pubDate', $this->formatTimeWarnerDate($values[TimeWarnerDistributionField::PUB_DATE]), $item); kXml::setNodeValue($this->xpath, 'media:copyright', $values[TimeWarnerDistributionField::MEDIA_COPYRIGHT], $item); kXml::setNodeValue($this->xpath, 'media:keywords', $values[TimeWarnerDistributionField::MEDIA_KEYWORDS], $item); kXml::setNodeValue($this->xpath, 'media:rating', $values[TimeWarnerDistributionField::MEDIA_RATING], $item); //handle category $this->addCategory($item, 'CT-' . $values[TimeWarnerDistributionField::MEDIA_CATEGORY_CT]); if ($values[TimeWarnerDistributionField::MEDIA_CATEGORY_GR] != "") { $this->addCategory($item, 'GR-' . $values[TimeWarnerDistributionField::MEDIA_CATEGORY_GR]); } else { $this->addCategory($item, 'GR-None'); } $this->addCategory($item, 'TX-' . $values[TimeWarnerDistributionField::MEDIA_CATEGORY_TX]); $geCategories = explode(',', $values[TimeWarnerDistributionField::MEDIA_CATEGORY_GE]); $geCategories = array_unique($geCategories); foreach ($geCategories as $geCategory) { $this->addCategory($item, 'GE-' . $geCategory); } kXml::setNodeValue($this->xpath, 'plmedia:approved', $values[TimeWarnerDistributionField::PLMEDIA_APPROVED], $item); kXml::setNodeValue($this->xpath, 'twcable:episodeNumber', $values[TimeWarnerDistributionField::CABLE_EPISODE_NUMBER], $item); kXml::setNodeValue($this->xpath, 'twcable:externalID', $values[TimeWarnerDistributionField::CABLE_EXTERNAL_ID], $item); kXml::setNodeValue($this->xpath, 'twcable:productionDate', $values[TimeWarnerDistributionField::CABLE_PRODUCTION_DATE], $item); kXml::setNodeValue($this->xpath, 'twcable:network', $values[TimeWarnerDistributionField::CABLE_NETWORK], $item); kXml::setNodeValue($this->xpath, 'twcable:provider', $values[TimeWarnerDistributionField::CABLE_PROVIDER], $item); kXml::setNodeValue($this->xpath, 'twcable:shortDescription', $values[TimeWarnerDistributionField::CABLE_SHORT_DESCRIPTION], $item); kXml::setNodeValue($this->xpath, 'twcable:shortTitle', $values[TimeWarnerDistributionField::CABLE_SHORT_TITLE], $item); kXml::setNodeValue($this->xpath, 'twcable:showName', $values[TimeWarnerDistributionField::CABLE_SHOW_NAME], $item); $startTime = date('c', $values[TimeWarnerDistributionField::START_TIME]); $endTime = date('c', $values[TimeWarnerDistributionField::END_TIME]); $dcTerms = "start={$startTime}; end={$endTime};"; kXml::setNodeValue($this->xpath, 'dcterms:valid', $dcTerms, $item); if (!is_null($flavorAssets) && is_array($flavorAssets) && count($flavorAssets) > 0) { $this->setFlavorAsset($item, $flavorAssets); } if (!is_null($thumbAssets) && is_array($thumbAssets) && count($thumbAssets) > 0) { $this->setThumbAsset($item, $thumbAssets); } if (is_array($additionalAssets)) { foreach ($additionalAssets as $additionalAsset) { /* @var $additionalAsset asset */ $assetType = $additionalAsset->getType(); switch ($assetType) { case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION): /* @var $captionPlugin CaptionPlugin */ $captionPlugin = KalturaPluginManager::getPluginInstance(CaptionPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $captionPlugin->contributeCaptionAssets($additionalAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $captionDom = $dummyDom->getElementsByTagName('subTitle'); $captionDom = $this->doc->importNode($captionDom->item(0), true); $captionDom = $item->appendChild($captionDom); break; case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT): /* @var $attachmentPlugin AttachmentPlugin */ $attachmentPlugin = KalturaPluginManager::getPluginInstance(AttachmentPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $attachmentPlugin->contributeAttachmentAssets($additionalAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $attachmentDom = $dummyDom->getElementsByTagName('attachment'); $attachmentDom = $this->doc->importNode($attachmentDom->item(0), true); $attachmentDom = $item->appendChild($attachmentDom); break; } } } return $item; }
/** * Checks whether the string enum value is valid for the reflected string enum * * @param mixed $value * @return boolean */ public function checkStringEnumValue($value) { if (!$this->isStringEnum()) { return false; } $this->getConstants(); foreach ($this->_constants as $constValue) { if ((string) $constValue->getDefaultValue() === (string) $value) { return true; } } if ($this->isDynamicEnum()) { $split = explode(IKalturaEnumerator::PLUGIN_VALUE_DELIMITER, $value, 2); if (count($split) == 1) { return false; } list($pluginName, $valueName) = $split; $type = $this->getType(); // TODO remove call_user_func after moving to php 5.3 $baseEnumName = call_user_func(array($type, 'getEnumClass')); // $baseEnumName = $type::getEnumClass(); $pluginInstance = KalturaPluginManager::getPluginInstance($pluginName); $enums = $pluginInstance->getEnums($baseEnumName); foreach ($enums as $enum) { // TODO remove call_user_func after moving to php 5.3 $enumConstans = call_user_func(array($enum, 'getAdditionalValues')); // $enumConstans = $enum::getAdditionalValues(); if (in_array($valueName, $enumConstans)) { return true; } } } return false; }
/** * @param array $values * @param array $flavorAssets * @param array $thumbAssets */ public function getItem(array $values, entry $entry, array $flavorAssets = null, array $thumbAssets = null, array $additionalAssets = null) { $item = $this->item->cloneNode(true); kXml::setNodeValue($this->xpath, 'atom:title', $values[SynacorHboDistributionField::ENTRY_TITLE], $item); kXml::setNodeValue($this->xpath, 'atom:summary', $values[SynacorHboDistributionField::ENTRY_SUMMARY], $item); $updatedTime = $this->formatSynacorHboTime($values[SynacorHboDistributionField::ENTRY_UPDATED]); kXml::setNodeValue($this->xpath, 'atom:updated', $updatedTime, $item); kXml::setNodeValue($this->xpath, 'atom:author/atom:name', $values[SynacorHboDistributionField::ENTRY_AUTHOR_NAME], $item); $categoryValue = $values[SynacorHboDistributionField::ENTRY_CATEGORY_TERM]; if (strlen($categoryValue) > 0) { kXml::setNodeValue($this->xpath, 'atom:category/@term', $categoryValue, $item); } else { $this->removeNode('atom:category', $item); } $genreValue = $values[SynacorHboDistributionField::ENTRY_GENRE_TERM]; if (strlen($genreValue) > 0) { kXml::setNodeValue($this->xpath, 'atom:genre/@term', $genreValue, $item); } else { $this->removeNode('atom:genre', $item); } kXml::setNodeValue($this->xpath, 'atom:assetType', $values[SynacorHboDistributionField::ENTRY_ASSET_TYPE], $item); kXml::setNodeValue($this->xpath, 'atom:assetId', $values[SynacorHboDistributionField::ENTRY_ASSET_ID], $item); $startTime = $this->formatSynacorHboTime($values[SynacorHboDistributionField::ENTRY_OFFERING_START]); kXml::setNodeValue($this->xpath, 'atom:offering/atom:start', $startTime, $item); $endTime = $this->formatSynacorHboTime($values[SynacorHboDistributionField::ENTRY_OFFERING_END]); kXml::setNodeValue($this->xpath, 'atom:offering/atom:end', $endTime, $item); $ratingValue = $values[SynacorHboDistributionField::ENTRY_RATING]; if (strlen($ratingValue) > 0) { kXml::setNodeValue($this->xpath, 'atom:rating', $ratingValue, $item); $ratingType = stripos($ratingValue, 'tv') === '0' ? 'tv' : 'theatrical'; kXml::setNodeValue($this->xpath, 'atom:rating/@type', $ratingType, $item); } else { $this->removeNode('atom:rating', $item); } $durationInSeconds = ceil($entry->getDuration()); $durationInMinuesRoundedUp = ceil($durationInSeconds / 60); kXml::setNodeValue($this->xpath, 'atom:runtime', $durationInMinuesRoundedUp, $item); kXml::setNodeValue($this->xpath, 'atom:runtime/@timeInSeconds', $durationInSeconds, $item); kXml::setNodeValue($this->xpath, 'go:series/go:title', $values[SynacorHboDistributionField::ENTRY_SERIES_TITLE], $item); kXml::setNodeValue($this->xpath, 'atom:brand', $values[SynacorHboDistributionField::ENTRY_BRAND], $item); if (!is_null($flavorAssets) && is_array($flavorAssets) && count($flavorAssets) > 0) { $flavorAsset = $flavorAssets[0]; /* @var $flavorAsset flavorAsset */ $flavorUrl = $this->getAssetUrl($flavorAsset); // we don't have a way to identify the mime type of the file // as there is no guarantee that the file exists in the current data center // so we will just use those hardcoded conditions $mimeType = ''; switch ($flavorAsset->getFileExt()) { case 'flv': $mimeType = 'video/x-flv'; break; case 'mp4': $mimeType = 'video/mp4'; break; case 'mpeg': case 'mpg': $mimeType = 'video/mpeg'; break; default: $mimeType = 'video/x-flv'; // default requested by synacor } kXml::setNodeValue($this->xpath, 'atom:link[@type=\'VIDEO_MIME_TYPE\']/@href', $flavorUrl, $item); kXml::setNodeValue($this->xpath, 'atom:link[@type=\'VIDEO_MIME_TYPE\']/@type', $mimeType, $item); } if (!is_null($thumbAssets) && is_array($thumbAssets) && count($thumbAssets) > 0) { $thumbAsset = $thumbAssets[0]; /* @var $thumbAssets thumbAssets */ $thumbUrl = $this->getAssetUrl($thumbAsset); kXml::setNodeValue($this->xpath, 'atom:link[@type=\'image/jpeg\']/@href', $thumbUrl, $item); } if (is_array($additionalAssets)) { foreach ($additionalAssets as $additionalAsset) { /* @var $additionalAsset asset */ $assetType = $additionalAsset->getType(); switch ($assetType) { case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION): /* @var $captionPlugin CaptionPlugin */ $captionPlugin = KalturaPluginManager::getPluginInstance(CaptionPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $captionPlugin->contributeCaptionAssets($additionalAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $captionDom = $dummyDom->getElementsByTagName('subTitle'); $captionDom = $this->doc->importNode($captionDom->item(0), true); $captionDom = $item->appendChild($captionDom); break; case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT): /* @var $attachmentPlugin AttachmentPlugin */ $attachmentPlugin = KalturaPluginManager::getPluginInstance(AttachmentPlugin::PLUGIN_NAME); $dummyElement = new SimpleXMLElement('<dummy/>'); $attachmentPlugin->contributeAttachmentAssets($additionalAsset, $dummyElement); $dummyDom = dom_import_simplexml($dummyElement); $attachmentDom = $dummyDom->getElementsByTagName('attachment'); $attachmentDom = $this->doc->importNode($attachmentDom->item(0), true); $attachmentDom = $item->appendChild($attachmentDom); break; } } } return $item; }