From 3f093974f9c5d9e739ba8e18098bef05bee1621f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 9 Jul 2014 14:47:43 +0200 Subject: [PATCH 1/3] use fileinfo object in search results --- lib/private/search/result/file.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/private/search/result/file.php b/lib/private/search/result/file.php index da5fa64ef45..82c425adb15 100644 --- a/lib/private/search/result/file.php +++ b/lib/private/search/result/file.php @@ -18,7 +18,9 @@ */ namespace OC\Search\Result; -use \OC\Files\Filesystem; +use OC\Files\Filesystem; +use OCP\Files\FileInfo; + /** * A found file */ @@ -65,20 +67,20 @@ class File extends \OCP\Search\Result { * Create a new file search result * @param array $data file data given by provider */ - public function __construct(array $data = null) { - $info = pathinfo($data['path']); - $this->id = $data['fileid']; + public function __construct(FileInfo $data) { + $info = pathinfo($data->getPath()); + $this->id = $data->getId(); $this->name = $info['basename']; $this->link = \OCP\Util::linkTo( 'files', 'index.php', array('dir' => $info['dirname'], 'file' => $info['basename']) ); - $this->permissions = self::get_permissions($data['path']); - $this->path = (strpos($data['path'], 'files') === 0) ? substr($data['path'], 5) : $data['path']; - $this->size = $data['size']; - $this->modified = $data['mtime']; - $this->mime_type = $data['mimetype']; + $this->permissions = self::get_permissions($data->getPath()); + $this->path = (strpos($data->getPath(), 'files') === 0) ? substr($data->getPath(), 5) : $data->getPath(); + $this->size = $data->getSize(); + $this->modified = $data->getMtime(); + $this->mime_type = $data->getMimetype(); } /** From eea5c2ee0a847a80746aef3ecda1687edc962b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 14 Jul 2014 17:10:52 +0200 Subject: [PATCH 2/3] return relative path --- lib/private/search/result/file.php | 42 +++++++++++------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/lib/private/search/result/file.php b/lib/private/search/result/file.php index 82c425adb15..38acac48ed7 100644 --- a/lib/private/search/result/file.php +++ b/lib/private/search/result/file.php @@ -65,10 +65,13 @@ class File extends \OCP\Search\Result { /** * Create a new file search result - * @param array $data file data given by provider + * @param FileInfo $data file data given by provider */ public function __construct(FileInfo $data) { - $info = pathinfo($data->getPath()); + + $path = $this->getRelativePath($data->getPath()); + + $info = pathinfo($path); $this->id = $data->getId(); $this->name = $info['basename']; $this->link = \OCP\Util::linkTo( @@ -76,38 +79,23 @@ class File extends \OCP\Search\Result { 'index.php', array('dir' => $info['dirname'], 'file' => $info['basename']) ); - $this->permissions = self::get_permissions($data->getPath()); - $this->path = (strpos($data->getPath(), 'files') === 0) ? substr($data->getPath(), 5) : $data->getPath(); + $this->permissions = $data->getPermissions(); + $this->path = $path; $this->size = $data->getSize(); $this->modified = $data->getMtime(); $this->mime_type = $data->getMimetype(); } /** - * Determine permissions for a given file path + * converts a path relative to the users files folder + * eg /user/files/foo.txt -> /foo.txt * @param string $path - * @return int + * @return string relative path */ - function get_permissions($path) { - // add read permissions - $permissions = \OCP\PERMISSION_READ; - // get directory - $fileinfo = pathinfo($path); - $dir = $fileinfo['dirname'] . '/'; - // add update permissions - if (Filesystem::isUpdatable($dir)) { - $permissions |= \OCP\PERMISSION_UPDATE; - } - // add delete permissions - if (Filesystem::isDeletable($dir)) { - $permissions |= \OCP\PERMISSION_DELETE; - } - // add share permissions - if (Filesystem::isSharable($dir)) { - $permissions |= \OCP\PERMISSION_SHARE; - } - // return - return $permissions; + function getRelativePath ($path) { + $root = \OC::$server->getUserFolder(); + return $root->getRelativePath($path); + } - + } From 8f11019f4562ba2eb483421f3a62c7f7f7db0ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 14 Jul 2014 19:27:10 +0200 Subject: [PATCH 3/3] mkae getRelativePath of file search results overwriteable in subclasses --- lib/private/search/result/file.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/private/search/result/file.php b/lib/private/search/result/file.php index 38acac48ed7..331fdaa383a 100644 --- a/lib/private/search/result/file.php +++ b/lib/private/search/result/file.php @@ -92,10 +92,9 @@ class File extends \OCP\Search\Result { * @param string $path * @return string relative path */ - function getRelativePath ($path) { + protected function getRelativePath ($path) { $root = \OC::$server->getUserFolder(); return $root->getRelativePath($path); - } }