public function checkIsLive($url)
 {
     KalturaLog::info('url to check:' . $url);
     $parts = parse_url($url);
     parse_str($parts['query'], $query);
     $token = $query[$this->getParamName()];
     $data = $this->urlExists($url, array($this->getHdsManifestContentType()));
     if (!$data) {
         KalturaLog::Info("URL [{$url}] returned no valid data. Exiting.");
         return false;
     }
     KalturaLog::info('Velocix HDS manifest data:' . $data);
     $dom = new KDOMDocument();
     $dom->loadXML($data);
     $element = $dom->getElementsByTagName('baseURL')->item(0);
     if (!$element) {
         KalturaLog::Info("No base url was given");
         return false;
     }
     $baseUrl = $element->nodeValue;
     foreach ($dom->getElementsByTagName('media') as $media) {
         $href = $media->getAttribute('href');
         $streamUrl = $baseUrl . $href;
         $streamUrl .= $token ? '?' . $this->getParamName() . "={$token}" : '';
         if ($this->urlExists($streamUrl, array(), '0-0') !== false) {
             KalturaLog::info('is live:' . $streamUrl);
             return true;
         }
     }
     return false;
 }
 /**
  * Allows you to add a metadata profile object and metadata profile content associated with Kaltura object type
  * 
  * @action add
  * @param KalturaMetadataProfile $metadataProfile
  * @param string $xsdData XSD metadata definition
  * @param string $viewsData UI views definition
  * @return KalturaMetadataProfile
  */
 function addAction(KalturaMetadataProfile $metadataProfile, $xsdData, $viewsData = null)
 {
     // validates the xsd
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xml = new KDOMDocument();
     if (!$xml->loadXML($xsdData)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xsdData);
         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(), $xsdData, false, $metadataProfile->metadataObjectType);
     $dbMetadataProfile = $metadataProfile->toInsertableObject();
     $dbMetadataProfile->setStatus(KalturaMetadataProfileStatus::ACTIVE);
     $dbMetadataProfile->setPartnerId($this->getPartnerId());
     $dbMetadataProfile->save();
     $xsdData = html_entity_decode($xsdData);
     $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION);
     kFileSyncUtils::file_put_contents($key, $xsdData);
     if ($viewsData) {
         $viewsData = html_entity_decode($viewsData);
         $key = $dbMetadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_VIEWS);
         kFileSyncUtils::file_put_contents($key, $viewsData);
     }
     kMetadataManager::parseProfileSearchFields($this->getPartnerId(), $dbMetadataProfile);
     $metadataProfile = new KalturaMetadataProfile();
     $metadataProfile->fromObject($dbMetadataProfile);
     return $metadataProfile;
 }
 public function apply(KalturaRelatedFilter $filter, KalturaObject $parentObject)
 {
     $filterProperty = $this->filterProperty;
     $parentProperty = $this->parentProperty;
     KalturaLog::debug("Mapping XPath {$parentProperty} to " . get_class($filter) . "::{$filterProperty}");
     if (!$parentObject instanceof KalturaMetadata) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_TYPE, get_class($parentObject));
     }
     if (!property_exists($filter, $filterProperty)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_IS_NOT_DEFINED, $filterProperty, get_class($filter));
     }
     $xml = $parentObject->xml;
     $doc = new KDOMDocument();
     $doc->loadXML($xml);
     $xpath = new DOMXPath($doc);
     $metadataElements = $xpath->query($parentProperty);
     if ($metadataElements->length == 1) {
         $filter->{$filterProperty} = $metadataElements->item(0)->nodeValue;
     } elseif ($metadataElements->length > 1) {
         $values = array();
         foreach ($metadataElements as $element) {
             $values[] = $element->nodeValue;
         }
         $filter->{$filterProperty} = implode(',', $values);
     } elseif (!$this->allowNull) {
         return false;
     }
     return true;
 }
예제 #4
0
 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;
 }
