2015-11-16 22:57:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2016-05-04 11:28:06 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-11-16 22:57:41 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files\Controller;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Controller;
|
2015-12-02 19:30:40 +03:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2016-08-19 09:15:30 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-06-07 14:51:16 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2016-04-12 12:08:26 +03:00
|
|
|
use OCP\IConfig;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\INavigationManager;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IURLGenerator;
|
2016-04-12 12:08:26 +03:00
|
|
|
use OCP\IUserSession;
|
2015-11-16 22:57:41 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-05-04 11:28:06 +03:00
|
|
|
use OCP\Files\Folder;
|
2016-05-11 20:41:36 +03:00
|
|
|
use OCP\App\IAppManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ViewController
|
|
|
|
*
|
|
|
|
* @package OCA\Files\Controller
|
|
|
|
*/
|
|
|
|
class ViewController extends Controller {
|
|
|
|
/** @var string */
|
|
|
|
protected $appName;
|
|
|
|
/** @var IRequest */
|
|
|
|
protected $request;
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
protected $urlGenerator;
|
|
|
|
/** @var IL10N */
|
|
|
|
protected $l10n;
|
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
|
|
|
/** @var EventDispatcherInterface */
|
|
|
|
protected $eventDispatcher;
|
2016-04-12 12:08:26 +03:00
|
|
|
/** @var IUserSession */
|
|
|
|
protected $userSession;
|
2016-05-11 20:41:36 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
protected $appManager;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IRootFolder */
|
2016-05-11 20:41:36 +03:00
|
|
|
protected $rootFolder;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IURLGenerator $urlGenerator
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param EventDispatcherInterface $eventDispatcherInterface
|
2016-04-12 18:10:09 +03:00
|
|
|
* @param IUserSession $userSession
|
2016-05-11 20:41:36 +03:00
|
|
|
* @param IAppManager $appManager
|
2016-08-19 09:15:30 +03:00
|
|
|
* @param IRootFolder $rootFolder
|
2015-11-16 22:57:41 +03:00
|
|
|
*/
|
|
|
|
public function __construct($appName,
|
|
|
|
IRequest $request,
|
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
IL10N $l10n,
|
|
|
|
IConfig $config,
|
2016-04-12 12:08:26 +03:00
|
|
|
EventDispatcherInterface $eventDispatcherInterface,
|
2016-05-04 11:28:06 +03:00
|
|
|
IUserSession $userSession,
|
2016-05-11 20:41:36 +03:00
|
|
|
IAppManager $appManager,
|
2016-08-19 09:15:30 +03:00
|
|
|
IRootFolder $rootFolder
|
2016-05-04 11:28:06 +03:00
|
|
|
) {
|
2015-11-16 22:57:41 +03:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->appName = $appName;
|
|
|
|
$this->request = $request;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
$this->config = $config;
|
|
|
|
$this->eventDispatcher = $eventDispatcherInterface;
|
2016-04-12 12:08:26 +03:00
|
|
|
$this->userSession = $userSession;
|
2016-05-11 20:41:36 +03:00
|
|
|
$this->appManager = $appManager;
|
|
|
|
$this->rootFolder = $rootFolder;
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param string $scriptName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function renderScript($appName, $scriptName) {
|
|
|
|
$content = '';
|
|
|
|
$appPath = \OC_App::getAppPath($appName);
|
|
|
|
$scriptPath = $appPath . '/' . $scriptName;
|
|
|
|
if (file_exists($scriptPath)) {
|
|
|
|
// TODO: sanitize path / script name ?
|
|
|
|
ob_start();
|
|
|
|
include $scriptPath;
|
|
|
|
$content = ob_get_contents();
|
|
|
|
@ob_end_clean();
|
|
|
|
}
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FIXME: Replace with non static code
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
*/
|
|
|
|
protected function getStorageInfo() {
|
|
|
|
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
|
|
|
|
return \OC_Helper::getStorageInfo('/', $dirInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $dir
|
|
|
|
* @param string $view
|
2016-05-04 11:28:06 +03:00
|
|
|
* @param string $fileid
|
2016-08-19 11:10:19 +03:00
|
|
|
* @return TemplateResponse|RedirectResponse
|
2015-11-16 22:57:41 +03:00
|
|
|
*/
|
2016-08-19 11:10:19 +03:00
|
|
|
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
|
2016-05-04 11:28:06 +03:00
|
|
|
if ($fileid !== null) {
|
2016-06-07 14:51:16 +03:00
|
|
|
try {
|
|
|
|
return $this->showFile($fileid);
|
|
|
|
} catch (NotFoundException $e) {
|
2016-08-19 11:10:19 +03:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
|
2016-06-07 14:51:16 +03:00
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
|
|
|
|
2015-11-17 15:36:40 +03:00
|
|
|
$nav = new \OCP\Template('files', 'appnavigation', '');
|
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
// Load the files we need
|
2016-09-26 11:50:43 +03:00
|
|
|
\OCP\Util::addScript('files', 'app');
|
|
|
|
\OCP\Util::addScript('files', 'file-upload');
|
|
|
|
\OCP\Util::addScript('files', 'newfilemenu');
|
|
|
|
\OCP\Util::addScript('files', 'jquery.fileupload');
|
|
|
|
\OCP\Util::addScript('files', 'jquery-visibility');
|
|
|
|
\OCP\Util::addScript('files', 'fileinfomodel');
|
|
|
|
\OCP\Util::addScript('files', 'filesummary');
|
|
|
|
\OCP\Util::addScript('files', 'breadcrumb');
|
|
|
|
\OCP\Util::addScript('files', 'filelist');
|
|
|
|
\OCP\Util::addScript('files', 'search');
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
\OCP\Util::addScript('files', 'favoritesfilelist');
|
2016-07-22 16:20:51 +03:00
|
|
|
\OCP\Util::addScript('files', 'recentfilelist');
|
2015-11-16 22:57:41 +03:00
|
|
|
\OCP\Util::addScript('files', 'tagsplugin');
|
2016-07-05 16:05:01 +03:00
|
|
|
\OCP\Util::addScript('files', 'gotoplugin');
|
2015-11-16 22:57:41 +03:00
|
|
|
\OCP\Util::addScript('files', 'favoritesplugin');
|
2016-07-22 16:20:51 +03:00
|
|
|
\OCP\Util::addScript('files', 'recentplugin');
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
\OCP\Util::addScript('files', 'detailfileinfoview');
|
2016-07-04 13:02:07 +03:00
|
|
|
\OCP\Util::addScript('files', 'sidebarpreviewmanager');
|
2016-07-04 13:54:12 +03:00
|
|
|
\OCP\Util::addScript('files', 'sidebarpreviewtext');
|
2015-11-16 22:57:41 +03:00
|
|
|
\OCP\Util::addScript('files', 'detailtabview');
|
|
|
|
\OCP\Util::addScript('files', 'mainfileinfodetailview');
|
|
|
|
\OCP\Util::addScript('files', 'detailsview');
|
2017-03-21 18:35:31 +03:00
|
|
|
\OCP\Util::addStyle('files', 'merged');
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2016-09-26 11:50:43 +03:00
|
|
|
\OCP\Util::addScript('files', 'fileactions');
|
|
|
|
\OCP\Util::addScript('files', 'fileactionsmenu');
|
|
|
|
\OCP\Util::addScript('files', 'files');
|
|
|
|
\OCP\Util::addScript('files', 'keyboardshortcuts');
|
|
|
|
\OCP\Util::addScript('files', 'navigation');
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
// mostly for the home storage's free space
|
|
|
|
// FIXME: Make non static
|
|
|
|
$storageInfo = $this->getStorageInfo();
|
|
|
|
|
|
|
|
\OCA\Files\App::getNavigationManager()->add(
|
|
|
|
[
|
|
|
|
'id' => 'favorites',
|
|
|
|
'appname' => 'files',
|
|
|
|
'script' => 'simplelist.php',
|
|
|
|
'order' => 5,
|
|
|
|
'name' => $this->l10n->t('Favorites')
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
|
|
|
|
usort($navItems, function($item1, $item2) {
|
|
|
|
return $item1['order'] - $item2['order'];
|
|
|
|
});
|
|
|
|
$nav->assign('navigationItems', $navItems);
|
|
|
|
|
|
|
|
$contentItems = [];
|
|
|
|
|
|
|
|
// render the container content for every navigation item
|
|
|
|
foreach ($navItems as $item) {
|
|
|
|
$content = '';
|
|
|
|
if (isset($item['script'])) {
|
|
|
|
$content = $this->renderScript($item['appname'], $item['script']);
|
|
|
|
}
|
|
|
|
$contentItem = [];
|
|
|
|
$contentItem['id'] = $item['id'];
|
|
|
|
$contentItem['content'] = $content;
|
|
|
|
$contentItems[] = $contentItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts');
|
|
|
|
|
|
|
|
$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');
|
2016-04-12 12:08:26 +03:00
|
|
|
$user = $this->userSession->getUser()->getUID();
|
|
|
|
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
|
2016-04-12 12:51:50 +03:00
|
|
|
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
2016-04-12 18:10:09 +03:00
|
|
|
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
|
|
|
|
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
|
2016-06-07 14:51:16 +03:00
|
|
|
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
|
2015-11-16 22:57:41 +03:00
|
|
|
$params['appNavigation'] = $nav;
|
|
|
|
$params['appContents'] = $contentItems;
|
|
|
|
|
2015-12-02 19:30:40 +03:00
|
|
|
$response = new TemplateResponse(
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->appName,
|
|
|
|
'index',
|
|
|
|
$params
|
|
|
|
);
|
2015-12-02 19:30:40 +03:00
|
|
|
$policy = new ContentSecurityPolicy();
|
|
|
|
$policy->addAllowedFrameDomain('\'self\'');
|
|
|
|
$response->setContentSecurityPolicy($policy);
|
|
|
|
|
|
|
|
return $response;
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects to the file list and highlight the given file id
|
|
|
|
*
|
|
|
|
* @param string $fileId file id to show
|
2016-06-07 14:51:16 +03:00
|
|
|
* @return RedirectResponse redirect response or not found response
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
2016-05-04 11:28:06 +03:00
|
|
|
*/
|
2016-08-19 09:15:30 +03:00
|
|
|
private function showFile($fileId) {
|
2016-06-07 14:51:16 +03:00
|
|
|
$uid = $this->userSession->getUser()->getUID();
|
2016-08-19 09:15:30 +03:00
|
|
|
$baseFolder = $this->rootFolder->getUserFolder($uid);
|
2016-06-07 14:51:16 +03:00
|
|
|
$files = $baseFolder->getById($fileId);
|
|
|
|
$params = [];
|
2016-05-11 20:41:36 +03:00
|
|
|
|
2016-06-07 14:51:16 +03:00
|
|
|
if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
|
|
|
|
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
|
|
|
|
$files = $baseFolder->getById($fileId);
|
|
|
|
$params['view'] = 'trashbin';
|
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
|
2016-06-07 14:51:16 +03:00
|
|
|
if (!empty($files)) {
|
|
|
|
$file = current($files);
|
|
|
|
if ($file instanceof Folder) {
|
|
|
|
// set the full path to enter the folder
|
|
|
|
$params['dir'] = $baseFolder->getRelativePath($file->getPath());
|
|
|
|
} else {
|
|
|
|
// set parent path as dir
|
|
|
|
$params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
|
|
|
|
// and scroll to the entry
|
|
|
|
$params['scrollto'] = $file->getName();
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2016-06-07 14:51:16 +03:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2016-06-07 14:51:16 +03:00
|
|
|
throw new \OCP\Files\NotFoundException();
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|