2013-08-22 23:04:06 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2013-08-22 23:04:06 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-08-22 23:04:06 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Search\Result;
|
2020-04-09 05:48:10 -04:00
|
|
|
|
2014-07-09 08:47:43 -04:00
|
|
|
use OCP\Files\FileInfo;
|
2015-04-13 05:29:10 -04:00
|
|
|
use OCP\Files\Folder;
|
2020-08-04 04:00:27 -04:00
|
|
|
use OCP\IPreview;
|
|
|
|
|
use OCP\IUserSession;
|
2014-07-09 08:47:43 -04:00
|
|
|
|
2013-08-22 23:04:06 -04:00
|
|
|
/**
|
|
|
|
|
* A found file
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-22 23:04:06 -04:00
|
|
|
*/
|
2014-06-05 19:17:02 -04:00
|
|
|
class File extends \OCP\Search\Result {
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* Type name; translated in templates
|
2020-04-09 10:09:23 -04:00
|
|
|
* @var string
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
|
|
|
|
public $type = 'file';
|
2013-08-22 23:04:06 -04:00
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* Path to file
|
|
|
|
|
* @var string
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
|
|
|
|
public $path;
|
2013-08-22 23:04:06 -04:00
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* Size, in bytes
|
2020-04-09 10:09:23 -04:00
|
|
|
* @var int
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
|
|
|
|
public $size;
|
2013-08-22 23:04:06 -04:00
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* Date modified, in human readable form
|
|
|
|
|
* @var string
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
|
|
|
|
public $modified;
|
2013-08-22 23:04:06 -04:00
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* File mime type
|
|
|
|
|
* @var string
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
|
|
|
|
public $mime_type;
|
2013-08-22 23:04:06 -04:00
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* File permissions:
|
2020-04-09 10:09:23 -04:00
|
|
|
*
|
2013-08-26 08:12:06 -04:00
|
|
|
* @var string
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
|
|
|
|
public $permissions;
|
2013-08-22 23:04:06 -04:00
|
|
|
|
2020-08-04 04:00:27 -04:00
|
|
|
/**
|
|
|
|
|
* Has a preview
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
* @deprecated 20.0.0
|
|
|
|
|
*/
|
|
|
|
|
public $has_preview;
|
|
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* Create a new file search result
|
2014-07-14 11:10:52 -04:00
|
|
|
* @param FileInfo $data file data given by provider
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
2014-07-09 08:47:43 -04:00
|
|
|
public function __construct(FileInfo $data) {
|
2014-07-14 11:10:52 -04:00
|
|
|
$path = $this->getRelativePath($data->getPath());
|
|
|
|
|
|
2014-07-09 08:47:43 -04:00
|
|
|
$this->id = $data->getId();
|
2021-03-19 09:47:30 -04:00
|
|
|
$this->name = $data->getName();
|
2016-03-12 16:29:47 -05:00
|
|
|
$this->link = \OC::$server->getURLGenerator()->linkToRoute(
|
|
|
|
|
'files.view.index',
|
|
|
|
|
[
|
2021-03-19 09:47:30 -04:00
|
|
|
'dir' => dirname($path),
|
|
|
|
|
'scrollto' => $data->getName(),
|
2016-03-12 16:29:47 -05:00
|
|
|
]
|
2013-08-26 08:12:06 -04:00
|
|
|
);
|
2014-07-14 11:10:52 -04:00
|
|
|
$this->permissions = $data->getPermissions();
|
|
|
|
|
$this->path = $path;
|
2014-07-09 08:47:43 -04:00
|
|
|
$this->size = $data->getSize();
|
|
|
|
|
$this->modified = $data->getMtime();
|
2017-07-19 13:59:21 -04:00
|
|
|
$this->mime_type = $data->getMimetype();
|
2020-08-04 04:00:27 -04:00
|
|
|
$this->has_preview = $this->hasPreview($data);
|
2013-08-26 08:12:06 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-13 05:29:10 -04:00
|
|
|
/**
|
|
|
|
|
* @var Folder $userFolderCache
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2015-04-13 05:29:10 -04:00
|
|
|
*/
|
2020-04-10 10:48:31 -04:00
|
|
|
protected static $userFolderCache = null;
|
2015-04-13 05:29:10 -04:00
|
|
|
|
2013-08-26 08:12:06 -04:00
|
|
|
/**
|
2014-07-14 11:10:52 -04:00
|
|
|
* converts a path relative to the users files folder
|
|
|
|
|
* eg /user/files/foo.txt -> /foo.txt
|
2013-08-26 08:12:06 -04:00
|
|
|
* @param string $path
|
2014-07-14 11:10:52 -04:00
|
|
|
* @return string relative path
|
2020-06-22 04:57:40 -04:00
|
|
|
* @deprecated 20.0.0
|
2013-08-26 08:12:06 -04:00
|
|
|
*/
|
2020-04-09 07:53:40 -04:00
|
|
|
protected function getRelativePath($path) {
|
2015-04-13 05:29:10 -04:00
|
|
|
if (!isset(self::$userFolderCache)) {
|
2020-08-04 04:00:27 -04:00
|
|
|
$userSession = \OC::$server->get(IUserSession::class);
|
|
|
|
|
$userID = $userSession->getUser()->getUID();
|
|
|
|
|
self::$userFolderCache = \OC::$server->getUserFolder($userID);
|
2015-04-13 05:29:10 -04:00
|
|
|
}
|
2021-03-24 09:33:35 -04:00
|
|
|
$relativePath = self::$userFolderCache->getRelativePath($path);
|
|
|
|
|
if ($relativePath === null) {
|
|
|
|
|
throw new \Exception("Search result not in user folder");
|
|
|
|
|
}
|
|
|
|
|
return $relativePath;
|
2013-08-26 08:12:06 -04:00
|
|
|
}
|
2020-08-04 04:00:27 -04: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 08:12:06 -04:00
|
|
|
}
|