예제 #5
0
 public function checkIsLive($url)
 {
     $data = $this->urlExists($url, array('video/f4m'));
     if (is_bool($data)) {
         return $data;
     }
     $element = new KDOMDocument();
     $element->loadXML($data);
     $streamType = $element->getElementsByTagName('streamType')->item(0);
     if ($streamType->nodeValue == 'live') {
         return true;
     }
     return false;
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     if (!$puser_kuser) {
         $this->addError(APIErrors::INVALID_USER_ID, $puser_id);
         return;
     }
     $entry_id = $this->getPM("entry_id");
     $entry = entryPeer::retrieveByPK($entry_id);
     // TODO - verify the user is allowed to modify the entry
     $source_entry_id = $this->getP("source_entry_id");
     if ($source_entry_id) {
         $source_entry = entryPeer::retrieveByPK($source_entry_id);
         if (!$source_entry) {
             return;
         }
     } else {
         $source_entry = $entry;
     }
     $time_offset = $this->getP("time_offset", -1);
     if (!myEntryUtils::createThumbnailFromEntry($entry, $source_entry, $time_offset)) {
         $this->addError(APIErrors::INVALID_ENTRY_TYPE, "ENTRY_TYPE_MEDIACLIP");
         return;
     }
     if ($entry->getType() == entryType::MIX) {
         /*			
         		$roughcutPath = myContentStorage::getFSContentRootPath() . $entry->getDataPath(); // replaced__getDataPath
         		$xml_doc = new KDOMDocument();
         		$xml_doc->load( $roughcutPath );
         	
         		if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getThumbnailUrl()))
         			$xml_doc->save($roughcutPath);
         */
         $sync_key = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         $xml_doc = new KDOMDocument();
         $xml_doc->loadXML(kFileSyncUtils::file_get_contents($sync_key));
         if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getThumbnailUrl())) {
             $entry->setMetadata(null, $xml_doc->saveXML(), true, null, null);
             //$entry->getVersion() );
         }
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE_THUMBNAIL, $entry);
     }
     $wrapper = objectWrapperBase::getWrapperClass($entry, objectWrapperBase::DETAIL_LEVEL_DETAILED);
     $wrapper->removeFromCache("entry", $entry->getId());
     $this->addMsg("entry", $wrapper);
 }
 public function loadProperties(KalturaDistributionJobData $distributionJobData, KalturaGenericDistributionProfile $distributionProfile, $action)
 {
     $actionName = self::$actionAttributes[$action];
     $genericProviderAction = GenericDistributionProviderActionPeer::retrieveByProviderAndAction($distributionProfile->genericProviderId, $action);
     if (!$genericProviderAction) {
         KalturaLog::err("Generic provider [{$distributionProfile->genericProviderId}] action [{$actionName}] not found");
         return;
     }
     if (!$distributionJobData->entryDistribution) {
         KalturaLog::err("Entry Distribution object not provided");
         return;
     }
     if (!$distributionProfile->{$actionName}->protocol) {
         $distributionProfile->{$actionName}->protocol = $genericProviderAction->getProtocol();
     }
     if (!$distributionProfile->{$actionName}->serverUrl) {
         $distributionProfile->{$actionName}->serverUrl = $genericProviderAction->getServerAddress();
     }
     if (!$distributionProfile->{$actionName}->serverPath) {
         $distributionProfile->{$actionName}->serverPath = $genericProviderAction->getRemotePath();
     }
     if (!$distributionProfile->{$actionName}->username) {
         $distributionProfile->{$actionName}->username = $genericProviderAction->getRemoteUsername();
     }
     if (!$distributionProfile->{$actionName}->password) {
         $distributionProfile->{$actionName}->password = $genericProviderAction->getRemotePassword();
     }
     if (!$distributionProfile->{$actionName}->ftpPassiveMode) {
         $distributionProfile->{$actionName}->ftpPassiveMode = $genericProviderAction->getFtpPassiveMode();
     }
     if (!$distributionProfile->{$actionName}->httpFieldName) {
         $distributionProfile->{$actionName}->httpFieldName = $genericProviderAction->getHttpFieldName();
     }
     if (!$distributionProfile->{$actionName}->httpFileName) {
         $distributionProfile->{$actionName}->httpFileName = $genericProviderAction->getHttpFileName();
     }
     $entry = entryPeer::retrieveByPKNoFilter($distributionJobData->entryDistribution->entryId);
     if (!$entry) {
         KalturaLog::err("Entry [" . $distributionJobData->entryDistribution->entryId . "] not found");
         return;
     }
     $mrss = kMrssManager::getEntryMrss($entry);
     if (!$mrss) {
         KalturaLog::err("MRSS not returned for entry [" . $entry->getId() . "]");
         return;
     }
     $xml = new KDOMDocument();
     if (!$xml->loadXML($mrss)) {
         KalturaLog::err("MRSS not is not valid XML:\n{$mrss}\n");
         return;
     }
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_MRSS_TRANSFORMER);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $xslPath = kFileSyncUtils::getLocalFilePathForKey($key);
         if ($xslPath) {
             $xsl = new KDOMDocument();
             $xsl->load($xslPath);
             // set variables in the xsl
             $varNodes = $xsl->getElementsByTagName('variable');
             foreach ($varNodes as $varNode) {
                 $nameAttr = $varNode->attributes->getNamedItem('name');
                 if (!$nameAttr) {
                     continue;
                 }
                 $name = $nameAttr->value;
                 if ($name && $distributionJobData->{$name}) {
                     $varNode->textContent = $distributionJobData->{$name};
                     $varNode->appendChild($xsl->createTextNode($distributionJobData->{$name}));
                 }
             }
             $proc = new XSLTProcessor();
             $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
             $proc->importStyleSheet($xsl);
             $xml = $proc->transformToDoc($xml);
             if (!$xml) {
                 KalturaLog::err("Transform returned false");
                 return;
             }
         }
     }
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_MRSS_VALIDATOR);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $xsdPath = kFileSyncUtils::getLocalFilePathForKey($key);
         if ($xsdPath && !$xml->schemaValidate($xsdPath)) {
             KalturaLog::err("Inavlid XML:\n" . $xml->saveXML());
             KalturaLog::err("Schema [{$xsdPath}]:\n" . file_get_contents($xsdPath));
             return;
         }
     }
     $this->xml = $xml->saveXML();
     $key = $genericProviderAction->getSyncKey(GenericDistributionProviderAction::FILE_SYNC_DISTRIBUTION_PROVIDER_ACTION_RESULTS_TRANSFORMER);
     if (kFileSyncUtils::fileSync_exists($key)) {
         $this->resultParseData = kFileSyncUtils::file_get_contents($key, true, false);
     }
     $this->resultParserType = $genericProviderAction->getResultsParser();
 }
