|
|
|
@ -54,23 +54,12 @@ class File {
|
|
|
|
|
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
|
|
|
|
// seems to be a valid share
|
|
|
|
|
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
|
|
|
|
|
$fileOwner = $rootLinkItem['uid_owner'];
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception('This file was probably unshared');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isset($rootLinkItem['path']) && isset($rootLinkItem['file_target'])){
|
|
|
|
|
$rootLinkItem['path'] = $rootLinkItem['file_target'];
|
|
|
|
|
}
|
|
|
|
|
$file = new File($rootLinkItem['file_source'], array($rootLinkItem));
|
|
|
|
|
$file->setToken($token);
|
|
|
|
|
|
|
|
|
|
if (isset($rootLinkItem['uid_owner'])){
|
|
|
|
|
\OC_Util::tearDownFS();
|
|
|
|
|
\OC_Util::setupFS($rootLinkItem['uid_owner']);
|
|
|
|
|
$file->setOwner($rootLinkItem['uid_owner']);
|
|
|
|
|
$file->setPath(\OC\Files\Filesystem::getPath($linkItem['file_source']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
|
|
|
|
|
$file->setPasswordProtected(true);
|
|
|
|
@ -79,6 +68,10 @@ class File {
|
|
|
|
|
return $file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getToken($token){
|
|
|
|
|
return $this->token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getFileId(){
|
|
|
|
|
return $this->fileId;
|
|
|
|
|
}
|
|
|
|
@ -156,28 +149,34 @@ class File {
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function getOwnerViewAndPath(){
|
|
|
|
|
if (!$this->owner || !$this->path){
|
|
|
|
|
if ($this->isPublicShare()){
|
|
|
|
|
list($owner, $path) = $this->getSharedFileOwnerAndPath();
|
|
|
|
|
if ($this->isPublicShare()){
|
|
|
|
|
$rootLinkItem = \OCP\Share::resolveReShare($this->sharing[0]);
|
|
|
|
|
if (isset($rootLinkItem['uid_owner'])){
|
|
|
|
|
$owner = $rootLinkItem['uid_owner'];
|
|
|
|
|
} else {
|
|
|
|
|
$owner = \OCP\User::getUser();
|
|
|
|
|
$path = Storage::resolvePath($this->fileId);
|
|
|
|
|
if (!$path){
|
|
|
|
|
throw new \Exception($this->fileId . ' can not be resolved');
|
|
|
|
|
}
|
|
|
|
|
throw new \Exception($this->fileId . ' is a broken share');
|
|
|
|
|
}
|
|
|
|
|
$view = new View('/' . $owner . '/files');
|
|
|
|
|
$path = $rootLinkItem['file_target'];
|
|
|
|
|
} else {
|
|
|
|
|
$owner = \OCP\User::getUser();
|
|
|
|
|
$view = new View('/' . $this->owner);
|
|
|
|
|
$path = $view->getPath($this->fileId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->path = $path;
|
|
|
|
|
$this->owner = $owner;
|
|
|
|
|
if (!$path){
|
|
|
|
|
throw new \Exception($this->fileId . ' can not be resolved');
|
|
|
|
|
}
|
|
|
|
|
$this->path = $path;
|
|
|
|
|
$this->owner = $owner;
|
|
|
|
|
|
|
|
|
|
$view = new View('/' . $this->owner . '/files');
|
|
|
|
|
if (!$view->file_exists($this->path)){
|
|
|
|
|
throw new \Exception($this->path . ' doesn\'t exist');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array($view, $this->path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getOwner(){
|
|
|
|
|
if (!$this->owner){
|
|
|
|
@ -186,28 +185,6 @@ class File {
|
|
|
|
|
return $this->owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* public links only
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function getSharedFileOwnerAndPath(){
|
|
|
|
|
foreach ($this->sharing as $share){
|
|
|
|
|
$rootLinkItem = \OCP\Share::resolveReShare($share);
|
|
|
|
|
if (isset($rootLinkItem['uid_owner'])){
|
|
|
|
|
$owner = $rootLinkItem['uid_owner'];
|
|
|
|
|
} else {
|
|
|
|
|
$owner = false;
|
|
|
|
|
}
|
|
|
|
|
$view = new View('/' . $owner . '/files');
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
$owner,
|
|
|
|
|
$view->getPath($rootLinkItem['file_source'])
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getPassword(){
|
|
|
|
|
return $this->sharing[0]['share_with'];
|
|
|
|
|