server/lib/private/search/result/file.php

101 lines
2.1 KiB
PHP
Raw Normal View History

<?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;
/**
* A found file
*/
class File extends \OCP\Search\Result {
2013-08-26 12:12:06 +00:00
/**
* Type name; translated in templates
* @var string
*/
public $type = 'file';
2013-08-26 12:12:06 +00:00
/**
* Path to file
* @var string
*/
public $path;
2013-08-26 12:12:06 +00:00
/**
* Size, in bytes
* @var int
*/
public $size;
2013-08-26 12:12:06 +00:00
/**
* Date modified, in human readable form
* @var string
*/
public $modified;
2013-08-26 12:12:06 +00:00
/**
* File mime type
* @var string
*/
public $mime_type;
2013-08-26 12:12:06 +00:00
/**
* File permissions:
*
* @var string
*/
public $permissions;
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',
array('dir' => $info['dirname'], 'file' => $info['basename'])
);
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();
$this->mime_type = $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
*/
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
}