Пример #1
0
 /**
  * Answer a new MediaAsset that wraps the Asset identified with the passed Ids.
  * 
  * @param object Id $repositoryId
  * @param object Id $assetId
  * @return object MediaAsset
  * @access public
  * @since 4/27/07
  * @static
  */
 public static function withIds($repositoryId, $assetId, $recordId)
 {
     ArgumentValidator::validate($repositoryId, ExtendsValidatorRule::getRule("Id"));
     ArgumentValidator::validate($assetId, ExtendsValidatorRule::getRule("Id"));
     ArgumentValidator::validate($recordId, ExtendsValidatorRule::getRule("Id"));
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($repositoryId);
     $asset = $repository->getAsset($assetId);
     $mediaFile = new MediaFile(MediaAsset::withAsset($asset), $asset->getRecord($recordId));
     return $mediaFile;
 }
 /**
  * Answer an XML representation of a media file.
  * 
  * @param object Asset $asset
  * @param string $parentId
  * @access protected
  */
 protected function recordMediaAsset(Asset $asset, $parentId)
 {
     $mediaAsset = MediaAsset::withAsset($asset);
     if (!$mediaAsset->getFiles()->hasNext()) {
         return;
     }
     $file = $mediaAsset->getFiles()->next();
     $element = $this->channel->insertBefore($this->doc->createElement('item'), $this->endFiles);
     $element->appendChild($this->getElement('title', $mediaAsset->getDisplayName()));
     $element->appendChild($this->getElement('link', $file->getUrl()));
     $element->appendChild($this->getElement('guid', $file->getUrl()))->setAttribute('isPermaLink', 'false');
     $element->appendChild($this->getElement('description', $mediaAsset->getDescription()));
     $element->appendChild($this->getCDATAElementNS("http://wordpress.org/export/1.1/excerpt/", 'excerpt:encoded', $mediaAsset->getDescription()));
     $element->appendChild($this->getElement('pubDate', $mediaAsset->getModificationDate()->format('r')));
     $agentUID = $this->recordAgent($asset->getCreator());
     $element->appendChild($this->getElementNS("http://purl.org/dc/elements/1.1/", 'dc:creator', $agentUID));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_id', $mediaAsset->getId()));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_date', $mediaAsset->getModificationDate()->format('Y-m-d H:i:s')));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_date_gmt', $mediaAsset->getModificationDate()->asUTC()->format('Y-m-d H:i:s')));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_status', 'closed'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:ping_status', 'closed'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:status', 'publish'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_parent', $parentId));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:menu_order', '0'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_type', 'attachment'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_password', ''));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:is_sticky', '0'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:attachment_url', $file->getUrl()));
     // Thumbnail
     $element = $this->channel->insertBefore($this->doc->createElement('item'), $this->endFiles);
     if ($file->getThumbnailMimeType()) {
         $mime = Services::getService("MIME");
         $thumbExtension = $mime->getExtensionForMIMEType($file->getThumbnailMimeType());
     } else {
         $thumbExtension = 'png';
     }
     $element->appendChild($this->getElement('title', $mediaAsset->getDisplayName() . ' - thumbnail'));
     $element->appendChild($this->getElement('link', $file->getThumbnailUrl()));
     $element->appendChild($this->getElement('guid', $file->getThumbnailUrl()))->setAttribute('isPermaLink', 'false');
     $element->appendChild($this->getElement('description', $mediaAsset->getDescription()));
     $element->appendChild($this->getElement('pubDate', $mediaAsset->getModificationDate()->format('r')));
     $agentUID = $this->recordAgent($asset->getCreator());
     $element->appendChild($this->getElementNS("http://purl.org/dc/elements/1.1/", 'dc:creator', $agentUID));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_id', intval($mediaAsset->getId()->getIdString()) + 200000000000));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_date', $mediaAsset->getModificationDate()->format('Y-m-d H:i:s')));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_date_gmt', $mediaAsset->getModificationDate()->asUTC()->format('Y-m-d H:i:s')));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_status', 'closed'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:ping_status', 'closed'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:status', 'publish'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_parent', $parentId));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:menu_order', '0'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_type', 'attachment'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:post_password', ''));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:is_sticky', '0'));
     $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:attachment_url', $file->getThumbnailUrl()));
 }