You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.4 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Andrew Brown <andrew@casabrown.com>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\Search\Result;
  28. use OCP\Files\FileInfo;
  29. use OCP\Files\Folder;
  30. use OCP\IPreview;
  31. use OCP\IUserSession;
  32. /**
  33. * A found file
  34. * @deprecated 20.0.0
  35. */
  36. class File extends \OCP\Search\Result {
  37. /**
  38. * Type name; translated in templates
  39. * @var string
  40. * @deprecated 20.0.0
  41. */
  42. public $type = 'file';
  43. /**
  44. * Path to file
  45. * @var string
  46. * @deprecated 20.0.0
  47. */
  48. public $path;
  49. /**
  50. * Size, in bytes
  51. * @var int
  52. * @deprecated 20.0.0
  53. */
  54. public $size;
  55. /**
  56. * Date modified, in human readable form
  57. * @var string
  58. * @deprecated 20.0.0
  59. */
  60. public $modified;
  61. /**
  62. * File mime type
  63. * @var string
  64. * @deprecated 20.0.0
  65. */
  66. public $mime_type;
  67. /**
  68. * File permissions:
  69. *
  70. * @var string
  71. * @deprecated 20.0.0
  72. */
  73. public $permissions;
  74. /**
  75. * Has a preview
  76. *
  77. * @var string
  78. * @deprecated 20.0.0
  79. */
  80. public $has_preview;
  81. /**
  82. * Create a new file search result
  83. * @param FileInfo $data file data given by provider
  84. * @deprecated 20.0.0
  85. */
  86. public function __construct(FileInfo $data) {
  87. $path = $this->getRelativePath($data->getPath());
  88. $info = pathinfo($path);
  89. $this->id = $data->getId();
  90. $this->name = $info['basename'];
  91. $this->link = \OC::$server->getURLGenerator()->linkToRoute(
  92. 'files.view.index',
  93. [
  94. 'dir' => $info['dirname'],
  95. 'scrollto' => $info['basename'],
  96. ]
  97. );
  98. $this->permissions = $data->getPermissions();
  99. $this->path = $path;
  100. $this->size = $data->getSize();
  101. $this->modified = $data->getMtime();
  102. $this->mime_type = $data->getMimetype();
  103. $this->has_preview = $this->hasPreview($data);
  104. }
  105. /**
  106. * @var Folder $userFolderCache
  107. * @deprecated 20.0.0
  108. */
  109. protected static $userFolderCache = null;
  110. /**
  111. * converts a path relative to the users files folder
  112. * eg /user/files/foo.txt -> /foo.txt
  113. * @param string $path
  114. * @return string relative path
  115. * @deprecated 20.0.0
  116. */
  117. protected function getRelativePath($path) {
  118. if (!isset(self::$userFolderCache)) {
  119. $userSession = \OC::$server->get(IUserSession::class);
  120. $userID = $userSession->getUser()->getUID();
  121. self::$userFolderCache = \OC::$server->getUserFolder($userID);
  122. }
  123. return self::$userFolderCache->getRelativePath($path);
  124. }
  125. /**
  126. * Is the preview available
  127. * @param FileInfo $data
  128. * @return bool
  129. * @deprecated 20.0.0
  130. */
  131. protected function hasPreview($data) {
  132. $previewManager = \OC::$server->get(IPreview::class);
  133. return $previewManager->isAvailable($data);
  134. }
  135. }