예제 #8
0
 public static function modifiedByKeditor($content)
 {
     $xml_doc = new KDOMDocument();
     $xml_doc->loadXML($content);
     $xpath = new DOMXPath($xml_doc);
     $metadata_elem = $xpath->query("//Metadata");
     $modified_by_keditor_list = $metadata_elem->getElementsByTagName("Modified");
     if ($modified_by_keditor_list != null && $modified_by_keditor_list->length > 0) {
         $modified_by_keditor = $modified_by_keditor_list->item(0)->nodeValue;
         return $content;
         //$modified_by_keditor->setValue
     } else {
         $newTextNode = $xml_doc->createTextNode("keditor");
         $modified = $xml_doc->createElement("Modified");
         //, "keditor" );
         $modified->appendChild($newTextNode);
         $metadata_elem->appendChild($modified);
     }
     return $xml_doc->saveXML();
 }
예제 #9
0
 /**
  * @param string $xml
  * @param string $xslt
  * @param array $xsltParams
  * @return string  
  */
 public static function transformXmlUsingXslt($xmlStr, $xslt, $xsltParams = array(), &$xsltErrors = array())
 {
     $xml = new KDOMDocument();
     if (!$xml->loadXML($xmlStr)) {
         KalturaLog::debug("Could not load xmlStr");
         return null;
     }
     $xsl = new KDOMDocument();
     if (!$xsl->loadXML($xslt)) {
         KalturaLog::debug("Could not load xslt");
         return null;
     }
     $proc = new XSLTProcessor();
     foreach ($xsltParams as $key => $value) {
         $proc->setParameter('', $key, $value);
     }
     $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
     @$proc->importStyleSheet($xsl);
     $errorHandler = new XSLTErrorCollector();
     $xml = @$proc->transformToDoc($xml);
     $errorHandler->restoreErrorHandler();
     $xsltErrors = $errorHandler->errors;
     if (!$xml) {
         KalturaLog::err("XML Transformation failed");
         return null;
     }
     if (isset($xml->documentElement)) {
         $xml->documentElement->removeAttributeNS('http://php.net/xsl', 'php');
     }
     return $xml->saveXML();
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $kshowId = $this->getP("kshow_id");
     $numberOfVersions = $this->getP("number_of_versions", 5);
     // must be int and not more than 50
     $numberOfVersions = (int) $numberOfVersions;
     $numberOfVersions = min($numberOfVersions, 50);
     $kshow = kshowPeer::retrieveByPK($kshowId);
     if (!$kshow) {
         $this->addError(APIErrors::KSHOW_DOES_NOT_EXISTS);
         return;
     }
     $showEntry = $kshow->getShowEntry();
     if (!$showEntry) {
         $this->addError(APIErrors::ROUGHCUT_NOT_FOUND);
         return;
     }
     $sync_key = $showEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
     $showEntryDataPath = kFileSyncUtils::getLocalFilePathForKey($sync_key);
     $versionsInfoFilePath = $showEntryDataPath . '.info';
     $lastVersionDoc = new KDOMDocument();
     $lastVersionDoc->loadXML(kFileSyncUtils::file_get_contents($sync_key, true, false));
     $lastVersion = myContentStorage::getVersion($showEntryDataPath);
     // check if we need to refresh the data in the info file
     $refreshInfoFile = true;
     if (file_exists($versionsInfoFilePath)) {
         $versionsInfoDoc = new KDOMDocument();
         $versionsInfoDoc->load($versionsInfoFilePath);
         $lastVersionInInfoFile = kXml::getLastElementAsText($versionsInfoDoc, "ShowVersion");
         if ($lastVersionInInfoFile && $lastVersion == $lastVersionInInfoFile) {
             $refreshInfoFile = false;
         } else {
             $refreshInfoFile = true;
         }
     } else {
         $refreshInfoFile = true;
     }
     // refresh or create the data in the info file
     if ($refreshInfoFile) {
         $versionsInfoDoc = new KDOMDocument();
         $xmlElement = $versionsInfoDoc->createElement("xml");
         // start from the first edited version (100001) and don't use 100000
         for ($i = myContentStorage::MIN_OBFUSCATOR_VALUE + 1; $i <= $lastVersion; $i++) {
             $version_sync_key = $showEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA, $i);
             if (kFileSyncUtils::file_exists($version_sync_key, false)) {
                 $xmlContent = kFileSyncUtils::file_get_contents($version_sync_key);
                 //echo "[" . htmlspecialchars( $xmlContent ) . "]<br>";
                 $xmlDoc = new KDOMDocument();
                 $xmlDoc->loadXML($xmlContent);
                 $elementToCopy = kXml::getFirstElement($xmlDoc, "MetaData");
                 //echo "[$i]";
                 $elementCloned = $elementToCopy->cloneNode(true);
                 $elementImported = $versionsInfoDoc->importNode($elementCloned, true);
                 $xmlElement->appendChild($elementImported);
             }
         }
         $versionsInfoDoc->appendChild($xmlElement);
         kFile::setFileContent($versionsInfoFilePath, $versionsInfoDoc->saveXML());
         // FileSync OK - created a temp file on DC's disk
     }
     $metadataNodes = $versionsInfoDoc->getElementsByTagName("MetaData");
     $count = 0;
     $versionsInfo = array();
     for ($i = $metadataNodes->length - 1; $i >= 0; $i--) {
         $metadataNode = $metadataNodes->item($i);
         $node = kXml::getFirstElement($metadataNode, "ShowVersion");
         $showVersion = $node ? $node->nodeValue : "";
         $node = kXml::getFirstElement($metadataNode, "PuserId");
         $puserId = $node ? $node->nodeValue : "";
         $node = kXml::getFirstElement($metadataNode, "ScreenName");
         $screenName = $node ? $node->nodeValue : "";
         $node = kXml::getFirstElement($metadataNode, "UpdatedAt");
         $updatedAt = $node ? $node->nodeValue : "";
         $versionsInfo[] = array("version" => $showVersion, "puserId" => $puserId, "screenName" => $screenName, "updatedAt" => $updatedAt);
         $count++;
         if ($count >= $numberOfVersions) {
             break;
         }
     }
     $this->addMsg("show_versions", $versionsInfo);
 }
