public function watchFolder(KalturaDropFolder $folder)
 {
     $this->dropFolder = $folder;
     $this->fileTransferMgr = self::getFileTransferManager($this->dropFolder);
     KalturaLog::info('Watching folder [' . $this->dropFolder->id . ']');
     $physicalFiles = $this->getDropFolderFilesFromPhysicalFolder();
     if (count($physicalFiles) > 0) {
         $dropFolderFilesMap = $this->loadDropFolderFiles();
     } else {
         $dropFolderFilesMap = array();
     }
     $maxModificationTime = 0;
     foreach ($physicalFiles as &$physicalFile) {
         /* @var $physicalFile FileObject */
         $physicalFileName = $physicalFile->filename;
         $utfFileName = kString::stripUtf8InvalidChars($physicalFileName);
         if ($physicalFileName != $utfFileName) {
             KalturaLog::info("File name [{$physicalFileName}] is not utf-8 compatible, Skipping file...");
             continue;
         }
         if (!kXml::isXMLValidContent($utfFileName)) {
             KalturaLog::info("File name [{$physicalFileName}] contains invalid XML characters, Skipping file...");
             continue;
         }
         if ($this->dropFolder->incremental && $physicalFile->modificationTime < $this->dropFolder->lastFileTimestamp) {
             KalturaLog::info("File modification time [" . $physicalFile->modificationTime . "] predates drop folder last timestamp [" . $this->dropFolder->lastFileTimestamp . "]. Skipping.");
             if (isset($dropFolderFilesMap[$physicalFileName])) {
                 unset($dropFolderFilesMap[$physicalFileName]);
             }
             continue;
         }
         if ($this->validatePhysicalFile($physicalFileName)) {
             $maxModificationTime = $physicalFile->modificationTime > $maxModificationTime ? $physicalFile->modificationTime : $maxModificationTime;
             KalturaLog::info('Watch file [' . $physicalFileName . ']');
             if (!array_key_exists($physicalFileName, $dropFolderFilesMap)) {
                 try {
                     $lastModificationTime = $physicalFile->modificationTime;
                     $fileSize = $physicalFile->fileSize;
                     $this->handleFileAdded($physicalFileName, $fileSize, $lastModificationTime);
                 } catch (Exception $e) {
                     KalturaLog::err("Error handling drop folder file [{$physicalFileName}] " . $e->getMessage());
                 }
             } else {
                 $dropFolderFile = $dropFolderFilesMap[$physicalFileName];
                 //if file exist in the folder remove it from the map
                 //all the files that are left in a map will be marked as PURGED
                 unset($dropFolderFilesMap[$physicalFileName]);
                 $this->handleExistingDropFolderFile($dropFolderFile);
             }
         }
     }
     foreach ($dropFolderFilesMap as $dropFolderFile) {
         $this->handleFilePurged($dropFolderFile->id);
     }
     if ($this->dropFolder->incremental && $maxModificationTime > $this->dropFolder->lastFileTimestamp) {
         $updateDropFolder = new KalturaDropFolder();
         $updateDropFolder->lastFileTimestamp = $maxModificationTime;
         $this->dropFolderPlugin->dropFolder->update($this->dropFolder->id, $updateDropFolder);
     }
 }
