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>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @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;
|
2020-04-09 12:48:10 +03:00
|
|
|
|
2014-07-09 16:47:43 +04:00
|
|
|
use OCP\Files\FileInfo;
|
2015-04-13 12:29:10 +03:00
|
|
|
use OCP\Files\Folder;
|
2020-08-04 11:00:27 +03:00
|
|
|
use OCP\IPreview;
|
|
|
|
use OCP\IUserSession;
|
2014-07-09 16:47:43 +04:00
|
|
|
|
2013-08-23 07:04:06 +04:00
|
|
|
/**
|
|
|
|
* A found file
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-23 07:04:06 +04:00
|
|
|
*/
|
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
|
2020-04-09 17:09:23 +03:00
|
|
|
* @var string
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
|
|
|
public $type = 'file';
|
2013-08-23 07:04:06 +04:00
|
|
|
|
2013-08-26 16:12:06 +04:00
|
|
|
/**
|
|
|
|
* Path to file
|
|
|
|
* @var string
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
|
|
|
public $path;
|
2013-08-23 07:04:06 +04:00
|
|
|
|
2013-08-26 16:12:06 +04:00
|
|
|
/**
|
|
|
|
* Size, in bytes
|
2020-04-09 17:09:23 +03:00
|
|
|
* @var int
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
|
|
|
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
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
|
|
|
public $modified;
|
2013-08-23 07:04:06 +04:00
|
|
|
|
2013-08-26 16:12:06 +04:00
|
|
|
/**
|
|
|
|
* File mime type
|
|
|
|
* @var string
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
|
|
|
public $mime_type;
|
2013-08-23 07:04:06 +04:00
|
|
|
|
2013-08-26 16:12:06 +04:00
|
|
|
/**
|
|
|
|
* File permissions:
|
2020-04-09 17:09:23 +03:00
|
|
|
*
|
2013-08-26 16:12:06 +04:00
|
|
|
* @var string
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
|
|
|
public $permissions;
|
2013-08-23 07:04:06 +04:00
|
|
|
|
2020-08-04 11:00:27 +03:00
|
|
|
/**
|
|
|
|
* Has a preview
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @deprecated 20.0.0
|
|
|
|
*/
|
|
|
|
public $has_preview;
|
|
|
|
|
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
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
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();
|
2020-08-04 11:00:27 +03:00
|
|
|
$this->has_preview = $this->hasPreview($data);
|
2013-08-26 16:12:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-13 12:29:10 +03:00
|
|
|
/**
|
|
|
|
* @var Folder $userFolderCache
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2015-04-13 12:29:10 +03:00
|
|
|
*/
|
2020-04-10 17:48:31 +03:00
|
|
|
protected static $userFolderCache = null;
|
2015-04-13 12:29:10 +03:00
|
|
|
|
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
|
2020-06-22 11:57:40 +03:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 16:12:06 +04:00
|
|
|
*/
|
2020-04-09 14:53:40 +03:00
|
|
|
protected function getRelativePath($path) {
|
2015-04-13 12:29:10 +03:00
|
|
|
if (!isset(self::$userFolderCache)) {
|
2020-08-04 11:00:27 +03:00
|
|
|
$userSession = \OC::$server->get(IUserSession::class);
|
|
|
|
$userID = $userSession->getUser()->getUID();
|
|
|
|
self::$userFolderCache = \OC::$server->getUserFolder($userID);
|
2015-04-13 12:29:10 +03:00
|
|
|
}
|
|
|
|
return self::$userFolderCache->getRelativePath($path);
|
2013-08-26 16:12:06 +04:00
|
|
|
}
|
2020-08-04 11:00:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the preview available
|
|
|
|
* @param FileInfo $data
|
|
|
|
* @return bool
|
|
|
|
* @deprecated 20.0.0
|
|
|
|
*/
|
|
|
|
protected function hasPreview($data) {
|
|
|
|
$previewManager = \OC::$server->get(IPreview::class);
|
|
|
|
return $previewManager->isAvailable($data);
|
|
|
|
}
|
2013-08-26 16:12:06 +04:00
|
|
|
}
|