예제 #11
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;
 }
예제 #12
0
 public function getContent($content)
 {
     $xml = new KDOMDocument();
     try {
         $xml->loadXML($content);
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
         return null;
     }
     return trim(preg_replace('/\\s+/', ' ', $xml->textContent));
 }
 public function addItemXml($xml)
 {
     $tempDoc = new KDOMDocument('1.0', 'UTF-8');
     $tempDoc->loadXML($xml);
     $importedItem = $this->doc->importNode($tempDoc->firstChild, true);
     $channelNode = $this->xpath->query('/rss/channel')->item(0);
     $channelNode->appendChild($importedItem);
 }
예제 #14
0
 protected function getOriginalOrTransformIfNeeded(DropFolder $folder, $xmlPath)
 {
     if (!file_exists($xmlPath) || !filesize($xmlPath)) {
         throw new Exception('Empty file supplied as input');
     }
     if (!$folder->getConversionProfileId()) {
         KalturaLog::debug('No conversion profile found on drop folder [' . $folder->getId() . '] assuming no xsl transformation is needed');
         return file_get_contents($xmlPath);
     }
     $conversionProfile = conversionProfile2Peer::retrieveByPK($folder->getConversionProfileId());
     if (!$conversionProfile || strlen($conversionProfile->getXsl()) == 0) {
         KalturaLog::debug('No conversion profile found Or no xsl transform found');
         return file_get_contents($xmlPath);
     }
     $originalXmlDoc = file_get_contents($xmlPath);
     $origianlXml = new KDOMDocument();
     if (!$origianlXml->loadXML($originalXmlDoc)) {
         KalturaLog::debug('Could not load original xml');
         $errorMessage = kXml::getLibXmlErrorDescription($originalXmlDoc);
         throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE));
     }
     libxml_clear_errors();
     $proc = new XSLTProcessor();
     $xsl = new KDOMDocument();
     if (!$xsl->loadXML($conversionProfile->getXsl())) {
         KalturaLog::debug('Could not load xsl ' . $conversionProfile->getXsl());
         $errorMessage = kXml::getLibXmlErrorDescription($conversionProfile->getXsl());
         throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE));
     }
     $proc->importStyleSheet($xsl);
     libxml_clear_errors();
     $transformedXml = $proc->transformToXML($origianlXml);
     if (!$transformedXml) {
         KalturaLog::debug('Could not transform xml ' . $conversionProfile->getXsl());
         $errorMessage = kXml::getLibXmlErrorDescription($conversionProfile->getXsl());
         throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE));
     }
     $xmlDoc = new KDOMDocument();
     $res = $xmlDoc->loadXML($transformedXml);
     if (!$res) {
         throw new Exception(DropFolderXmlBulkUploadPlugin::MALFORMED_XML_FILE_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::MALFORMED_XML_FILE));
     }
     return $transformedXml;
 }
 /**
  * @param string $entryId
  * @param KalturaIdeticDistributionJobProviderData $providerData
  * @return DOMDocument
  */
 public static function generateXML($entryId, KalturaIdeticDistributionJobProviderData $providerData)
 {
     $entry = entryPeer::retrieveByPKNoFilter($entryId);
     $mrss = kMrssManager::getEntryMrss($entry);
     if (!$mrss) {
         KalturaLog::err("No MRSS returned for entry [{$entryId}]");
         return null;
     }
     $xml = new KDOMDocument();
     if (!$xml->loadXML($mrss)) {
         KalturaLog::err("Could not load MRSS as XML for entry [{$entryId}]");
         return null;
     }
     $xslPath = realpath(dirname(__FILE__) . '/../') . '/xml/submit.xsl';
     if (!file_exists($xslPath)) {
         KalturaLog::err("XSL file not found [{$xslPath}]");
         return null;
     }
     $xsl = new KDOMDocument();
     $xsl->load($xslPath);
     // set variables in the xsl
     $varNodes = $xsl->getElementsByTagName('variable');
     foreach ($varNodes as $varNode) {
         $nameAttr = $varNode->attributes->getNamedItem('name');
         if (!$nameAttr) {
             continue;
         }
         $name = $nameAttr->value;
         if ($name && $providerData->{$name}) {
             $varNode->textContent = $providerData->{$name};
             $varNode->appendChild($xsl->createTextNode($providerData->{$name}));
             KalturaLog::debug("Set variable [{$name}] to [{$providerData->{$name}}]");
         }
     }
     $proc = new XSLTProcessor();
     $proc->registerPHPFunctions();
     $proc->importStyleSheet($xsl);
     $xml = $proc->transformToDoc($xml);
     if (!$xml) {
         KalturaLog::err("XML Transformation failed");
         return null;
     }
     // TODO create validation XSD
     $xsdPath = realpath(dirname(__FILE__) . '/../') . '/xml/submit.xsd';
     if (file_exists($xsdPath) && !$xml->schemaValidate($xsdPath)) {
         KalturaLog::err("Schema validation failed");
         return null;
     }
     return $xml;
 }