Example #2
0
 /**	
  * 
  * Generates a new KalturaTestsFailures object from a given failure file path 
  * @param string $failureFilePath
  */
 public function fromXml($failureFilePath)
 {
     $simpleXML = kXml::openXmlFile($failureFilePath);
     foreach ($simpleXML->Failures->UnitTestFailures as $unitTestFailureXml) {
         $this->testCaseFailures[] = KalturaTestCaseFailure::generateFromXml($unitTestFailureXml);
     }
 }
 /**
  * sets the KalturaDataGeneratorConfigFile object from simpleXMLElement (the source xml of the data)
  * @param SimpleXMLElement $simpleXMLElement
  * 
  * @return None, sets the given object
  */
 public function fromSourceXML(SimpleXMLElement $simpleXMLElement)
 {
     //For each test file
     foreach ($simpleXMLElement->TestDataFile as $xmlTestDataFile) {
         //Create new test file obejct
         $testDataFile = new KalturaUnitTestDataFile();
         //For each UnitTest data (in this file)
         foreach ($xmlTestDataFile->UnitTestsData->UnitTestData as $xmlUnitTestData) {
             //Create new unit test data
             $unitTestData = new KalturaUnitTestData();
             //For each input create the needed Kaltura object identifier
             foreach ($xmlUnitTestData->Inputs->Input as $input) {
                 $additionalData = kXml::getAttributesAsArray($input);
                 $unitTestDataObjectIdentifier = new KalturaUnitTestDataObject((string) $input["type"], $additionalData);
                 $unitTestData->input[] = $unitTestDataObjectIdentifier;
             }
             //And for each output reference create the needed kaltura object identifier
             foreach ($xmlUnitTestData->OutputReferences->OutputReference as $outputReference) {
                 $additionalData = kXml::getAttributesAsArray($outputReference);
                 $unitTestDataObjectIdentifier = new KalturaUnitTestDataObject((string) $outputReference["type"], $additionalData);
                 $unitTestData->outputReference[] = $unitTestDataObjectIdentifier;
             }
             //Add the new unit test into the tests array.
             $testDataFile->unitTestsData[] = $unitTestData;
         }
         $testDataFile->fileName = trim((string) $xmlTestDataFile->FileName);
         $this->testFiles[] = $testDataFile;
     }
 }
 private function parseStrTTTime($timeStr)
 {
     $matches = null;
     if (preg_match('/(\\d+)s/', $timeStr)) {
         return intval($matches[1]) * 1000;
     }
     return kXml::timeToInteger($timeStr);
 }
 public function execute()
 {
     $this->forceSystemAuthentication();
     $kshow_id = @$_REQUEST["kshow_id"];
     $this->kshow_id = $kshow_id;
     $this->kshow = NULL;
     $entry_id = @$_REQUEST["entry_id"];
     $this->entry_id = $entry_id;
     $this->entry = NULL;
     $this->message = "";
     if (!empty($kshow_id)) {
         $this->kshow = kshowPeer::retrieveByPK($kshow_id);
         if (!$this->kshow) {
             $this->message = "Cannot find kshow [{$kshow_id}]";
         } else {
             $this->entry = $this->kshow->getShowEntry();
         }
     } elseif (!empty($kshow_id)) {
         $this->entry = entryPeer::retrieveByPK($entry_id);
         if (!$this->entry) {
             $this->message = "Cannot find entry [{$entry_id}]";
         } else {
             $this->kshow = $this->{$this}->entry->getKshow();
         }
     }
     if ($this->kshow) {
         $this->metadata = $this->kshow->getMetadata();
     } else {
         $this->metadata = "";
     }
     $pending_str = $this->getP("pending");
     $remove_pending = $this->getP("remove_pending");
     if ($this->metadata && ($remove_pending || $pending_str)) {
         if ($remove_pending) {
             $pending_str = "";
         }
         $xml_doc = new DOMDocument();
         $xml_doc->loadXML($this->metadata);
         $metadata = kXml::getFirstElement($xml_doc, "MetaData");
         $should_save = kXml::setChildElement($xml_doc, $metadata, "Pending", $pending_str, true);
         if ($remove_pending) {
             $should_save = kXml::setChildElement($xml_doc, $metadata, "LastPendingTimeStamp", "", true);
         }
         if ($should_save) {
             $fixed_content = $xml_doc->saveXML();
             $content_dir = myContentStorage::getFSContentRootPath();
             $file_name = realpath($content_dir . $this->entry->getDataPath());
             $res = file_put_contents($file_name, $fixed_content);
             // sync - NOTOK
             $this->metadata = $fixed_content;
         }
     }
     $this->pending = $pending_str;
     $this->kshow_id = $kshow_id;
     $this->entry_id = $entry_id;
 }
