? stream_wrapper_getTarget.701358.11.patch
? sites/default/files
? sites/default/private
? sites/default/settings.php
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.204
diff -u -p -r1.204 file.inc
--- includes/file.inc	30 Jan 2010 02:01:41 -0000	1.204
+++ includes/file.inc	1 Feb 2010 17:18:43 -0000
@@ -197,29 +197,6 @@ function file_stream_wrapper_valid_schem
 }
 
 /**
- * Returns the target of a URI (e.g. a stream).
- *
- * @param $uri
- *   A stream, referenced as "scheme://target".
- * @return
- *   A string containing the target (path), or FALSE if none.
- *   For example, the URI "public://sample/test.txt" would return
- *   "sample/test.txt".
- */
-function file_uri_target($uri) {
-  $data = explode('://', $uri, 2);
-
-  if (count($data) != 2) {
-    return FALSE;
-  }
-
-  // Remove erroneous beginning forward slash.
-  $data[1] = ltrim($data[1], '\/');
-
-  return $data[1];
-}
-
-/**
  * Normalizes a URI by making it syntactically correct.
  *
  * A stream is referenced as "scheme://target".
@@ -238,10 +215,11 @@ function file_stream_wrapper_uri_normali
   $scheme = file_uri_scheme($uri);
 
   if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
-    $target = file_uri_target($uri);
+    $instance = file_stream_wrapper_get_instance_by_scheme($scheme);
+    $target = $instance->getTarget($uri);
 
     // Remove all occurrences of the wrapper's directory path.
-    $directory_path = file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath();
+    $directory_path = $instance->getDirectoryPath();
     $target = str_replace($directory_path, '', $target);
 
     // Trim trailing slashes from target.
@@ -1858,7 +1836,8 @@ function drupal_dirname($uri) {
   $scheme = file_uri_scheme($uri);
 
   if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
-    $target  = file_uri_target($uri);
+    $instance = file_stream_wrapper_get_instance_by_scheme($scheme);
+    $target = $instance->getTarget($uri);
     $dirname = dirname($target);
 
     if ($dirname == '.') {
Index: includes/stream_wrappers.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/stream_wrappers.inc,v
retrieving revision 1.11
diff -u -p -r1.11 stream_wrappers.inc
--- includes/stream_wrappers.inc	29 Jan 2010 22:40:41 -0000	1.11
+++ includes/stream_wrappers.inc	1 Feb 2010 17:18:43 -0000
@@ -146,6 +146,19 @@ interface DrupalStreamWrapperInterface e
   public function getExternalUrl();
 
   /**
+   * Returns the local target of the resource within the stream.
+   *
+   * @param $uri
+   *   Optional URI.
+   *
+   * @return
+   *  Returns a string representing the physical location of the file or
+   *  resource as it is referenced within the stream, or FALSE if that
+   *  information is inaccessible or irrelevant.
+   */
+  public function getTarget($uri = NULL);
+
+  /**
    * Returns the MIME type of the resource.
    *
    * @param $uri
@@ -248,6 +261,22 @@ abstract class DrupalLocalStreamWrapper 
   }
 
   /**
+   *  Base implementation of getTarget().
+   */
+  function getTarget($uri = NULL) {
+    if (!isset($uri)) {
+      $uri = $this->uri;
+    }
+
+    $data = explode('://', $uri, 2);
+
+    // Remove erroneous beginning forward slash.
+    $data[1] = ltrim($data[1], '\/');
+
+    return $data[1];
+  }
+
+  /**
    * Base implementation of getMimeType().
    */
   static function getMimeType($uri, $mapping = NULL) {
@@ -303,7 +332,7 @@ abstract class DrupalLocalStreamWrapper 
     if (!isset($uri)) {
       $uri = $this->uri;
     }
-    $path = $this->getDirectoryPath() . '/' . file_uri_target($uri);
+    $path = $this->getDirectoryPath() . '/' . $this->getTarget($uri);
     $realpath = realpath($path);
     if (!$realpath) {
       // This file does not yet exist.
@@ -510,7 +539,7 @@ abstract class DrupalLocalStreamWrapper 
     if ($recursive) {
       // $this->getLocalPath() fails if $uri has multiple levels of directories
       // that do not yet exist.
-      $localpath = $this->getDirectoryPath() . '/' . file_uri_target($uri);
+      $localpath = $this->getDirectoryPath() . '/' . $this->getTarget($uri);
     }
     else {
       $localpath = $this->getLocalPath($uri);
@@ -638,7 +667,7 @@ class DrupalPublicStreamWrapper extends 
    * Return the HTML URI of a public file.
    */
   function getExternalUrl() {
-    $path = str_replace('\\', '/', file_uri_target($this->uri));
+    $path = str_replace('\\', '/', $this->getTarget());
     return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . drupal_encode_path($path);
   }
 }
@@ -666,7 +695,7 @@ class DrupalPrivateStreamWrapper extends
    * Return the HTML URI of a private file.
    */
   function getExternalUrl() {
-    $path = str_replace('\\', '/', file_uri_target($this->uri));
+    $path = str_replace('\\', '/', $this->getTarget());
     return url('system/files/' . $path, array('absolute' => TRUE));
   }
 }
@@ -691,7 +720,7 @@ class DrupalTemporaryStreamWrapper exten
    * Overrides getExternalUrl().
    */
   public function getExternalUrl() {
-    $path = str_replace('\\', '/', file_uri_target($this->uri));
+    $path = str_replace('\\', '/', $this->getTarget());
     return url('system/temporary/' . $path, array('absolute' => TRUE));
   }
 }
