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