Example #6
0
 public function handleFooter()
 {
     $mrss = $this->getKalturaMrssXml($this->syndicationFeed->name, $this->syndicationFeed->feedLandingPage, $this->syndicationFeed->feedDescription);
     if ($this->kalturaXslt) {
         $mrss = kXml::transformXmlUsingXslt($mrss, $this->kalturaXslt);
     }
     $divideHeaderFromFooter = strpos($mrss, self::ITEMS_PLACEHOLDER) + strlen(self::ITEMS_PLACEHOLDER);
     $mrss = substr($mrss, $divideHeaderFromFooter);
     return $mrss;
 }
 /**
  * 
  * Generates a new testCaseFailure object from a given simpleXmlElement (failure file xml)
  * @param SimpleXMlElement $unitTestFailureXml
  */
 public function fromXml(SimpleXMlElement $unitTestFailureXml)
 {
     //Sets the inputs as key => value byt the xml attributes
     foreach ($unitTestFailureXml->Inputs->Input as $inputXml) {
         $this->testCaseInput[] = kXml::getAttributesAsArray($inputXml);
     }
     foreach ($unitTestFailureXml->Failures->Failure as $failureXml) {
         $this->testCaseFailures[] = KalturaFailure::generateFromXml($failureXml);
     }
 }
 public static function validateXsdData($xsdData, &$errorMessage)
 {
     // validates the xsd
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xml = new KDOMDocument();
     if (!$xml->loadXML($xsdData)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xsdData);
         return false;
     }
     libxml_clear_errors();
     libxml_use_internal_errors(false);
     return true;
 }
 protected function parseOutput($output)
 {
     $output = kXml::stripXMLInvalidChars($output);
     $tokenizer = new KStringTokenizer($output, "\t\n");
     $mediaInfo = new KalturaMediaInfo();
     $mediaInfo->rawData = $output;
     $fieldCnt = 0;
     $section = self::SrteamGeneral;
     $sectionID = 0;
     $mediaInfo->streamArray = array();
     $streamMediaInfo = null;
     while ($tokenizer->hasMoreTokens()) {
         $tok = strtolower(trim($tokenizer->nextToken()));
         if (strrpos($tok, ":") == false) {
             if (isset($streamMediaInfo)) {
                 $mediaInfo->streamArray[$section][] = $streamMediaInfo;
             }
             $streamMediaInfo = new KalturaMediaInfo();
             $sectionID = strchr($tok, "#");
             if ($sectionID) {
                 $sectionID = trim($sectionID, "#");
             } else {
                 $sectionID = 0;
             }
             if (strstr($tok, self::SrteamGeneral) == true) {
                 $section = self::SrteamGeneral;
             } else {
                 if (strstr($tok, self::SrteamVideo) == true) {
                     $section = self::SrteamVideo;
                 } else {
                     if (strstr($tok, self::SrteamAudio) == true) {
                         $section = self::SrteamAudio;
                     } else {
                         $section = $tok;
                     }
                 }
             }
         } else {
             if ($sectionID <= 1) {
                 self::loadStreamMedia($mediaInfo, $section, $tok);
                 $fieldCnt++;
             }
         }
         self::loadStreamMedia($streamMediaInfo, $section, $tok);
     }
     if (isset($streamMediaInfo)) {
         $mediaInfo->streamArray[$section][] = $streamMediaInfo;
     }
     return $mediaInfo;
 }
 public function doTest($xmlPath, $type)
 {
     echo "\tTesting File [{$xmlPath}]\n";
     $serviceUrl = $this->client->getConfig()->serviceUrl;
     $xsdPath = "{$serviceUrl}/api_v3/index.php/service/schema/action/serve/type/{$type}";
     //		libxml_use_internal_errors(true);
     //		libxml_clear_errors();
     $doc = new DOMDocument();
     $doc->Load($xmlPath);
     //Validate the XML file against the schema
     if (!$doc->schemaValidate($xsdPath)) {
         $description = kXml::getLibXmlErrorDescription(file_get_contents($xmlPath));
         $this->fail("Type [{$type}] File [{$xmlPath}]: {$description}");
     }
 }
