diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 4397ca03e7..2d1e21bdff 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -336,7 +336,7 @@ class Vfs extends Vfs\Base * - hidden => {true|false(default)} include hidden files (name starts with a '.' or is Thumbs.db) * - show-deleted => {true|false(default)} get also set by hidden, if not explicitly set otherwise (requires versioning!) * - * @param string|array/true $exec =null function to call with each found file/dir as first param and stat array as last param or + * @param string|array|true $exec =null function to call with each found file/dir as first param and stat array as last param or * true to return file => stat pairs * @param array $exec_params =null further params for exec as array, path is always the first param and stat the last! * @return array of pathes if no $exec, otherwise path => stat pairs @@ -793,7 +793,7 @@ class Vfs extends Vfs\Base return $ret; } - if (!isset($vfs)) $vfs = new Vfs\StreamWrapper(); + if (!isset($vfs)) $vfs = new Vfs\StreamWrapper($path); return $vfs->check_access($path, $check, $stat); } @@ -2074,7 +2074,7 @@ class Vfs extends Vfs\Base */ static function resolve_url_symlinks($_path,$file_exists=true,$resolve_last_symlink=true,&$stat=null) { - $vfs = new Vfs\StreamWrapper(); + $vfs = new Vfs\StreamWrapper($_path); return $vfs->resolve_url_symlinks($_path, $file_exists, $resolve_last_symlink, $stat); } diff --git a/api/src/Vfs/UserContextTrait.php b/api/src/Vfs/UserContextTrait.php index 3a44c94ef6..8c749a6da4 100644 --- a/api/src/Vfs/UserContextTrait.php +++ b/api/src/Vfs/UserContextTrait.php @@ -209,6 +209,28 @@ trait UserContextTrait } } + /** + * Get user context for given url, eg. to use with regular stream functions + * + * @param string $url + * @param array $extra =[] addtional context options + * @return resource context with user, plus optional extra options + */ + public static function userContext($url, array $extra=[]) + { + if (($user = Vfs::parse_url($url, PHP_URL_USER)) && + ($account_id = Api\Accounts::getInstance()->name2id($user)) && + ($account_id != Vfs::$user) || $extra) // never set extra options on default context! + { + $context = stream_context_create(array_merge_recursive([Vfs::SCHEME => ['user' => (int)$account_id ?: Vfs::$user]], $extra)); + } + else + { + $context = stream_context_get_default(); + } + return $context; + } + /** * @param string $name * @return bool