예제 #16
0
 /**
  * Validate the XML against the profile XSD and set the metadata status
  *
  * @param int $metadataProfileId
  * @param string $metadata
  * @param string $errorMessage
  * @param int $compareAgainstPreviousVersion leave it false to use the latest metadata profile version
  *
  * returns bool
  */
 public static function validateMetadata($metadataProfileId, $metadata, &$errorMessage, $compareAgainstPreviousVersion = false)
 {
     KalturaLog::debug("Validating metadata [{$metadata}]");
     $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId);
     if (!$metadataProfile) {
         $errorMessage = "Metadata profile [{$metadataProfileId}] not found";
         KalturaLog::err($errorMessage);
         return false;
     }
     $metadataProfileFSVersion = null;
     if ($compareAgainstPreviousVersion) {
         $metadataProfileFSVersion = $metadataProfile->getPreviousFileSyncVersion();
     }
     $metadataProfileKey = $metadataProfile->getSyncKey(MetadataProfile::FILE_SYNC_METADATA_DEFINITION, $metadataProfileFSVersion);
     $xsdData = kFileSyncUtils::file_get_contents($metadataProfileKey, true, false);
     if (!$xsdData) {
         $errorMessage = "Metadata profile xsd not found";
         KalturaLog::err($errorMessage);
         return false;
     }
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xml = new KDOMDocument();
     $xml->loadXML($metadata);
     if ($xml->schemaValidateSource($xsdData)) {
         if (!self::validateMetadataObjects($metadataProfileId, $xml, $errorMessage)) {
             KalturaLog::err($errorMessage);
             return false;
         }
         KalturaLog::debug("Metadata is valid");
         return true;
     }
     $errorMessage = kXml::getLibXmlErrorDescription($metadata);
     KalturaLog::err("Metadata is invalid:\n{$errorMessage}");
     return false;
 }
 /**
  * @param string $xsdPath
  * @param string $appInfoField
  * @param string $appInfoValue
  * @return array of xPaths
  */
 public static function findXpathsByAppInfo($xsdPath, $appInfoField, $appInfoValue, $isPath = true)
 {
     $xsd = new KDOMDocument();
     if ($isPath) {
         $xsd->load($xsdPath);
     } else {
         $xsd->loadXML($xsdPath);
     }
     $xPaths = array();
     $appInfos = $xsd->getElementsByTagName('appinfo');
     foreach ($appInfos as $appInfo) {
         $fields = $appInfo->getElementsByTagName($appInfoField);
         $found = false;
         foreach ($fields as $field) {
             if ($field->nodeValue == $appInfoValue) {
                 $found = true;
             }
         }
         if (!$found) {
             continue;
         }
         $name = self::getXsdElementName($appInfo);
         $type = self::getXsdNodeType($appInfo);
         $xPath = self::getXsdXpath($appInfo);
         $data = array();
         if ($name) {
             $data['name'] = $name;
         }
         if ($type) {
             $data['type'] = $type;
         }
         foreach ($appInfo->childNodes as $childNode) {
             if ($childNode->nodeType == XML_TEXT_NODE || $childNode->nodeType == XML_COMMENT_NODE) {
                 continue;
             }
             $data[$childNode->localName] = $childNode->nodeValue;
         }
         $xPaths[$xPath] = $data;
     }
     return $xPaths;
 }
