|
|
|
|
@ -33,6 +33,8 @@ use OCP\AppFramework\Controller; |
|
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
|
|
|
|
use OCP\AppFramework\Http\RedirectResponse; |
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
|
|
|
|
use OCP\App\IAppManager; |
|
|
|
|
use OCP\Files\Folder; |
|
|
|
|
use OCP\Files\IRootFolder; |
|
|
|
|
use OCP\Files\NotFoundException; |
|
|
|
|
use OCP\IConfig; |
|
|
|
|
@ -41,8 +43,6 @@ use OCP\IRequest; |
|
|
|
|
use OCP\IURLGenerator; |
|
|
|
|
use OCP\IUserSession; |
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
|
|
use OCP\Files\Folder; |
|
|
|
|
use OCP\App\IAppManager; |
|
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -73,27 +73,27 @@ class ViewController extends Controller { |
|
|
|
|
protected $activityHelper; |
|
|
|
|
|
|
|
|
|
public function __construct(string $appName, |
|
|
|
|
IRequest $request, |
|
|
|
|
IURLGenerator $urlGenerator, |
|
|
|
|
IL10N $l10n, |
|
|
|
|
IConfig $config, |
|
|
|
|
EventDispatcherInterface $eventDispatcherInterface, |
|
|
|
|
IUserSession $userSession, |
|
|
|
|
IAppManager $appManager, |
|
|
|
|
IRootFolder $rootFolder, |
|
|
|
|
Helper $activityHelper |
|
|
|
|
IRequest $request, |
|
|
|
|
IURLGenerator $urlGenerator, |
|
|
|
|
IL10N $l10n, |
|
|
|
|
IConfig $config, |
|
|
|
|
EventDispatcherInterface $eventDispatcherInterface, |
|
|
|
|
IUserSession $userSession, |
|
|
|
|
IAppManager $appManager, |
|
|
|
|
IRootFolder $rootFolder, |
|
|
|
|
Helper $activityHelper |
|
|
|
|
) { |
|
|
|
|
parent::__construct($appName, $request); |
|
|
|
|
$this->appName = $appName; |
|
|
|
|
$this->request = $request; |
|
|
|
|
$this->urlGenerator = $urlGenerator; |
|
|
|
|
$this->l10n = $l10n; |
|
|
|
|
$this->config = $config; |
|
|
|
|
$this->appName = $appName; |
|
|
|
|
$this->request = $request; |
|
|
|
|
$this->urlGenerator = $urlGenerator; |
|
|
|
|
$this->l10n = $l10n; |
|
|
|
|
$this->config = $config; |
|
|
|
|
$this->eventDispatcher = $eventDispatcherInterface; |
|
|
|
|
$this->userSession = $userSession; |
|
|
|
|
$this->appManager = $appManager; |
|
|
|
|
$this->rootFolder = $rootFolder; |
|
|
|
|
$this->activityHelper = $activityHelper; |
|
|
|
|
$this->userSession = $userSession; |
|
|
|
|
$this->appManager = $appManager; |
|
|
|
|
$this->rootFolder = $rootFolder; |
|
|
|
|
$this->activityHelper = $activityHelper; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -102,8 +102,8 @@ class ViewController extends Controller { |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
protected function renderScript($appName, $scriptName) { |
|
|
|
|
$content = ''; |
|
|
|
|
$appPath = \OC_App::getAppPath($appName); |
|
|
|
|
$content = ''; |
|
|
|
|
$appPath = \OC_App::getAppPath($appName); |
|
|
|
|
$scriptPath = $appPath . '/' . $scriptName; |
|
|
|
|
if (file_exists($scriptPath)) { |
|
|
|
|
// TODO: sanitize path / script name ? |
|
|
|
|
@ -112,6 +112,7 @@ class ViewController extends Controller { |
|
|
|
|
$content = ob_get_contents(); |
|
|
|
|
@ob_end_clean(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -123,6 +124,7 @@ class ViewController extends Controller { |
|
|
|
|
*/ |
|
|
|
|
protected function getStorageInfo() { |
|
|
|
|
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
|
|
|
|
|
|
|
|
return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -156,6 +158,7 @@ class ViewController extends Controller { |
|
|
|
|
|
|
|
|
|
$user = $this->userSession->getUser()->getUID(); |
|
|
|
|
|
|
|
|
|
// Get all the user favorites to create a submenu |
|
|
|
|
try { |
|
|
|
|
$favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); |
|
|
|
|
} catch (\RuntimeException $e) { |
|
|
|
|
@ -170,21 +173,21 @@ class ViewController extends Controller { |
|
|
|
|
$favoritesSublistArray = Array(); |
|
|
|
|
|
|
|
|
|
$navBarPositionPosition = 6; |
|
|
|
|
$currentCount = 0; |
|
|
|
|
$currentCount = 0; |
|
|
|
|
foreach ($favElements['folders'] as $dir) { |
|
|
|
|
|
|
|
|
|
$id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); |
|
|
|
|
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
|
|
|
$id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); |
|
|
|
|
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); |
|
|
|
|
$sortingValue = ++$currentCount; |
|
|
|
|
$element = [ |
|
|
|
|
'id' => str_replace('/', '-', $dir), |
|
|
|
|
'view' => 'files', |
|
|
|
|
'href' => $link, |
|
|
|
|
'dir' => $dir, |
|
|
|
|
'order' => $navBarPositionPosition, |
|
|
|
|
'folderPosition' => $sortingValue, |
|
|
|
|
'name' => $id, |
|
|
|
|
'icon' => 'files', |
|
|
|
|
$element = [ |
|
|
|
|
'id' => str_replace('/', '-', $dir), |
|
|
|
|
'view' => 'files', |
|
|
|
|
'href' => $link, |
|
|
|
|
'dir' => $dir, |
|
|
|
|
'order' => $navBarPositionPosition, |
|
|
|
|
'folderPosition' => $sortingValue, |
|
|
|
|
'name' => $id, |
|
|
|
|
'icon' => 'files', |
|
|
|
|
'quickaccesselement' => 'true' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
@ -192,28 +195,18 @@ class ViewController extends Controller { |
|
|
|
|
$navBarPositionPosition++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
|
|
|
|
|
|
|
|
// show_Quick_Access stored as string |
|
|
|
|
$defaultExpandedState = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', '0') === '1'; |
|
|
|
|
|
|
|
|
|
\OCA\Files\App::getNavigationManager()->add( |
|
|
|
|
[ |
|
|
|
|
'id' => 'favorites', |
|
|
|
|
'appname' => 'files', |
|
|
|
|
'script' => 'simplelist.php', |
|
|
|
|
'classes' => $collapseClasses, |
|
|
|
|
'order' => 5, |
|
|
|
|
'name' => $this->l10n->t('Favorites'), |
|
|
|
|
'sublist' => $favoritesSublistArray, |
|
|
|
|
'defaultExpandedState' => $defaultExpandedState, |
|
|
|
|
'enableMenuButton' => 0, |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
// add the favorites entry in menu |
|
|
|
|
$navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
|
|
|
$navItems['favorites']['classes'] = $collapseClasses; |
|
|
|
|
|
|
|
|
|
$navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
|
|
|
usort($navItems, function ($item1, $item2) { |
|
|
|
|
return $item1['order'] - $item2['order']; |
|
|
|
|
}); |
|
|
|
|
// parse every menu and add the expandedState user value |
|
|
|
|
foreach ($navItems as $key => $item) { |
|
|
|
|
if (isset($item['expandedState'])) { |
|
|
|
|
$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$nav->assign('navigationItems', $navItems); |
|
|
|
|
|
|
|
|
|
@ -235,29 +228,42 @@ class ViewController extends Controller { |
|
|
|
|
if (isset($item['script'])) { |
|
|
|
|
$content = $this->renderScript($item['appname'], $item['script']); |
|
|
|
|
} |
|
|
|
|
$contentItem = []; |
|
|
|
|
$contentItem['id'] = $item['id']; |
|
|
|
|
$contentItem['content'] = $content; |
|
|
|
|
$contentItems[] = $contentItem; |
|
|
|
|
// parse submenus |
|
|
|
|
if (isset($item['sublist'])) { |
|
|
|
|
foreach ($item['sublist'] as $subitem) { |
|
|
|
|
$subcontent = ''; |
|
|
|
|
if (isset($subitem['script'])) { |
|
|
|
|
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
|
|
|
} |
|
|
|
|
$contentItems[$subitem['id']] = [ |
|
|
|
|
'id' => $subitem['id'], |
|
|
|
|
'content' => $subcontent |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$contentItems[$item['id']] = [ |
|
|
|
|
'id' => $item['id'], |
|
|
|
|
'content' => $content |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$event = new GenericEvent(null, ['hiddenFields' => []]); |
|
|
|
|
$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event); |
|
|
|
|
|
|
|
|
|
$params = []; |
|
|
|
|
$params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
|
|
|
$params['owner'] = $storageInfo['owner']; |
|
|
|
|
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
|
|
|
$params['isPublic'] = false; |
|
|
|
|
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
|
|
|
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
|
|
|
$params = []; |
|
|
|
|
$params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
|
|
|
$params['owner'] = $storageInfo['owner']; |
|
|
|
|
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
|
|
|
$params['isPublic'] = false; |
|
|
|
|
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
|
|
|
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
|
|
|
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
|
|
|
$showHidden = (bool)$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
|
|
|
$params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
|
|
|
$params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
|
|
|
$params['appNavigation'] = $nav; |
|
|
|
|
$params['appContents'] = $contentItems; |
|
|
|
|
$params['hiddenFields'] = $event->getArgument('hiddenFields'); |
|
|
|
|
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
|
|
|
$params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
|
|
|
$params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
|
|
|
$params['appNavigation'] = $nav; |
|
|
|
|
$params['appContents'] = $contentItems; |
|
|
|
|
$params['hiddenFields'] = $event->getArgument('hiddenFields'); |
|
|
|
|
|
|
|
|
|
$response = new TemplateResponse( |
|
|
|
|
$this->appName, |
|
|
|
|
@ -268,7 +274,6 @@ class ViewController extends Controller { |
|
|
|
|
$policy->addAllowedFrameDomain('\'self\''); |
|
|
|
|
$response->setContentSecurityPolicy($policy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -280,14 +285,14 @@ class ViewController extends Controller { |
|
|
|
|
* @throws \OCP\Files\NotFoundException |
|
|
|
|
*/ |
|
|
|
|
private function showFile($fileId) { |
|
|
|
|
$uid = $this->userSession->getUser()->getUID(); |
|
|
|
|
$uid = $this->userSession->getUser()->getUID(); |
|
|
|
|
$baseFolder = $this->rootFolder->getUserFolder($uid); |
|
|
|
|
$files = $baseFolder->getById($fileId); |
|
|
|
|
$params = []; |
|
|
|
|
$files = $baseFolder->getById($fileId); |
|
|
|
|
$params = []; |
|
|
|
|
|
|
|
|
|
if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
|
|
|
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
|
|
|
$files = $baseFolder->getById($fileId); |
|
|
|
|
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
|
|
|
$files = $baseFolder->getById($fileId); |
|
|
|
|
$params['view'] = 'trashbin'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -302,6 +307,7 @@ class ViewController extends Controller { |
|
|
|
|
// and scroll to the entry |
|
|
|
|
$params['scrollto'] = $file->getName(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
|
|
|
} |
|
|
|
|
throw new \OCP\Files\NotFoundException(); |
|
|
|
|
|