|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -171,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'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
@ -193,19 +195,16 @@ class ViewController extends Controller {
|
|
|
|
|
$navBarPositionPosition++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
|
|
|
|
|
|
|
|
|
|
// transform the favorites entry in menu
|
|
|
|
|
// add the favorites entry in menu
|
|
|
|
|
$navItems['favorites']['sublist'] = $favoritesSublistArray;
|
|
|
|
|
$navItems['favorites']['classes'] = $collapseClasses;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// parse every menu and add the expandedState user value
|
|
|
|
|
foreach ($navItems as $key => $item) {
|
|
|
|
|
if (isset($item['expandedState'])) {
|
|
|
|
|
$defaultValue = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
|
|
|
|
|
$navItems[$key]['defaultExpandedState'] = $defaultValue;
|
|
|
|
|
$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -237,34 +236,34 @@ class ViewController extends Controller {
|
|
|
|
|
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
|
|
|
|
|
}
|
|
|
|
|
$contentItems[$subitem['id']] = [
|
|
|
|
|
'id' => $subitem['id'],
|
|
|
|
|
'content' =>$subcontent
|
|
|
|
|
'id' => $subitem['id'],
|
|
|
|
|
'content' => $subcontent
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$contentItems[$item['id']] = [
|
|
|
|
|
'id' => $item['id'],
|
|
|
|
|
'content' =>$content
|
|
|
|
|
'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,
|
|
|
|
@ -275,7 +274,6 @@ class ViewController extends Controller {
|
|
|
|
|
$policy->addAllowedFrameDomain('\'self\'');
|
|
|
|
|
$response->setContentSecurityPolicy($policy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -287,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';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -309,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();
|
|
|
|
|