Example #11
0
 public static function getAllAssetsData($filePath)
 {
     list($xml_doc, $xpath) = self::getDomAndXpath($filePath);
     $asset_ids = self::getElementsList($xpath, "*");
     //$asset_ids = $xpath->query( "//VideoAssets/vidAsset" );
     $arr = array();
     foreach ($asset_ids as $asset_id) {
         $node = array();
         $node["id"] = $asset_id->getAttribute("k_id");
         $stream_info_elem = kXml::getFirstElement($asset_id, "StreamInfo");
         $node["start_time"] = $stream_info_elem->getAttribute("start_time");
         $node["len_time"] = $stream_info_elem->getAttribute("len_time");
         //start_time="0" len_time=
         $arr[] = $node;
     }
     return $arr;
 }
 protected function parseCuePoint(SimpleXMLElement $scene)
 {
     if ($scene->getName() != 'scene-code-cue-point') {
         return null;
     }
     $cuePoint = parent::parseCuePoint($scene);
     if (!$cuePoint instanceof KalturaCodeCuePoint) {
         return null;
     }
     if (isset($scene->sceneEndTime)) {
         $cuePoint->endTime = kXml::timeToInteger($scene->sceneEndTime);
     }
     if (isset($scene->code)) {
         $cuePoint->code = "{$scene->code}";
     }
     if (isset($scene->description)) {
         $cuePoint->description = "{$scene->description}";
     }
     return $cuePoint;
 }
 /**
  * Parse content of caption asset and index it
  *
  * @action parse
  * @param string $captionAssetId
  * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND
  */
 function parseAction($captionAssetId)
 {
     $captionAsset = assetPeer::retrieveById($captionAssetId);
     if (!$captionAsset) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
     }
     $captionAssetItems = CaptionAssetItemPeer::retrieveByAssetId($captionAssetId);
     foreach ($captionAssetItems as $captionAssetItem) {
         /* @var $captionAssetItem CaptionAssetItem */
         $captionAssetItem->delete();
     }
     // make sure that all old items are deleted from the sphinx before creating the new ones
     kEventsManager::flushEvents();
     $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $content = kFileSyncUtils::file_get_contents($syncKey, true, false);
     if (!$content) {
         return;
     }
     $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat());
     if (!$captionsContentManager) {
         return;
     }
     $itemsData = $captionsContentManager->parse($content);
     foreach ($itemsData as $itemData) {
         $item = new CaptionAssetItem();
         $item->setCaptionAssetId($captionAsset->getId());
         $item->setEntryId($captionAsset->getEntryId());
         $item->setPartnerId($captionAsset->getPartnerId());
         $item->setStartTime($itemData['startTime']);
         $item->setEndTime($itemData['endTime']);
         $content = '';
         foreach ($itemData['content'] as $curChunk) {
             $content .= $curChunk['text'];
         }
         //Make sure there are no invalid chars in the caption asset items to avoid braking the search request by providing invalid XML
         $content = kString::stripUtf8InvalidChars($content);
         $content = kXml::stripXMLInvalidChars($content);
         $item->setContent($content);
         $item->save();
     }
 }
 protected function parseCuePoint(SimpleXMLElement $scene)
 {
     if ($scene->getName() != 'scene-annotation') {
         return null;
     }
     $cuePoint = parent::parseCuePoint($scene);
     if (!$cuePoint instanceof KalturaAnnotation) {
         return null;
     }
     if (isset($scene->sceneEndTime)) {
         $cuePoint->endTime = kXml::timeToInteger($scene->sceneEndTime);
     }
     if (isset($scene->sceneText)) {
         $cuePoint->text = "{$scene->sceneText}";
     }
     if (isset($scene->parentId)) {
         $cuePoint->parentId = "{$scene->parentId}";
     } elseif (isset($scene->parent)) {
         $cuePoint->parentId = $this->getCuePointId("{$scene->parent}");
     }
     return $cuePoint;
 }
 protected function parseCuePoint(SimpleXMLElement $scene)
 {
     if ($scene->getName() != 'scene-ad-cue-point') {
         return null;
     }
     $cuePoint = parent::parseCuePoint($scene);
     if (!$cuePoint instanceof KalturaAdCuePoint) {
         return null;
     }
     if (isset($scene->sceneEndTime)) {
         $cuePoint->endTime = kXml::timeToInteger($scene->sceneEndTime);
     }
     if (isset($scene->sceneTitle)) {
         $cuePoint->title = "{$scene->sceneTitle}";
     }
     if (isset($scene->sourceUrl)) {
         $cuePoint->sourceUrl = "{$scene->sourceUrl}";
     }
     $cuePoint->adType = "{$scene->adType}";
     $cuePoint->protocolType = "{$scene->protocolType}";
     return $cuePoint;
 }
 /**
  * Allows you to add a metadata profile object and metadata profile file associated with Kaltura object type
  * 
  * @action addFromFile
  * @param KalturaMetadataProfile $metadataProfile
  * @param file $xsdFile XSD metadata definition
  * @param file $viewsFile UI views definition
  * @return KalturaMetadataProfile
  * @throws MetadataErrors::METADATA_FILE_NOT_FOUND
  */
 function addFromFileAction(KalturaMetadataProfile $metadataProfile, $xsdFile, $viewsFile = null)
 {
     $filePath = $xsdFile['tmp_name'];
     if (!file_exists($filePath)) {
         throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $xsdFile['name']);
     }
     // validates the xsd
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xml = new KDOMDocument();
     if (!$xml->load($filePath)) {
         $errorMessage = kXml::getLibXmlErrorDescription(file_get_contents($xsdFile));
         throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_PROFILE_SCHEMA, $errorMessage);
     }
     libxml_clear_errors();
     libxml_use_internal_errors(false);
     // must be validatebefore checking available searchable fields count
     $metadataProfile->validatePropertyNotNull('metadataObjectType');
     kMetadataManager::validateMetadataProfileField($this->getPartnerId(), $xsdFile, false, $metadataProfile->metadataObjectType);
     $dbMetadataProfile = $metadataProfile->toInsertableObject();
     $dbMetadataProfile->setStatus(KalturaMetadataProfileStatus::ACTIVE);
     $dbMetadataProfile->setPartnerId($this->getPartnerId());
     $dbMetadataProfile->save();
     $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     kFileSyncUtils::moveFromFile($filePath, $key);
     if ($viewsFile && $viewsFile['size']) {
         $filePath = $viewsFile['tmp_name'];
         if (!file_exists($filePath)) {
             throw new KalturaAPIException(MetadataErrors::METADATA_FILE_NOT_FOUND, $viewsFile['name']);
         }
         $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS);
         kFileSyncUtils::moveFromFile($filePath, $key);
     }
     kMetadataManager::parseProfileSearchFields($this->getPartnerId(), $dbMetadataProfile);
     $metadataProfile = new KalturaMetadataProfile();
     $metadataProfile->fromObject($dbMetadataProfile);
     return $metadataProfile;
 }
 public static function syndicate(CuePoint $cuePoint, SimpleXMLElement $scenes, SimpleXMLElement $scene = null)
 {
     if (!$cuePoint instanceof Annotation) {
         return $scene;
     }
     if (!$scene) {
         $scene = kCuePointManager::syndicateCuePointXml($cuePoint, $scenes->addChild('scene-annotation'));
     }
     $scene->addChild('sceneEndTime', kXml::integerToTime($cuePoint->getEndTime()));
     if ($cuePoint->getText()) {
         $scene->addChild('sceneText', kMrssManager::stringToSafeXml($cuePoint->getText()));
     }
     if ($cuePoint->getParentId()) {
         $parentCuePoint = CuePointPeer::retrieveByPK($cuePoint->getParentId());
         if ($parentCuePoint) {
             if ($parentCuePoint->getSystemName()) {
                 $scene->addChild('parent', kMrssManager::stringToSafeXml($parentCuePoint->getSystemName()));
             }
             $scene->addChild('parentId', $parentCuePoint->getId());
         }
     }
     return $scene;
 }
