You are here

class ResourcePublicStreamWrapper in D7 Media 6

public:// stream wrapper class.

This class provides support for storing publicly accessible files with the Drupal resource api.

Hierarchy

Expanded class hierarchy of ResourcePublicStreamWrapper

1 string reference to 'ResourcePublicStreamWrapper'
resource_init in resource/resource.module
Implementation of hook_init().

File

resource/ResourcePublicStreamWrapper.inc, line 9

View source
class ResourcePublicStreamWrapper extends ResourceStreamWrapper {

  // A handle to the file opened by stream_open().
  private $pathKey = 'stream_public_path';
  private $pathDefault = 'sites/default/files';

  /**
   * Return the HTML Url of a public file.
   */
  function htmlUrl($url) {
    $basepath = variable_get($this->pathKey, $this->pathDefault);
    $path = parse_url($url, PHP_URL_PATH);
    return $GLOBALS['base_url'] . '/' . $basepath . '/' . str_replace('\\', '/', $path);
  }

  /**
   * Interpolate the url path, adding the public files path.
   */
  function interpolateUrl($url) {
    $basepath = variable_get($this->pathKey, $this->pathDefault);

    // just in case stream_public_path is s3://, ftp://, etc. Don't call PHP's
    // realpath().
    if (parse_url($basepath, PHP_URL_SCHEME)) {
      $path = $basepath . parse_url($url, PHP_URL_PATH);
    }
    else {

      // interpolate relative paths for basepath, and strip relative paths from
      // url path.
      $path = realpath($basepath) . str_replace('/..', '', parse_url($url, PHP_URL_PATH));
    }
    return $path;
  }

  /**
   * Return the mime type of a file.
   */
  function mime($url) {
    return file_get_mimetype(basename($url));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourcePublicStreamWrapper::$pathDefault private property 1
ResourcePublicStreamWrapper::$pathKey private property 1
ResourcePublicStreamWrapper::htmlUrl function Return the HTML Url of a public file. Overrides ResourceStreamWrapper::htmlUrl 1
ResourcePublicStreamWrapper::interpolateUrl function Interpolate the url path, adding the public files path. Overrides ResourceStreamWrapper::interpolateUrl
ResourcePublicStreamWrapper::mime function Return the mime type of a file. Overrides ResourceStreamWrapper::mime
ResourceStreamWrapper::$handle private property
ResourceStreamWrapper::dir_closedir public function Support for closedir(). Overrides StreamWrapperInterface::dir_closedir
ResourceStreamWrapper::dir_opendir public function Support for opendir(). Overrides StreamWrapperInterface::dir_opendir
ResourceStreamWrapper::dir_readdir public function Support for readdir(). Overrides StreamWrapperInterface::dir_readdir
ResourceStreamWrapper::dir_rewinddir public function Support for rewinddir(). Overrides StreamWrapperInterface::dir_rewinddir
ResourceStreamWrapper::mkdir public function Support for mkdir(). Overrides StreamWrapperInterface::mkdir
ResourceStreamWrapper::rename public function Support for rename(). Overrides StreamWrapperInterface::rename
ResourceStreamWrapper::rmdir public function Support for rmdir(). Overrides StreamWrapperInterface::rmdir
ResourceStreamWrapper::stream_close public function Support for fclose(). Overrides StreamWrapperInterface::stream_close
ResourceStreamWrapper::stream_eof public function Support for feof(). Overrides StreamWrapperInterface::stream_eof
ResourceStreamWrapper::stream_flush public function Support for fflush(). Overrides StreamWrapperInterface::stream_flush
ResourceStreamWrapper::stream_lock function Overrides StreamWrapperInterface::stream_lock
ResourceStreamWrapper::stream_open public function Support for fopen(), file_get_contents(), file_put_contents() etc. Overrides StreamWrapperInterface::stream_open
ResourceStreamWrapper::stream_read public function Support for fread(), file_get_contents() etc. Overrides StreamWrapperInterface::stream_read
ResourceStreamWrapper::stream_seek public function Support for fseek(). Overrides StreamWrapperInterface::stream_seek
ResourceStreamWrapper::stream_stat public function Support for fstat(). Overrides StreamWrapperInterface::stream_stat
ResourceStreamWrapper::stream_tell public function Support for ftell(). Overrides StreamWrapperInterface::stream_tell
ResourceStreamWrapper::stream_write public function Support for fwrite(), file_put_contents() etc. Overrides StreamWrapperInterface::stream_write
ResourceStreamWrapper::unlink public function Support for unlink(). Overrides StreamWrapperInterface::unlink
ResourceStreamWrapper::url_stat public function Support for stat(). Overrides StreamWrapperInterface::url_stat