Exemple #1
0
 /**
  * @param asset $asset
  * @param string $class
  * @param string $encodingProfile
  * @param string $duration
  * @param string $url
  */
 protected function createEnclosureXml(asset $asset, $class, $encodingProfile, $duration)
 {
     /**
      * 
      * In QuickPlay's XML example, the namespace "http://www.quickplaymedia.com" is added to the "enclosure" 
      * element regardless to the fact that it was registerted with the prefix "qpm" on the root element.
      * We cannot set a namespace that was already defined with a prefix because DOMDocument will add the element
      * as "qpm:enclosure" and won't set the namespace explicitly.
      * 
      * The hack is to create a new KDOMDocument with default namespace "http://www.quickplaymedia.com" and then
      * add it to the xml manually (see getXml() method)
      * 
      */
     $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     $contentNode = $this->_enclosureNode->cloneNode(true);
     kXml::setNodeValue($this->_xpath, '@encodingProfile', $encodingProfile, $contentNode);
     $url = $this->getAssetUrl($asset);
     $mimeType = $this->getContentTypeFromUrl($url);
     $enclosureDoc = new KDOMDocument();
     $enclosureElement = $enclosureDoc->createElementNS('http://www.quickplaymedia.com', 'enclosure');
     $xmlElement = $enclosureDoc->createElement('xml');
     $enclosureDoc->appendChild($xmlElement);
     $enclosureNode = $enclosureDoc->importNode($contentNode, true);
     $enclosureNode->setAttribute('class', $class);
     $link = $enclosureNode->getElementsByTagName('link')->item(0);
     $link->setAttribute('type', $mimeType);
     $link->setAttribute('length', $fileSync->getFileSize());
     $link->setAttribute('duration', $duration);
     $link->setAttribute('url', pathinfo($fileSync->getFilePath(), PATHINFO_BASENAME));
     $xmlElement->appendChild($enclosureNode);
     return $enclosureDoc->saveXML($enclosureNode);
 }