2013-08-23 07:04:06 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Andrew Brown <andrew@casabrown.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2013-08-23 07:04:06 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2013-08-23 07:04:06 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +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-03-26 13:44:34 +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-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-08-23 07:04:06 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-08-23 07:04:06 +04:00
|
|
|
namespace OC\Search\Result;
|
2014-07-09 16:47:43 +04:00
|
|
|
use OCP\Files\FileInfo;
|
2015-04-13 12:29:10 +03:00
|
|
|
use OCP\Files\Folder;
|
2014-07-09 16:47:43 +04:00
|
|
|
|
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'];
|
2016-03-13 00:29:47 +03:00
|
|
|
$this->link = \OC::$server->getURLGenerator()->linkToRoute(
|
|
|
|
'files.view.index',
|
|
|
|
[
|
|
|
|
'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();
|
2017-07-19 20:59:21 +03:00
|
|
|
$this->mime_type = $data->getMimetype();
|
2013-08-26 16:12:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-13 12:29:10 +03:00
|
|
|
/**
|
|
|
|
* @var Folder $userFolderCache
|
|
|
|
*/
|
|
|
|
static protected $userFolderCache = null;
|
|
|
|
|
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) {
|
2015-04-13 12:29:10 +03:00
|
|
|
if (!isset(self::$userFolderCache)) {
|
|
|
|
$user = \OC::$server->getUserSession()->getUser()->getUID();
|
|
|
|
self::$userFolderCache = \OC::$server->getUserFolder($user);
|
|
|
|
}
|
|
|
|
return self::$userFolderCache->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
|
|
|
}
|