Example #18
0
 /**
  * @param array<CuePoint> $cuePoints
  * @return string xml
  */
 public static function generateXml(array $cuePoints)
 {
     $schemaType = CuePointPlugin::getApiValue(CuePointSchemaType::SERVE_API);
     $xsdUrl = "http://" . kConf::get('cdn_host') . "/api_v3/service/schema/action/serve/type/{$schemaType}";
     $scenes = new SimpleXMLElement('<scenes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="' . $xsdUrl . '" />');
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaCuePointXmlParser');
     foreach ($cuePoints as $cuePoint) {
         $scene = null;
         foreach ($pluginInstances as $pluginInstance) {
             $scene = $pluginInstance->generateXml($cuePoint, $scenes, $scene);
         }
     }
     $xmlContent = $scenes->asXML();
     $xml = new KDOMDocument();
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     if (!$xml->loadXML($xmlContent)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xmlContent);
         throw new kCuePointException("XML is invalid:\n{$errorMessage}", kCuePointException::XML_INVALID);
     }
     $xsdPath = SchemaService::getSchemaPath($schemaType);
     libxml_clear_errors();
     if (!$xml->schemaValidate($xsdPath)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xmlContent);
         throw new kCuePointException("XML is invalid:\n{$errorMessage}", kCuePointException::XML_INVALID);
     }
     return $xmlContent;
 }
 /**
  * 
  * The test data provider (gets the data for the different tests)
  * @param string $className - The class name
  * @param string $procedureName - The current method (test) name
  * @return array<array>();
  */
 public function provider($className, $procedureName)
 {
     //print("In provider for $className, $procedureName \n");
     //Gets from the given class the class data file
     $class = get_class($this);
     $classFilePath = KAutoloader::getClassFilePath($class);
     $testClassDir = dirname($classFilePath);
     $dataFilePath = $testClassDir . DIRECTORY_SEPARATOR . "testsData/{$className}.data";
     KalturaLog::debug("The data file path [" . $dataFilePath . "]");
     if (file_exists($dataFilePath)) {
         $simpleXML = kXml::openXmlFile($dataFilePath);
     } else {
         //TODO: Give notice or create the file don't throw an exception
         throw new Exception("Data file [{$dataFilePath}] not found");
     }
     $inputsForTestProcedure = array();
     foreach ($simpleXML->TestProcedureData as $xmlTestProcedureData) {
         if ($xmlTestProcedureData["testProcedureName"] != $procedureName) {
             continue;
         }
         foreach ($xmlTestProcedureData->TestCaseData as $xmlTestCaseData) {
             $testCaseInstanceInputs = array();
             foreach ($xmlTestCaseData->Input as $input) {
                 $object = KalturaTestDataObject::generatefromXml($input);
                 //Add the new input to the test case instance data
                 $testCaseInstanceInputs[] = $object;
             }
             foreach ($xmlTestCaseData->OutputReference as $output) {
                 $object = KalturaTestDataObject::generatefromXml($output);
                 //Add the new output reference to the test case instance data
                 $testCaseInstanceInputs[] = $object;
             }
             //Add the test case into the test procedure data
             $inputsForTestProcedure[] = $testCaseInstanceInputs;
         }
     }
     KalturaLog::info("Tests data provided Before transformation to objects: \n[" . print_r($inputsForTestProcedure, true) . "]");
     $inputsForTestProcedure = $this->transformToObjects($inputsForTestProcedure);
     KalturaLog::info("Tests data provided [" . print_r($inputsForTestProcedure, true) . "]");
     return $inputsForTestProcedure;
 }
