@@ -51,264 +51,264 @@ |
||
| 51 | 51 | * @package OCA\Files\Controller |
| 52 | 52 | */ |
| 53 | 53 | class ViewController extends Controller { |
| 54 | - /** @var string */ |
|
| 55 | - protected $appName; |
|
| 56 | - /** @var IRequest */ |
|
| 57 | - protected $request; |
|
| 58 | - /** @var IURLGenerator */ |
|
| 59 | - protected $urlGenerator; |
|
| 60 | - /** @var IL10N */ |
|
| 61 | - protected $l10n; |
|
| 62 | - /** @var IConfig */ |
|
| 63 | - protected $config; |
|
| 64 | - /** @var EventDispatcherInterface */ |
|
| 65 | - protected $eventDispatcher; |
|
| 66 | - /** @var IUserSession */ |
|
| 67 | - protected $userSession; |
|
| 68 | - /** @var IAppManager */ |
|
| 69 | - protected $appManager; |
|
| 70 | - /** @var IRootFolder */ |
|
| 71 | - protected $rootFolder; |
|
| 72 | - /** @var Helper */ |
|
| 73 | - protected $activityHelper; |
|
| 74 | - |
|
| 75 | - public function __construct(string $appName, |
|
| 76 | - IRequest $request, |
|
| 77 | - IURLGenerator $urlGenerator, |
|
| 78 | - IL10N $l10n, |
|
| 79 | - IConfig $config, |
|
| 80 | - EventDispatcherInterface $eventDispatcherInterface, |
|
| 81 | - IUserSession $userSession, |
|
| 82 | - IAppManager $appManager, |
|
| 83 | - IRootFolder $rootFolder, |
|
| 84 | - Helper $activityHelper |
|
| 85 | - ) { |
|
| 86 | - parent::__construct($appName, $request); |
|
| 87 | - $this->appName = $appName; |
|
| 88 | - $this->request = $request; |
|
| 89 | - $this->urlGenerator = $urlGenerator; |
|
| 90 | - $this->l10n = $l10n; |
|
| 91 | - $this->config = $config; |
|
| 92 | - $this->eventDispatcher = $eventDispatcherInterface; |
|
| 93 | - $this->userSession = $userSession; |
|
| 94 | - $this->appManager = $appManager; |
|
| 95 | - $this->rootFolder = $rootFolder; |
|
| 96 | - $this->activityHelper = $activityHelper; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param string $appName |
|
| 101 | - * @param string $scriptName |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - protected function renderScript($appName, $scriptName) { |
|
| 105 | - $content = ''; |
|
| 106 | - $appPath = \OC_App::getAppPath($appName); |
|
| 107 | - $scriptPath = $appPath . '/' . $scriptName; |
|
| 108 | - if (file_exists($scriptPath)) { |
|
| 109 | - // TODO: sanitize path / script name ? |
|
| 110 | - ob_start(); |
|
| 111 | - include $scriptPath; |
|
| 112 | - $content = ob_get_contents(); |
|
| 113 | - @ob_end_clean(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $content; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * FIXME: Replace with non static code |
|
| 121 | - * |
|
| 122 | - * @return array |
|
| 123 | - * @throws \OCP\Files\NotFoundException |
|
| 124 | - */ |
|
| 125 | - protected function getStorageInfo() { |
|
| 126 | - $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
| 127 | - |
|
| 128 | - return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @NoCSRFRequired |
|
| 133 | - * @NoAdminRequired |
|
| 134 | - * |
|
| 135 | - * @param string $dir |
|
| 136 | - * @param string $view |
|
| 137 | - * @param string $fileid |
|
| 138 | - * @return TemplateResponse|RedirectResponse |
|
| 139 | - */ |
|
| 140 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
| 141 | - if ($fileid !== null) { |
|
| 142 | - try { |
|
| 143 | - return $this->showFile($fileid); |
|
| 144 | - } catch (NotFoundException $e) { |
|
| 145 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
| 150 | - |
|
| 151 | - // Load the files we need |
|
| 152 | - \OCP\Util::addStyle('files', 'merged'); |
|
| 153 | - \OCP\Util::addScript('files', 'merged-index'); |
|
| 154 | - |
|
| 155 | - // mostly for the home storage's free space |
|
| 156 | - // FIXME: Make non static |
|
| 157 | - $storageInfo = $this->getStorageInfo(); |
|
| 158 | - |
|
| 159 | - $user = $this->userSession->getUser()->getUID(); |
|
| 160 | - |
|
| 161 | - // Get all the user favorites to create a submenu |
|
| 162 | - try { |
|
| 163 | - $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
| 164 | - } catch (\RuntimeException $e) { |
|
| 165 | - $favElements['folders'] = []; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $collapseClasses = ''; |
|
| 169 | - if (count($favElements['folders']) > 0) { |
|
| 170 | - $collapseClasses = 'collapsible'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $favoritesSublistArray = Array(); |
|
| 174 | - |
|
| 175 | - $navBarPositionPosition = 6; |
|
| 176 | - $currentCount = 0; |
|
| 177 | - foreach ($favElements['folders'] as $dir) { |
|
| 178 | - |
|
| 179 | - $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
| 180 | - $sortingValue = ++$currentCount; |
|
| 181 | - $element = [ |
|
| 182 | - 'id' => str_replace('/', '-', $dir), |
|
| 183 | - 'view' => 'files', |
|
| 184 | - 'href' => $link, |
|
| 185 | - 'dir' => $dir, |
|
| 186 | - 'order' => $navBarPositionPosition, |
|
| 187 | - 'folderPosition' => $sortingValue, |
|
| 188 | - 'name' => basename($dir), |
|
| 189 | - 'icon' => 'files', |
|
| 190 | - 'quickaccesselement' => 'true' |
|
| 191 | - ]; |
|
| 192 | - |
|
| 193 | - array_push($favoritesSublistArray, $element); |
|
| 194 | - $navBarPositionPosition++; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 198 | - |
|
| 199 | - // add the favorites entry in menu |
|
| 200 | - $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
| 201 | - $navItems['favorites']['classes'] = $collapseClasses; |
|
| 202 | - |
|
| 203 | - // parse every menu and add the expandedState user value |
|
| 204 | - foreach ($navItems as $key => $item) { |
|
| 205 | - if (isset($item['expandedState'])) { |
|
| 206 | - $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $nav->assign('navigationItems', $navItems); |
|
| 211 | - |
|
| 212 | - $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
|
| 213 | - if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 214 | - $totalSpace = $this->l10n->t('Unlimited'); |
|
| 215 | - } else { |
|
| 216 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
| 217 | - } |
|
| 218 | - $nav->assign('total_space', $totalSpace); |
|
| 219 | - $nav->assign('quota', $storageInfo['quota']); |
|
| 220 | - $nav->assign('usage_relative', $storageInfo['relative']); |
|
| 221 | - |
|
| 222 | - $contentItems = []; |
|
| 223 | - |
|
| 224 | - // render the container content for every navigation item |
|
| 225 | - foreach ($navItems as $item) { |
|
| 226 | - $content = ''; |
|
| 227 | - if (isset($item['script'])) { |
|
| 228 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
| 229 | - } |
|
| 230 | - // parse submenus |
|
| 231 | - if (isset($item['sublist'])) { |
|
| 232 | - foreach ($item['sublist'] as $subitem) { |
|
| 233 | - $subcontent = ''; |
|
| 234 | - if (isset($subitem['script'])) { |
|
| 235 | - $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
| 236 | - } |
|
| 237 | - $contentItems[$subitem['id']] = [ |
|
| 238 | - 'id' => $subitem['id'], |
|
| 239 | - 'content' => $subcontent |
|
| 240 | - ]; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - $contentItems[$item['id']] = [ |
|
| 244 | - 'id' => $item['id'], |
|
| 245 | - 'content' => $content |
|
| 246 | - ]; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $event = new GenericEvent(null, ['hiddenFields' => []]); |
|
| 250 | - $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event); |
|
| 251 | - |
|
| 252 | - $params = []; |
|
| 253 | - $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
| 254 | - $params['owner'] = $storageInfo['owner']; |
|
| 255 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
| 256 | - $params['isPublic'] = false; |
|
| 257 | - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
| 258 | - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
| 259 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
| 260 | - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
| 261 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
| 262 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
| 263 | - $params['appNavigation'] = $nav; |
|
| 264 | - $params['appContents'] = $contentItems; |
|
| 265 | - $params['hiddenFields'] = $event->getArgument('hiddenFields'); |
|
| 266 | - |
|
| 267 | - $response = new TemplateResponse( |
|
| 268 | - $this->appName, |
|
| 269 | - 'index', |
|
| 270 | - $params |
|
| 271 | - ); |
|
| 272 | - $policy = new ContentSecurityPolicy(); |
|
| 273 | - $policy->addAllowedFrameDomain('\'self\''); |
|
| 274 | - $response->setContentSecurityPolicy($policy); |
|
| 275 | - |
|
| 276 | - return $response; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Redirects to the file list and highlight the given file id |
|
| 281 | - * |
|
| 282 | - * @param string $fileId file id to show |
|
| 283 | - * @return RedirectResponse redirect response or not found response |
|
| 284 | - * @throws \OCP\Files\NotFoundException |
|
| 285 | - */ |
|
| 286 | - private function showFile($fileId) { |
|
| 287 | - $uid = $this->userSession->getUser()->getUID(); |
|
| 288 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
| 289 | - $files = $baseFolder->getById($fileId); |
|
| 290 | - $params = []; |
|
| 291 | - |
|
| 292 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
| 293 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
| 294 | - $files = $baseFolder->getById($fileId); |
|
| 295 | - $params['view'] = 'trashbin'; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - if (!empty($files)) { |
|
| 299 | - $file = current($files); |
|
| 300 | - if ($file instanceof Folder) { |
|
| 301 | - // set the full path to enter the folder |
|
| 302 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
| 303 | - } else { |
|
| 304 | - // set parent path as dir |
|
| 305 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
| 306 | - // and scroll to the entry |
|
| 307 | - $params['scrollto'] = $file->getName(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
| 311 | - } |
|
| 312 | - throw new \OCP\Files\NotFoundException(); |
|
| 313 | - } |
|
| 54 | + /** @var string */ |
|
| 55 | + protected $appName; |
|
| 56 | + /** @var IRequest */ |
|
| 57 | + protected $request; |
|
| 58 | + /** @var IURLGenerator */ |
|
| 59 | + protected $urlGenerator; |
|
| 60 | + /** @var IL10N */ |
|
| 61 | + protected $l10n; |
|
| 62 | + /** @var IConfig */ |
|
| 63 | + protected $config; |
|
| 64 | + /** @var EventDispatcherInterface */ |
|
| 65 | + protected $eventDispatcher; |
|
| 66 | + /** @var IUserSession */ |
|
| 67 | + protected $userSession; |
|
| 68 | + /** @var IAppManager */ |
|
| 69 | + protected $appManager; |
|
| 70 | + /** @var IRootFolder */ |
|
| 71 | + protected $rootFolder; |
|
| 72 | + /** @var Helper */ |
|
| 73 | + protected $activityHelper; |
|
| 74 | + |
|
| 75 | + public function __construct(string $appName, |
|
| 76 | + IRequest $request, |
|
| 77 | + IURLGenerator $urlGenerator, |
|
| 78 | + IL10N $l10n, |
|
| 79 | + IConfig $config, |
|
| 80 | + EventDispatcherInterface $eventDispatcherInterface, |
|
| 81 | + IUserSession $userSession, |
|
| 82 | + IAppManager $appManager, |
|
| 83 | + IRootFolder $rootFolder, |
|
| 84 | + Helper $activityHelper |
|
| 85 | + ) { |
|
| 86 | + parent::__construct($appName, $request); |
|
| 87 | + $this->appName = $appName; |
|
| 88 | + $this->request = $request; |
|
| 89 | + $this->urlGenerator = $urlGenerator; |
|
| 90 | + $this->l10n = $l10n; |
|
| 91 | + $this->config = $config; |
|
| 92 | + $this->eventDispatcher = $eventDispatcherInterface; |
|
| 93 | + $this->userSession = $userSession; |
|
| 94 | + $this->appManager = $appManager; |
|
| 95 | + $this->rootFolder = $rootFolder; |
|
| 96 | + $this->activityHelper = $activityHelper; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param string $appName |
|
| 101 | + * @param string $scriptName |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + protected function renderScript($appName, $scriptName) { |
|
| 105 | + $content = ''; |
|
| 106 | + $appPath = \OC_App::getAppPath($appName); |
|
| 107 | + $scriptPath = $appPath . '/' . $scriptName; |
|
| 108 | + if (file_exists($scriptPath)) { |
|
| 109 | + // TODO: sanitize path / script name ? |
|
| 110 | + ob_start(); |
|
| 111 | + include $scriptPath; |
|
| 112 | + $content = ob_get_contents(); |
|
| 113 | + @ob_end_clean(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $content; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * FIXME: Replace with non static code |
|
| 121 | + * |
|
| 122 | + * @return array |
|
| 123 | + * @throws \OCP\Files\NotFoundException |
|
| 124 | + */ |
|
| 125 | + protected function getStorageInfo() { |
|
| 126 | + $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
| 127 | + |
|
| 128 | + return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @NoCSRFRequired |
|
| 133 | + * @NoAdminRequired |
|
| 134 | + * |
|
| 135 | + * @param string $dir |
|
| 136 | + * @param string $view |
|
| 137 | + * @param string $fileid |
|
| 138 | + * @return TemplateResponse|RedirectResponse |
|
| 139 | + */ |
|
| 140 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
| 141 | + if ($fileid !== null) { |
|
| 142 | + try { |
|
| 143 | + return $this->showFile($fileid); |
|
| 144 | + } catch (NotFoundException $e) { |
|
| 145 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
| 150 | + |
|
| 151 | + // Load the files we need |
|
| 152 | + \OCP\Util::addStyle('files', 'merged'); |
|
| 153 | + \OCP\Util::addScript('files', 'merged-index'); |
|
| 154 | + |
|
| 155 | + // mostly for the home storage's free space |
|
| 156 | + // FIXME: Make non static |
|
| 157 | + $storageInfo = $this->getStorageInfo(); |
|
| 158 | + |
|
| 159 | + $user = $this->userSession->getUser()->getUID(); |
|
| 160 | + |
|
| 161 | + // Get all the user favorites to create a submenu |
|
| 162 | + try { |
|
| 163 | + $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
| 164 | + } catch (\RuntimeException $e) { |
|
| 165 | + $favElements['folders'] = []; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $collapseClasses = ''; |
|
| 169 | + if (count($favElements['folders']) > 0) { |
|
| 170 | + $collapseClasses = 'collapsible'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $favoritesSublistArray = Array(); |
|
| 174 | + |
|
| 175 | + $navBarPositionPosition = 6; |
|
| 176 | + $currentCount = 0; |
|
| 177 | + foreach ($favElements['folders'] as $dir) { |
|
| 178 | + |
|
| 179 | + $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
| 180 | + $sortingValue = ++$currentCount; |
|
| 181 | + $element = [ |
|
| 182 | + 'id' => str_replace('/', '-', $dir), |
|
| 183 | + 'view' => 'files', |
|
| 184 | + 'href' => $link, |
|
| 185 | + 'dir' => $dir, |
|
| 186 | + 'order' => $navBarPositionPosition, |
|
| 187 | + 'folderPosition' => $sortingValue, |
|
| 188 | + 'name' => basename($dir), |
|
| 189 | + 'icon' => 'files', |
|
| 190 | + 'quickaccesselement' => 'true' |
|
| 191 | + ]; |
|
| 192 | + |
|
| 193 | + array_push($favoritesSublistArray, $element); |
|
| 194 | + $navBarPositionPosition++; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 198 | + |
|
| 199 | + // add the favorites entry in menu |
|
| 200 | + $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
| 201 | + $navItems['favorites']['classes'] = $collapseClasses; |
|
| 202 | + |
|
| 203 | + // parse every menu and add the expandedState user value |
|
| 204 | + foreach ($navItems as $key => $item) { |
|
| 205 | + if (isset($item['expandedState'])) { |
|
| 206 | + $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $nav->assign('navigationItems', $navItems); |
|
| 211 | + |
|
| 212 | + $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); |
|
| 213 | + if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 214 | + $totalSpace = $this->l10n->t('Unlimited'); |
|
| 215 | + } else { |
|
| 216 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
| 217 | + } |
|
| 218 | + $nav->assign('total_space', $totalSpace); |
|
| 219 | + $nav->assign('quota', $storageInfo['quota']); |
|
| 220 | + $nav->assign('usage_relative', $storageInfo['relative']); |
|
| 221 | + |
|
| 222 | + $contentItems = []; |
|
| 223 | + |
|
| 224 | + // render the container content for every navigation item |
|
| 225 | + foreach ($navItems as $item) { |
|
| 226 | + $content = ''; |
|
| 227 | + if (isset($item['script'])) { |
|
| 228 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
| 229 | + } |
|
| 230 | + // parse submenus |
|
| 231 | + if (isset($item['sublist'])) { |
|
| 232 | + foreach ($item['sublist'] as $subitem) { |
|
| 233 | + $subcontent = ''; |
|
| 234 | + if (isset($subitem['script'])) { |
|
| 235 | + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
| 236 | + } |
|
| 237 | + $contentItems[$subitem['id']] = [ |
|
| 238 | + 'id' => $subitem['id'], |
|
| 239 | + 'content' => $subcontent |
|
| 240 | + ]; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + $contentItems[$item['id']] = [ |
|
| 244 | + 'id' => $item['id'], |
|
| 245 | + 'content' => $content |
|
| 246 | + ]; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $event = new GenericEvent(null, ['hiddenFields' => []]); |
|
| 250 | + $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event); |
|
| 251 | + |
|
| 252 | + $params = []; |
|
| 253 | + $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
| 254 | + $params['owner'] = $storageInfo['owner']; |
|
| 255 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
| 256 | + $params['isPublic'] = false; |
|
| 257 | + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
| 258 | + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
| 259 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
| 260 | + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
| 261 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
| 262 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
| 263 | + $params['appNavigation'] = $nav; |
|
| 264 | + $params['appContents'] = $contentItems; |
|
| 265 | + $params['hiddenFields'] = $event->getArgument('hiddenFields'); |
|
| 266 | + |
|
| 267 | + $response = new TemplateResponse( |
|
| 268 | + $this->appName, |
|
| 269 | + 'index', |
|
| 270 | + $params |
|
| 271 | + ); |
|
| 272 | + $policy = new ContentSecurityPolicy(); |
|
| 273 | + $policy->addAllowedFrameDomain('\'self\''); |
|
| 274 | + $response->setContentSecurityPolicy($policy); |
|
| 275 | + |
|
| 276 | + return $response; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Redirects to the file list and highlight the given file id |
|
| 281 | + * |
|
| 282 | + * @param string $fileId file id to show |
|
| 283 | + * @return RedirectResponse redirect response or not found response |
|
| 284 | + * @throws \OCP\Files\NotFoundException |
|
| 285 | + */ |
|
| 286 | + private function showFile($fileId) { |
|
| 287 | + $uid = $this->userSession->getUser()->getUID(); |
|
| 288 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
| 289 | + $files = $baseFolder->getById($fileId); |
|
| 290 | + $params = []; |
|
| 291 | + |
|
| 292 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
| 293 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
| 294 | + $files = $baseFolder->getById($fileId); |
|
| 295 | + $params['view'] = 'trashbin'; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + if (!empty($files)) { |
|
| 299 | + $file = current($files); |
|
| 300 | + if ($file instanceof Folder) { |
|
| 301 | + // set the full path to enter the folder |
|
| 302 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
| 303 | + } else { |
|
| 304 | + // set parent path as dir |
|
| 305 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
| 306 | + // and scroll to the entry |
|
| 307 | + $params['scrollto'] = $file->getName(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
| 311 | + } |
|
| 312 | + throw new \OCP\Files\NotFoundException(); |
|
| 313 | + } |
|
| 314 | 314 | } |