2013-08-23 03:04:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Search\Result;
|
2014-07-09 12:47:43 +00:00
|
|
|
use OC\Files\Filesystem;
|
|
|
|
use OCP\Files\FileInfo;
|
|
|
|
|
2013-08-23 03:04:06 +00:00
|
|
|
/**
|
|
|
|
* A found file
|
|
|
|
*/
|
2014-06-05 23:17:02 +00:00
|
|
|
class File extends \OCP\Search\Result {
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* Type name; translated in templates
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $type = 'file';
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* Path to file
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $path;
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* Size, in bytes
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $size;
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* Date modified, in human readable form
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $modified;
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* File mime type
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $mime_type;
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* File permissions:
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $permissions;
|
2013-08-23 03:04:06 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
/**
|
|
|
|
* Create a new file search result
|
2014-07-14 15:10:52 +00:00
|
|
|
* @param FileInfo $data file data given by provider
|
2013-08-26 12:12:06 +00:00
|
|
|
*/
|
2014-07-09 12:47:43 +00:00
|
|
|
public function __construct(FileInfo $data) {
|
2014-07-14 15:10:52 +00:00
|
|
|
|
|
|
|
$path = $this->getRelativePath($data->getPath());
|
|
|
|
|
|
|
|
$info = pathinfo($path);
|
2014-07-09 12:47:43 +00:00
|
|
|
$this->id = $data->getId();
|
2013-08-26 12:12:06 +00:00
|
|
|
$this->name = $info['basename'];
|
|
|
|
$this->link = \OCP\Util::linkTo(
|
|
|
|
'files',
|
|
|
|
'index.php',
|
2015-01-29 11:21:20 +00:00
|
|
|
array('dir' => $info['dirname'], 'scrollto' => $info['basename'])
|
2013-08-26 12:12:06 +00:00
|
|
|
);
|
2014-07-14 15:10:52 +00:00
|
|
|
$this->permissions = $data->getPermissions();
|
|
|
|
$this->path = $path;
|
2014-07-09 12:47:43 +00:00
|
|
|
$this->size = $data->getSize();
|
|
|
|
$this->modified = $data->getMtime();
|
2014-12-05 23:53:06 +00:00
|
|
|
$this->mime = $data->getMimetype();
|
2013-08-26 12:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-14 15:10:52 +00:00
|
|
|
* converts a path relative to the users files folder
|
|
|
|
* eg /user/files/foo.txt -> /foo.txt
|
2013-08-26 12:12:06 +00:00
|
|
|
* @param string $path
|
2014-07-14 15:10:52 +00:00
|
|
|
* @return string relative path
|
2013-08-26 12:12:06 +00:00
|
|
|
*/
|
2014-07-14 17:27:10 +00:00
|
|
|
protected function getRelativePath ($path) {
|
2014-07-14 15:10:52 +00:00
|
|
|
$root = \OC::$server->getUserFolder();
|
|
|
|
return $root->getRelativePath($path);
|
2013-08-26 12:12:06 +00:00
|
|
|
}
|
2014-07-14 15:10:52 +00:00
|
|
|
|
2013-08-26 12:12:06 +00:00
|
|
|
}
|