Example #20
0
 public function setCuePoints(DOMElement $item, array $cuePoints)
 {
     foreach ($cuePoints as $cuePoint) {
         /* @var $cuePoint cuePoint */
         $content = $this->cuePoint->cloneNode(true);
         $mediaGroup = $this->xpath->query('.', $item)->item(0);
         $mediaGroup->appendChild($content);
         kXml::setNodeValue($this->xpath, '@type', self::MILLISECONDS, $content);
         kXml::setNodeValue($this->xpath, '@startTime', $cuePoint->getStartTime(), $content);
     }
 }
Example #21
0
 /**
  * @param array $flavorAssets
  */
 public function setThumbAssets(DOMElement $item, array $thumbAssets)
 {
     foreach ($thumbAssets as $thumbAsset) {
         /* @var $flavorAsset flavorAsset */
         $content = $this->thumbnail->cloneNode(true);
         $mediaGroup = $this->xpath->query('media:group', $item)->item(0);
         $mediaGroup->appendChild($content);
         $url = $this->getAssetUrl($thumbAsset);
         kXml::setNodeValue($this->xpath, '@url', $url, $content);
         kXml::setNodeValue($this->xpath, '@width', $thumbAsset->getWidth(), $content);
         kXml::setNodeValue($this->xpath, '@height', $thumbAsset->getHeight(), $content);
     }
 }
 /**
  * Creates a new Kaltura objects DataGenerator
  * Gets The file path to it's configuration file
  * 
  * @param string $dataGeneratorConfigFilePath the config file path
  */
 public function __construct($dataGeneratorConfigFilePath)
 {
     $simpleXMLElement = kXml::openXmlFile($dataGeneratorConfigFilePath);
     $this->dataSourceFile = KalturaTestDataSourceFile::generateFromXML($simpleXMLElement);
     $this->dataSourceFile->setFilePath($dataGeneratorConfigFilePath);
 }
 /**
  * @param string $results
  * @param KalturaGenericDistributionProviderParser $resultParserType
  * @param string $resultParseData
  * @return array of parsed values
  */
 protected function parseResults($results, $resultParserType, $resultParseData)
 {
     switch ($resultParserType) {
         case KalturaGenericDistributionProviderParser::XSL:
             $xml = new DOMDocument();
             if (!$xml->loadXML($results)) {
                 return false;
             }
             $xsl = new DOMDocument();
             $xsl->loadXML($resultParseData);
             $proc = new XSLTProcessor();
             $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
             $proc->importStyleSheet($xsl);
             $data = $proc->transformToDoc($xml);
             if (!$data) {
                 return false;
             }
             return explode(',', $data);
         case KalturaGenericDistributionProviderParser::XPATH:
             $xml = new DOMDocument();
             if (!$xml->loadXML($results)) {
                 return false;
             }
             $xpath = new DOMXPath($xml);
             $elements = $xpath->query($resultParseData);
             if (is_null($elements)) {
                 return false;
             }
             $matches = array();
             foreach ($elements as $element) {
                 $matches[] = $element->textContent;
             }
             return $matches;
         case KalturaGenericDistributionProviderParser::REGEX:
             $matches = array();
             if (!preg_match("/{$resultParseData}/", $results, $matches)) {
                 return false;
             }
             return array_shift($matches);
         default:
             return false;
     }
 }
 public function getTargetUserId()
 {
     $value = $this->castSimpleType("string", $this->paramsGrouped["targetUserId"]);
     if (!kXml::isXMLValidContent($value)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, 'targetUserId');
     }
     return $value;
 }
 public function handleCustomData($objectId, SimpleXMLElement $customData)
 {
     $action = KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::REPLACE];
     if (isset($customData->action)) {
         $action = strtolower($customData->action);
     }
     $metadataProfileId = null;
     if (!empty($customData['metadataProfileId'])) {
         $metadataProfileId = (int) $customData['metadataProfileId'];
     }
     if (!$metadataProfileId && !empty($customData['metadataProfile'])) {
         $metadataProfileId = $this->getMetadataProfileId($customData['metadataProfile']);
     }
     if (!$metadataProfileId) {
         throw new KalturaBatchException("Missing custom data metadataProfile attribute", KalturaBatchJobAppErrors::BULK_MISSING_MANDATORY_PARAMETER);
     }
     $metadataPlugin = KalturaMetadataClientPlugin::get(KBatchBase::$kClient);
     $metadataFilter = new KalturaMetadataFilter();
     $metadataFilter->metadataObjectTypeEqual = $this->objectType;
     $metadataFilter->objectIdEqual = $objectId;
     $metadataFilter->metadataProfileIdEqual = $metadataProfileId;
     $pager = new KalturaFilterPager();
     $pager->pageSize = 1;
     $metadataListResponse = $metadataPlugin->metadata->listAction($metadataFilter, $pager);
     $metadataId = null;
     $metadata = null;
     if (is_array($metadataListResponse->objects) && count($metadataListResponse->objects) > 0) {
         $metadata = reset($metadataListResponse->objects);
         $metadataId = $metadata->id;
     }
     switch ($action) {
         case KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::TRANSFORM_XSLT]:
             if (!isset($customData->xslt)) {
                 throw new KalturaBatchException($this->containerName . '->' . $this->nodeName . "->xslt element is missing", KalturaBatchJobAppErrors::BULK_ELEMENT_NOT_FOUND);
             }
             if ($metadata) {
                 $metadataXml = $metadata->xml;
             } else {
                 $metadataXml = '<metadata></metadata>';
             }
             $decodedXslt = kXml::decodeXml($customData->xslt);
             $metadataXml = kXml::transformXmlUsingXslt($metadataXml, $decodedXslt);
             break;
         case KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::REPLACE]:
             if (!isset($customData->xmlData)) {
                 throw new KalturaBatchException($this->containerName . '->' . $this->nodeName . "->xmlData element is missing", KalturaBatchJobAppErrors::BULK_ELEMENT_NOT_FOUND);
             }
             $metadataXmlObject = $customData->xmlData->children();
             $metadataXml = $metadataXmlObject->asXML();
             break;
         default:
             throw new KalturaBatchException($this->containerName . '->' . $this->nodeName . "->action: {$action} is not supported", KalturaBatchJobAppErrors::BULK_ACTION_NOT_SUPPORTED);
     }
     if ($metadataId) {
         $metadataPlugin->metadata->update($metadataId, $metadataXml);
     } else {
         $metadataPlugin->metadata->add($metadataProfileId, $this->objectType, $objectId, $metadataXml);
     }
 }
