File.php 3.3 KB

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