Index: modules/image/image.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.module,v
retrieving revision 1.32
diff -u -p -r1.32 image.module
--- modules/image/image.module	1 Feb 2010 07:08:49 -0000	1.32
+++ modules/image/image.module	1 Feb 2010 17:18:43 -0000
@@ -245,7 +245,8 @@ function image_flush_caches() {
  * Control the access to files underneath the styles directory.
  */
 function image_file_download($uri) {
-  $path = file_uri_target($uri);
+  $scheme = file_uri_scheme($uri);
+  $path = file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($uri);
 
   // Private file access for image style derivatives.
   if (strpos($path, 'styles/') === 0) {
@@ -255,7 +256,7 @@ function image_file_download($uri) {
     // Get the style name from the second part.
     $style_name = array_shift($args);
     // Then the remaining parts are the path to the image.
-    $original_uri = file_uri_scheme($uri) . '://' . implode('/', $args);
+    $original_uri = $scheme . '://' . implode('/', $args);
 
     // Check that the file exists and is an image.
     if ($info = image_get_info($uri)) {
@@ -745,7 +746,7 @@ function image_style_url($style_name, $p
   cache_set('access:' . $style_name . ':' . md5($path), 1, 'cache_image', REQUEST_TIME + 600);
 
   $scheme = file_uri_scheme($path);
-  $target = file_uri_target($path);
+  $target = file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($path);
 
   // Generate a callback path for the image.
   $url = url('image/generate/' . $style_name . '/' . $scheme . '/' . $target, array('absolute' => TRUE));
@@ -769,7 +770,7 @@ function image_style_url($style_name, $p
 function image_style_path($style_name, $uri) {
   $scheme = file_uri_scheme($uri);
   if ($scheme) {
-    $path = file_uri_target($uri);
+    $path = file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($uri);
   }
   else {
     $path = $uri;
Index: modules/simpletest/tests/file.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v
retrieving revision 1.51
diff -u -p -r1.51 file.test
--- modules/simpletest/tests/file.test	29 Jan 2010 22:40:41 -0000	1.51
+++ modules/simpletest/tests/file.test	1 Feb 2010 17:18:43 -0000
@@ -2253,9 +2253,10 @@ class StreamWrapperTest extends DrupalWe
     $uri = file_stream_wrapper_uri_normalize($uri);
     $this->assertEqual('public://foo/bar', $uri, t('Got a properly normalized URI @uri', array('@uri' => $uri)));
 
-    // Test file_uri_target().
-    $this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', t('Got a valid stream target from public://foo/bar.txt.'));
-    $this->assertFalse(file_uri_target('foo/bar.txt'), t('foo/bar.txt is not a valid stream.'));
+    // Test stream wrapper $instance->getTarget().
+    $instance = file_stream_wrapper_get_instance_by_scheme('public://');
+    $this->assertEqual($instance->getTarget('public://foo/bar.txt'), 'foo/bar.txt', t('Got a valid stream target from public://foo/bar.txt.'));
+    $this->assertFalse($instance->getTarget('foo/bar.txt'), t('foo/bar.txt is not a valid stream.'));
 
     // Test file_build_uri() and file_directory_path().
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', t('Expected scheme was added.'));
Index: modules/simpletest/tests/file_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file_test.module,v
retrieving revision 1.20
diff -u -p -r1.20 file_test.module
--- modules/simpletest/tests/file_test.module	29 Jan 2010 01:59:32 -0000	1.20
+++ modules/simpletest/tests/file_test.module	1 Feb 2010 17:18:43 -0000
@@ -296,7 +296,7 @@ function file_test_file_url_alter(&$uri)
     // Public created files.
     else {
       $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
-      $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+      $path = $wrapper->getDirectoryPath() . '/' . $wrapper->getTarget($uri);
     }
 
     // Clean up Windows paths.
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.256
diff -u -p -r1.256 system.admin.inc
--- modules/system/system.admin.inc	30 Jan 2010 07:54:01 -0000	1.256
+++ modules/system/system.admin.inc	1 Feb 2010 17:18:43 -0000
@@ -540,8 +540,8 @@ function system_theme_settings($form, &$
     $logo_path = theme_get_setting('logo_path', $key);
     // If $logo_path is a public:// URI, display the path relative to the files
     // directory; stream wrappers are not end-user friendly.
-    if (file_uri_scheme($logo_path) == 'public') {
-      $logo_path = file_uri_target($logo_path);
+    if (($scheme = file_uri_scheme($logo_path)) == 'public') {
+      $logo_path = file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($logo_path);
     }
     $form['logo']['settings']['logo_path'] = array(
       '#type' => 'textfield',
@@ -581,8 +581,8 @@ function system_theme_settings($form, &$
     $favicon_path = theme_get_setting('favicon_path', $key);
     // If $favicon_path is a public:// URI, display the path relative to the
     // files directory; stream wrappers are not end-user friendly.
-    if (file_uri_scheme($favicon_path) == 'public') {
-      $favicon_path = file_uri_target($favicon_path);
+    if (($scheme = file_uri_scheme($favicon_path)) == 'public') {
+      $favicon_path = file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($favicon_path);
     }
     $form['favicon']['settings']['favicon_path'] = array(
       '#type' => 'textfield',
Index: modules/system/system.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.api.php,v
retrieving revision 1.125
diff -u -p -r1.125 system.api.php
--- modules/system/system.api.php	30 Jan 2010 07:59:25 -0000	1.125
+++ modules/system/system.api.php	1 Feb 2010 17:18:44 -0000
@@ -1817,7 +1817,7 @@ function hook_file_url_alter(&$uri) {
     // Public created files.
     else {
       $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
-      $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
+      $path = $wrapper->getDirectoryPath() . '/' . $wrapper->getTarget($uri);
     }
 
     // Clean up Windows paths.
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1116
diff -u -p -r1.1116 user.module
--- modules/user/user.module	30 Jan 2010 07:59:26 -0000	1.1116
+++ modules/user/user.module	1 Feb 2010 17:18:44 -0000
@@ -796,7 +796,9 @@ function user_permission() {
  * Ensure that user pictures (avatars) are always downloadable.
  */
 function user_file_download($uri) {
-  if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
+  $scheme = file_uri_scheme($uri);
+  $target = file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($uri);
+  if (strpos($target, variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
     $info = image_get_info($uri);
     return array('Content-Type' => $info['mime_type']);
   }
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.78
diff -u -p -r1.78 user.test
--- modules/user/user.test	29 Jan 2010 13:50:14 -0000	1.78
+++ modules/user/user.test	1 Feb 2010 17:18:44 -0000
@@ -916,7 +916,10 @@ class UserPictureTestCase extends Drupal
 
       // Check if image is displayed in user's profile page.
       $this->drupalGet('user');
-      $this->assertRaw(file_uri_target($pic_path), t("Image is displayed in user's profile page"));
+      $scheme = file_uri_scheme($pic_path);
+      $instance = file_stream_wrapper_get_instance_by_scheme($scheme);
+      $target = $instance->getTarget($pic_path);
+      $this->assertRaw($target, t("Image is displayed in user's profile page"));
 
       // Check if file is located in proper directory.
       $this->assertTrue(is_file($pic_path), t('File is located in proper directory'));