Example #26
0
 /**
  * Returns the right resource instance for the source content of the item
  * @param SimpleXMLElement $elementToSearchIn
  * @param int $conversionProfileId
  * @return KalturaResource - the resource located in the given element
  */
 protected function getResourceInstance(SimpleXMLElement $elementToSearchIn, $conversionProfileId)
 {
     $resource = null;
     if (isset($elementToSearchIn->serverFileContentResource)) {
         if ($this->allowServerResource) {
             KalturaLog::debug("Resource is : serverFileContentResource");
             $resource = new KalturaServerFileResource();
             $localContentResource = $elementToSearchIn->serverFileContentResource;
             $resource->localFilePath = kXml::getXmlAttributeAsString($localContentResource, "filePath");
         } else {
             KalturaLog::err("serverFileContentResource is not allowed");
         }
     } elseif (isset($elementToSearchIn->urlContentResource)) {
         KalturaLog::debug("Resource is : urlContentResource");
         $resource = new KalturaUrlResource();
         $urlContentResource = $elementToSearchIn->urlContentResource;
         $resource->url = kXml::getXmlAttributeAsString($urlContentResource, "url");
     } elseif (isset($elementToSearchIn->sshUrlContentResource)) {
         KalturaLog::debug("Resource is : sshUrlContentResource");
         $resource = new KalturaSshUrlResource();
         $sshUrlContentResource = $elementToSearchIn->sshUrlContentResource;
         $resource->url = kXml::getXmlAttributeAsString($sshUrlContentResource, "url");
         $resource->keyPassphrase = kXml::getXmlAttributeAsString($sshUrlContentResource, "keyPassphrase");
         $resource->privateKey = strval($sshUrlContentResource->privateKey);
         $resource->publicKey = strval($sshUrlContentResource->publicKey);
     } elseif (isset($elementToSearchIn->remoteStorageContentResource)) {
         KalturaLog::debug("Resource is : remoteStorageContentResource");
         $resource = new KalturaRemoteStorageResource();
         $remoteContentResource = $elementToSearchIn->remoteStorageContentResource;
         $resource->url = kXml::getXmlAttributeAsString($remoteContentResource, "url");
         $resource->storageProfileId = $this->getStorageProfileId($remoteContentResource);
     } elseif (isset($elementToSearchIn->remoteStorageContentResources)) {
         KalturaLog::debug("Resource is : remoteStorageContentResources");
         $resource = new KalturaRemoteStorageResources();
         $resource->resources = array();
         $remoteContentResources = $elementToSearchIn->remoteStorageContentResources;
         foreach ($remoteContentResources->remoteStorageContentResource as $remoteContentResource) {
             /* @var $remoteContentResource SimpleXMLElement */
             KalturaLog::debug("Resources name [" . $remoteContentResource->getName() . "] url [" . $remoteContentResource['url'] . "] storage [{$remoteContentResource->storageProfile}]");
             $childResource = new KalturaRemoteStorageResource();
             $childResource->url = kXml::getXmlAttributeAsString($remoteContentResource, "url");
             $childResource->storageProfileId = $this->getStorageProfileId($remoteContentResource);
             $resource->resources[] = $childResource;
         }
     } elseif (isset($elementToSearchIn->entryContentResource)) {
         KalturaLog::debug("Resource is : entryContentResource");
         $resource = new KalturaEntryResource();
         $entryContentResource = $elementToSearchIn->entryContentResource;
         $resource->entryId = kXml::getXmlAttributeAsString($entryContentResource, "entryId");
         $resource->flavorParamsId = $this->getFlavorParamsId($entryContentResource, $conversionProfileId, false);
     } elseif (isset($elementToSearchIn->assetContentResource)) {
         KalturaLog::debug("Resource is : assetContentResource");
         $resource = new KalturaAssetResource();
         $assetContentResource = $elementToSearchIn->assetContentResource;
         $resource->assetId = kXml::getXmlAttributeAsString($assetContentResource, "assetId");
     }
     return $resource;
 }
