|
|
@ -27,6 +27,7 @@ class File {
|
|
|
|
protected $fileId;
|
|
|
|
protected $fileId;
|
|
|
|
protected $owner;
|
|
|
|
protected $owner;
|
|
|
|
protected $path;
|
|
|
|
protected $path;
|
|
|
|
|
|
|
|
protected $sharing;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($fileId){
|
|
|
|
public function __construct($fileId){
|
|
|
|
if (!$fileId){
|
|
|
|
if (!$fileId){
|
|
|
@ -34,6 +35,10 @@ class File {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->fileId = $fileId;
|
|
|
|
$this->fileId = $fileId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if you know how to get sharing info by fileId via API,
|
|
|
|
|
|
|
|
//please send me a link to video tutorial :/
|
|
|
|
|
|
|
|
$this->sharing = $this->getSharingOps();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function getByShareToken($token){
|
|
|
|
public static function getByShareToken($token){
|
|
|
@ -47,8 +52,6 @@ class File {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$file = new File($rootLinkItem['file_source']);
|
|
|
|
$file = new File($rootLinkItem['file_source']);
|
|
|
|
$file->setOwner($rootLinkItem['uid_owner']);
|
|
|
|
|
|
|
|
$file->setPath('/files' . $rootLinkItem['file_target']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $file;
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -65,6 +68,18 @@ class File {
|
|
|
|
$this->path = $path;
|
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function isPublicShare(){
|
|
|
|
|
|
|
|
foreach ($this->sharing as $share){
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
$share['share_type'] == \OCP\Share::SHARE_TYPE_LINK
|
|
|
|
|
|
|
|
|| $share['share_type'] == \OCP\Share::SHARE_TYPE_EMAIL
|
|
|
|
|
|
|
|
){
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return string owner of the current file item
|
|
|
|
* @return string owner of the current file item
|
|
|
@ -72,68 +87,86 @@ class File {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getOwnerViewAndPath(){
|
|
|
|
public function getOwnerViewAndPath(){
|
|
|
|
if (!$this->owner || !$this->path){
|
|
|
|
if (!$this->owner || !$this->path){
|
|
|
|
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
|
|
|
$info = $this->getSharedFileOwnerAndPath();
|
|
|
|
|
|
|
|
if (is_array($info) && count($info)){
|
|
|
|
//is it shared
|
|
|
|
$owner = $info[0];
|
|
|
|
$sharedInfo = $this->getSharedBySource();
|
|
|
|
$path = $info[1];
|
|
|
|
|
|
|
|
|
|
|
|
if (is_array($sharedInfo)){
|
|
|
|
|
|
|
|
$owner = $sharedInfo['uid_owner'];
|
|
|
|
|
|
|
|
$path = $sharedInfo['path'];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// owner is myself
|
|
|
|
list($owner, $path) = $this->getLocalFileOwnerAndPath();
|
|
|
|
$owner = \OCP\User::getUser();
|
|
|
|
|
|
|
|
$path = @$fileInfo[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!$path){
|
|
|
|
if (!$path){
|
|
|
|
throw new \Exception($this->fileId . ' can not be resolved');
|
|
|
|
throw new \Exception($this->fileId . ' can not be resolved');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$view = new View('/' . $owner);
|
|
|
|
$this->path = $path;
|
|
|
|
|
|
|
|
|
|
|
|
$this->owner = $owner;
|
|
|
|
$this->owner = $owner;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$view = new View('/' . $this->owner);
|
|
|
|
|
|
|
|
$path = $this->path;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!$view->file_exists($path)){
|
|
|
|
$view = new View('/' . $this->owner);
|
|
|
|
throw new \Exception($path . ' doesn\'t exist');
|
|
|
|
if (!$view->file_exists($this->path)){
|
|
|
|
|
|
|
|
throw new \Exception($this->path . ' doesn\'t exist');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return array($view, $path);
|
|
|
|
return array($view, $this->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getOwner(){
|
|
|
|
public function getOwner(){
|
|
|
|
if (!$this->owner){
|
|
|
|
if (!$this->owner){
|
|
|
|
|
|
|
|
$this->getOwnerViewAndPath();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->owner;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getSharedFileOwnerAndPath(){
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->sharing as $share){
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
|
|
|
$share['uid_owner'],
|
|
|
|
|
|
|
|
$share['path']
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getLocalFileOwnerAndPath(){
|
|
|
|
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
|
|
|
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
|
|
|
|
|
|
|
$owner = \OCP\User::getUser();
|
|
|
|
|
|
|
|
if (!$owner){
|
|
|
|
|
|
|
|
throw new Exception('Guest users can\'t access local files. This one was probably unshared recently.');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//is it shared
|
|
|
|
return array ($owner, @$fileInfo[1]);
|
|
|
|
$sharedInfo = $this->getSharedBySource();
|
|
|
|
|
|
|
|
if (!is_array($sharedInfo)){
|
|
|
|
|
|
|
|
$sharedInfo = $this->getSharedByLink();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (is_array($sharedInfo)){
|
|
|
|
protected function getSharingOps(){
|
|
|
|
$this->owner = $sharedInfo['uid_owner'];
|
|
|
|
|
|
|
|
|
|
|
|
$where = 'AND `file_source`=?';
|
|
|
|
|
|
|
|
$values = array($this->fileId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (\OCP\User::isLoggedIn()){
|
|
|
|
|
|
|
|
$where .= ' AND ((`share_type`=' . \OCP\Share::SHARE_TYPE_USER . ' AND `share_with`=?) OR `share_type`=' . \OCP\Share::SHARE_TYPE_LINK . ')';
|
|
|
|
|
|
|
|
$values[] = \OCP\User::getUser();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// owner is myself
|
|
|
|
$where .= ' AND (`share_type`=' . \OCP\Share::SHARE_TYPE_LINK . ')';
|
|
|
|
$this->owner = \OCP\User::getUser();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, '
|
|
|
|
|
|
|
|
.'`share_type`, `share_with`, `file_source`, `path`, `file_target`, '
|
|
|
|
|
|
|
|
.'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, '
|
|
|
|
|
|
|
|
.'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`'
|
|
|
|
|
|
|
|
.'FROM `*PREFIX*share` INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `item_type` = `file` ' . $where);
|
|
|
|
|
|
|
|
$result = $query->execute($values);
|
|
|
|
|
|
|
|
$shares = $result->fetchAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$origins = array();
|
|
|
|
|
|
|
|
if (is_array($shares)){
|
|
|
|
|
|
|
|
foreach ($shares as $share){
|
|
|
|
|
|
|
|
$origins[] = \OCP\Share::resolveReShare($share);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->owner;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $origins;
|
|
|
|
protected function getSharedBySource(){
|
|
|
|
|
|
|
|
return \OCP\Share::getItemSharedWithBySource(
|
|
|
|
|
|
|
|
'file',
|
|
|
|
|
|
|
|
$this->fileId,
|
|
|
|
|
|
|
|
\OCP\Share::FORMAT_NONE,
|
|
|
|
|
|
|
|
null,
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|