You are here

class MediaFeedsRemoteProvider in Media Feeds 7

Same name and namespace in other branches
  1. 7.2 includes/MediaFeedsRemoteProvider.inc \MediaFeedsRemoteProvider

Class for mapping values using the remote_stream_wrapper_module.

Hierarchy

Expanded class hierarchy of MediaFeedsRemoteProvider

File

includes/MediaFeedsRemoteProvider.inc, line 11
Map files using the remote_stream_wrapper module.

View source
class MediaFeedsRemoteProvider extends MediaFeedsProvider {
  protected $uri;

  /**
   * The value is the remote URI.
   */
  public function __construct($value, $config = array()) {
    $this->uri = file_stream_wrapper_uri_normalize($value);
  }

  /**
   * Create a file object like remote_stream_wrapper_file_create_by_uri does,
   * only don't save it directly.
   */
  public function getFileObject() {
    $file = new stdClass();
    $file->fid = NULL;
    $file->uri = $this->uri;
    $file->filename = basename($file->uri);
    $file->filemime = file_get_mimetype($file->uri);
    $file->uid = $GLOBALS['user']->uid;
    $file->status = FILE_STATUS_PERMANENT;
    return $file;
  }

  /**
   * Save the file or return an existing one.
   */
  public function save() {

    // Make sure no file with tha URI exists.
    $existing = remote_stream_wrapper_file_load_by_uri($this->uri);
    if ($existing) {
      return $existing;
    }

    // Save the file.
    $file = $this
      ->getFileObject();
    file_save($file);
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaFeedsProvider::$config protected property An associative array of configuration options.
MediaFeedsProvider::$entity protected property The target entity.
MediaFeedsProvider::$source protected property The FeedsSource.
MediaFeedsProvider::$target protected property The target name.
MediaFeedsProvider::$value protected property The values to save.
MediaFeedsProvider::validate public function Validate the source value. 1
MediaFeedsRemoteProvider::$uri protected property
MediaFeedsRemoteProvider::getFileObject public function Create a file object like remote_stream_wrapper_file_create_by_uri does, only don't save it directly. Overrides MediaFeedsProvider::getFileObject
MediaFeedsRemoteProvider::save public function Save the file or return an existing one. Overrides MediaFeedsProvider::save
MediaFeedsRemoteProvider::__construct public function The value is the remote URI. Overrides MediaFeedsProvider::__construct