Example #27
0
 public static function syndicate(CuePoint $cuePoint, SimpleXMLElement $scenes, SimpleXMLElement $scene = null)
 {
     if (!$cuePoint instanceof ThumbCuePoint) {
         return $scene;
     }
     if (!$scene) {
         $scene = kCuePointManager::syndicateCuePointXml($cuePoint, $scenes->addChild('scene-thumb-cue-point'));
     }
     if ($cuePoint->getEndTime()) {
         $scene->addChild('sceneEndTime', kXml::integerToTime($cuePoint->getEndTime()));
     }
     $scene->addChild('thumbAssetId', $cuePoint->getAssetId());
     return $scene;
 }
 /**
  * @param SimpleXMLElement $scene
  * @return KalturaCuePoint
  */
 protected function parseCuePoint(SimpleXMLElement $scene)
 {
     $cuePoint = $this->getNewInstance();
     if (isset($scene['systemName']) && $scene['systemName']) {
         $cuePoint->systemName = $scene['systemName'] . '';
     }
     $cuePoint->startTime = kXml::timeToInteger($scene->sceneStartTime);
     $tags = array();
     foreach ($scene->tags->children() as $tag) {
         $value = "{$tag}";
         if ($value) {
             $tags[] = $value;
         }
     }
     $cuePoint->tags = implode(',', $tags);
     return $cuePoint;
 }
Example #29
0
 public static function syndicate(CuePoint $cuePoint, SimpleXMLElement $scenes, SimpleXMLElement $scene = null)
 {
     if (!$cuePoint instanceof AdCuePoint) {
         return $scene;
     }
     if (!$scene) {
         $scene = kCuePointManager::syndicateCuePointXml($cuePoint, $scenes->addChild('scene-ad-cue-point'));
     }
     if ($cuePoint->getEndTime()) {
         $scene->addChild('sceneEndTime', kXml::integerToTime($cuePoint->getEndTime()));
     }
     if ($cuePoint->getName()) {
         $scene->addChild('sceneTitle', kMrssManager::stringToSafeXml($cuePoint->getName()));
     }
     if ($cuePoint->getSourceUrl()) {
         $scene->addChild('sourceUrl', htmlspecialchars($cuePoint->getSourceUrl()));
     }
     $scene->addChild('adType', $cuePoint->getAdType());
     $scene->addChild('protocolType', $cuePoint->getSubType());
     return $scene;
 }
Example #30
0
 public function updateFromXSLImpl($id, $xslData)
 {
     $dbMetadataObject = MetadataPeer::retrieveByPK($id);
     if (!$dbMetadataObject) {
         throw new KalturaAPIException(MetadataErrors::METADATA_NOT_FOUND);
     }
     $dbMetadataObjectFileSyncKey = $dbMetadataObject->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA);
     $xsltErrors = array();
     $transformMetadataObjectData = kXml::transformXmlUsingXslt(kFileSyncUtils::file_get_contents($dbMetadataObjectFileSyncKey), $xslData, array(), $xsltErrors);
     if (count($xsltErrors)) {
         throw new KalturaAPIException(MetadataErrors::XSLT_VALIDATION_ERROR, implode(',', $xsltErrors));
     }
     return $this->updateImpl($id, $transformMetadataObjectData);
 }