예제 #18
0
 /**
  * Transform Xml file with conversion profile xsl
  * If xsl is not found, original Xml returned
  * @param string $filePath the original xml that was taken from partner file path
  * @return string - transformed Xml
  */
 protected function xslTransform($filePath)
 {
     $xdoc = file_get_contents($filePath);
     if (is_null($xdoc) || is_null($this->conversionProfileXsl)) {
         return $xdoc;
     }
     libxml_clear_errors();
     $xml = new KDOMDocument();
     if (!$xml->loadXML($xdoc)) {
         KalturaLog::debug("Could not load xml");
         $errorMessage = kXml::getLibXmlErrorDescription($xdoc);
         throw new KalturaBatchException("Could not load xml [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     libxml_clear_errors();
     $proc = new XSLTProcessor();
     $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
     $xsl = new KDOMDocument();
     if (!$xsl->loadXML($this->conversionProfileXsl)) {
         KalturaLog::debug("Could not load xsl" . $this->conversionProfileXsl);
         $errorMessage = kXml::getLibXmlErrorDescription($this->conversionProfileXsl);
         throw new KalturaBatchException("Could not load xsl [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     $proc->importStyleSheet($xsl);
     libxml_clear_errors();
     $transformedXml = $proc->transformToXML($xml);
     if (!$transformedXml) {
         KalturaLog::debug("Could not transform xml" . $this->conversionProfileXsl);
         $errorMessage = kXml::getLibXmlErrorDescription($this->conversionProfileXsl);
         throw new KalturaBatchException("Could not transform xml [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     return $transformedXml;
 }
예제 #19
0
파일: AvnFeed.php 프로젝트: DBezemer/server
 /**
  * @param string $xsd
  * @return array
  */
 protected function getAvnCategoriesFromXsd($xsd)
 {
     $categories = array();
     $doc = new KDOMDocument();
     $doc->loadXML($xsd);
     $xpath = new DOMXPath($doc);
     $xpath->registerNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');
     $categoryNodes = $xpath->query("//xsd:element[@name='AVNCategory']/xsd:simpleType/xsd:restriction[@base='listType']/xsd:enumeration/@value");
     foreach ($categoryNodes as $categoryNode) {
         $categories[] = $categoryNode->nodeValue;
     }
     return $categories;
 }