@@ -38,99 +38,99 @@ |
||
38 | 38 | */ |
39 | 39 | class TagService { |
40 | 40 | |
41 | - /** @var IUserSession */ |
|
42 | - private $userSession; |
|
43 | - /** @var IManager */ |
|
44 | - private $activityManager; |
|
45 | - /** @var ITags */ |
|
46 | - private $tagger; |
|
47 | - /** @var Folder */ |
|
48 | - private $homeFolder; |
|
41 | + /** @var IUserSession */ |
|
42 | + private $userSession; |
|
43 | + /** @var IManager */ |
|
44 | + private $activityManager; |
|
45 | + /** @var ITags */ |
|
46 | + private $tagger; |
|
47 | + /** @var Folder */ |
|
48 | + private $homeFolder; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param IUserSession $userSession |
|
52 | - * @param IManager $activityManager |
|
53 | - * @param ITags $tagger |
|
54 | - * @param Folder $homeFolder |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - IUserSession $userSession, |
|
58 | - IManager $activityManager, |
|
59 | - ITags $tagger, |
|
60 | - Folder $homeFolder |
|
61 | - ) { |
|
62 | - $this->userSession = $userSession; |
|
63 | - $this->activityManager = $activityManager; |
|
64 | - $this->tagger = $tagger; |
|
65 | - $this->homeFolder = $homeFolder; |
|
66 | - } |
|
50 | + /** |
|
51 | + * @param IUserSession $userSession |
|
52 | + * @param IManager $activityManager |
|
53 | + * @param ITags $tagger |
|
54 | + * @param Folder $homeFolder |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + IUserSession $userSession, |
|
58 | + IManager $activityManager, |
|
59 | + ITags $tagger, |
|
60 | + Folder $homeFolder |
|
61 | + ) { |
|
62 | + $this->userSession = $userSession; |
|
63 | + $this->activityManager = $activityManager; |
|
64 | + $this->tagger = $tagger; |
|
65 | + $this->homeFolder = $homeFolder; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Updates the tags of the specified file path. |
|
70 | - * The passed tags are absolute, which means they will |
|
71 | - * replace the actual tag selection. |
|
72 | - * |
|
73 | - * @param string $path path |
|
74 | - * @param array $tags array of tags |
|
75 | - * @return array list of tags |
|
76 | - * @throws \OCP\Files\NotFoundException if the file does not exist |
|
77 | - */ |
|
78 | - public function updateFileTags($path, $tags) { |
|
79 | - $fileId = $this->homeFolder->get($path)->getId(); |
|
68 | + /** |
|
69 | + * Updates the tags of the specified file path. |
|
70 | + * The passed tags are absolute, which means they will |
|
71 | + * replace the actual tag selection. |
|
72 | + * |
|
73 | + * @param string $path path |
|
74 | + * @param array $tags array of tags |
|
75 | + * @return array list of tags |
|
76 | + * @throws \OCP\Files\NotFoundException if the file does not exist |
|
77 | + */ |
|
78 | + public function updateFileTags($path, $tags) { |
|
79 | + $fileId = $this->homeFolder->get($path)->getId(); |
|
80 | 80 | |
81 | - $currentTags = $this->tagger->getTagsForObjects(array($fileId)); |
|
81 | + $currentTags = $this->tagger->getTagsForObjects(array($fileId)); |
|
82 | 82 | |
83 | - if (!empty($currentTags)) { |
|
84 | - $currentTags = current($currentTags); |
|
85 | - } |
|
83 | + if (!empty($currentTags)) { |
|
84 | + $currentTags = current($currentTags); |
|
85 | + } |
|
86 | 86 | |
87 | - $newTags = array_diff($tags, $currentTags); |
|
88 | - foreach ($newTags as $tag) { |
|
89 | - if ($tag === Tags::TAG_FAVORITE) { |
|
90 | - $this->addActivity(true, $fileId, $path); |
|
91 | - } |
|
92 | - $this->tagger->tagAs($fileId, $tag); |
|
93 | - } |
|
94 | - $deletedTags = array_diff($currentTags, $tags); |
|
95 | - foreach ($deletedTags as $tag) { |
|
96 | - if ($tag === Tags::TAG_FAVORITE) { |
|
97 | - $this->addActivity(false, $fileId, $path); |
|
98 | - } |
|
99 | - $this->tagger->unTag($fileId, $tag); |
|
100 | - } |
|
87 | + $newTags = array_diff($tags, $currentTags); |
|
88 | + foreach ($newTags as $tag) { |
|
89 | + if ($tag === Tags::TAG_FAVORITE) { |
|
90 | + $this->addActivity(true, $fileId, $path); |
|
91 | + } |
|
92 | + $this->tagger->tagAs($fileId, $tag); |
|
93 | + } |
|
94 | + $deletedTags = array_diff($currentTags, $tags); |
|
95 | + foreach ($deletedTags as $tag) { |
|
96 | + if ($tag === Tags::TAG_FAVORITE) { |
|
97 | + $this->addActivity(false, $fileId, $path); |
|
98 | + } |
|
99 | + $this->tagger->unTag($fileId, $tag); |
|
100 | + } |
|
101 | 101 | |
102 | - // TODO: re-read from tagger to make sure the |
|
103 | - // list is up to date, in case of concurrent changes ? |
|
104 | - return $tags; |
|
105 | - } |
|
102 | + // TODO: re-read from tagger to make sure the |
|
103 | + // list is up to date, in case of concurrent changes ? |
|
104 | + return $tags; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @param bool $addToFavorite |
|
109 | - * @param int $fileId |
|
110 | - * @param string $path |
|
111 | - */ |
|
112 | - protected function addActivity($addToFavorite, $fileId, $path) { |
|
113 | - $user = $this->userSession->getUser(); |
|
114 | - if (!$user instanceof IUser) { |
|
115 | - return; |
|
116 | - } |
|
107 | + /** |
|
108 | + * @param bool $addToFavorite |
|
109 | + * @param int $fileId |
|
110 | + * @param string $path |
|
111 | + */ |
|
112 | + protected function addActivity($addToFavorite, $fileId, $path) { |
|
113 | + $user = $this->userSession->getUser(); |
|
114 | + if (!$user instanceof IUser) { |
|
115 | + return; |
|
116 | + } |
|
117 | 117 | |
118 | - $event = $this->activityManager->generateEvent(); |
|
119 | - try { |
|
120 | - $event->setApp('files') |
|
121 | - ->setObject('files', $fileId, $path) |
|
122 | - ->setType('favorite') |
|
123 | - ->setAuthor($user->getUID()) |
|
124 | - ->setAffectedUser($user->getUID()) |
|
125 | - ->setTimestamp(time()) |
|
126 | - ->setSubject( |
|
127 | - $addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED, |
|
128 | - ['id' => $fileId, 'path' => $path] |
|
129 | - ); |
|
130 | - $this->activityManager->publish($event); |
|
131 | - } catch (\InvalidArgumentException $e) { |
|
132 | - } catch (\BadMethodCallException $e) { |
|
133 | - } |
|
134 | - } |
|
118 | + $event = $this->activityManager->generateEvent(); |
|
119 | + try { |
|
120 | + $event->setApp('files') |
|
121 | + ->setObject('files', $fileId, $path) |
|
122 | + ->setType('favorite') |
|
123 | + ->setAuthor($user->getUID()) |
|
124 | + ->setAffectedUser($user->getUID()) |
|
125 | + ->setTimestamp(time()) |
|
126 | + ->setSubject( |
|
127 | + $addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED, |
|
128 | + ['id' => $fileId, 'path' => $path] |
|
129 | + ); |
|
130 | + $this->activityManager->publish($event); |
|
131 | + } catch (\InvalidArgumentException $e) { |
|
132 | + } catch (\BadMethodCallException $e) { |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
136 | 136 |
@@ -29,23 +29,23 @@ |
||
29 | 29 | use OCP\Util; |
30 | 30 | |
31 | 31 | class SettingsController extends Controller { |
32 | - public function __construct($appName, IRequest $request) { |
|
33 | - parent::__construct($appName, $request); |
|
34 | - } |
|
32 | + public function __construct($appName, IRequest $request) { |
|
33 | + parent::__construct($appName, $request); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $maxUploadSize |
|
38 | - * @return JSONResponse |
|
39 | - */ |
|
40 | - public function setMaxUploadSize($maxUploadSize) { |
|
41 | - $setMaxSize = \OC_Files::setUploadLimit(Util::computerFileSize($maxUploadSize)); |
|
36 | + /** |
|
37 | + * @param string $maxUploadSize |
|
38 | + * @return JSONResponse |
|
39 | + */ |
|
40 | + public function setMaxUploadSize($maxUploadSize) { |
|
41 | + $setMaxSize = \OC_Files::setUploadLimit(Util::computerFileSize($maxUploadSize)); |
|
42 | 42 | |
43 | - if ($setMaxSize === false) { |
|
44 | - return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
45 | - } else { |
|
46 | - return new JSONResponse([ |
|
47 | - 'maxUploadSize' => Util::humanFileSize($setMaxSize) |
|
48 | - ]); |
|
49 | - } |
|
50 | - } |
|
43 | + if ($setMaxSize === false) { |
|
44 | + return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
45 | + } else { |
|
46 | + return new JSONResponse([ |
|
47 | + 'maxUploadSize' => Util::humanFileSize($setMaxSize) |
|
48 | + ]); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | protected function renderScript($appName, $scriptName) { |
110 | 110 | $content = ''; |
111 | 111 | $appPath = \OC_App::getAppPath($appName); |
112 | - $scriptPath = $appPath . '/' . $scriptName; |
|
112 | + $scriptPath = $appPath.'/'.$scriptName; |
|
113 | 113 | if (file_exists($scriptPath)) { |
114 | 114 | // TODO: sanitize path / script name ? |
115 | 115 | ob_start(); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
227 | 227 | |
228 | 228 | $params = []; |
229 | - $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
229 | + $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
230 | 230 | $params['owner'] = $storageInfo['owner']; |
231 | 231 | $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
232 | 232 | $params['isPublic'] = false; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $params = []; |
267 | 267 | |
268 | 268 | if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
269 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
269 | + $baseFolder = $this->rootFolder->get($uid.'/files_trashbin/files/'); |
|
270 | 270 | $files = $baseFolder->getById($fileId); |
271 | 271 | $params['view'] = 'trashbin'; |
272 | 272 | } |
@@ -49,207 +49,207 @@ |
||
49 | 49 | * @package OCA\Files\Controller |
50 | 50 | */ |
51 | 51 | class ViewController extends Controller { |
52 | - /** @var string */ |
|
53 | - protected $appName; |
|
54 | - /** @var IRequest */ |
|
55 | - protected $request; |
|
56 | - /** @var IURLGenerator */ |
|
57 | - protected $urlGenerator; |
|
58 | - /** @var IL10N */ |
|
59 | - protected $l10n; |
|
60 | - /** @var IConfig */ |
|
61 | - protected $config; |
|
62 | - /** @var EventDispatcherInterface */ |
|
63 | - protected $eventDispatcher; |
|
64 | - /** @var IUserSession */ |
|
65 | - protected $userSession; |
|
66 | - /** @var IAppManager */ |
|
67 | - protected $appManager; |
|
68 | - /** @var IRootFolder */ |
|
69 | - protected $rootFolder; |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $appName |
|
73 | - * @param IRequest $request |
|
74 | - * @param IURLGenerator $urlGenerator |
|
75 | - * @param IL10N $l10n |
|
76 | - * @param IConfig $config |
|
77 | - * @param EventDispatcherInterface $eventDispatcherInterface |
|
78 | - * @param IUserSession $userSession |
|
79 | - * @param IAppManager $appManager |
|
80 | - * @param IRootFolder $rootFolder |
|
81 | - */ |
|
82 | - public function __construct($appName, |
|
83 | - IRequest $request, |
|
84 | - IURLGenerator $urlGenerator, |
|
85 | - IL10N $l10n, |
|
86 | - IConfig $config, |
|
87 | - EventDispatcherInterface $eventDispatcherInterface, |
|
88 | - IUserSession $userSession, |
|
89 | - IAppManager $appManager, |
|
90 | - IRootFolder $rootFolder |
|
91 | - ) { |
|
92 | - parent::__construct($appName, $request); |
|
93 | - $this->appName = $appName; |
|
94 | - $this->request = $request; |
|
95 | - $this->urlGenerator = $urlGenerator; |
|
96 | - $this->l10n = $l10n; |
|
97 | - $this->config = $config; |
|
98 | - $this->eventDispatcher = $eventDispatcherInterface; |
|
99 | - $this->userSession = $userSession; |
|
100 | - $this->appManager = $appManager; |
|
101 | - $this->rootFolder = $rootFolder; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param string $appName |
|
106 | - * @param string $scriptName |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function renderScript($appName, $scriptName) { |
|
110 | - $content = ''; |
|
111 | - $appPath = \OC_App::getAppPath($appName); |
|
112 | - $scriptPath = $appPath . '/' . $scriptName; |
|
113 | - if (file_exists($scriptPath)) { |
|
114 | - // TODO: sanitize path / script name ? |
|
115 | - ob_start(); |
|
116 | - include $scriptPath; |
|
117 | - $content = ob_get_contents(); |
|
118 | - @ob_end_clean(); |
|
119 | - } |
|
120 | - return $content; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * FIXME: Replace with non static code |
|
125 | - * |
|
126 | - * @return array |
|
127 | - * @throws \OCP\Files\NotFoundException |
|
128 | - */ |
|
129 | - protected function getStorageInfo() { |
|
130 | - $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
131 | - return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @NoCSRFRequired |
|
136 | - * @NoAdminRequired |
|
137 | - * |
|
138 | - * @param string $dir |
|
139 | - * @param string $view |
|
140 | - * @param string $fileid |
|
141 | - * @return TemplateResponse|RedirectResponse |
|
142 | - */ |
|
143 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
144 | - if ($fileid !== null) { |
|
145 | - try { |
|
146 | - return $this->showFile($fileid); |
|
147 | - } catch (NotFoundException $e) { |
|
148 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
153 | - |
|
154 | - // Load the files we need |
|
155 | - \OCP\Util::addStyle('files', 'merged'); |
|
156 | - \OCP\Util::addScript('files', 'merged-index'); |
|
157 | - |
|
158 | - // mostly for the home storage's free space |
|
159 | - // FIXME: Make non static |
|
160 | - $storageInfo = $this->getStorageInfo(); |
|
161 | - |
|
162 | - \OCA\Files\App::getNavigationManager()->add( |
|
163 | - [ |
|
164 | - 'id' => 'favorites', |
|
165 | - 'appname' => 'files', |
|
166 | - 'script' => 'simplelist.php', |
|
167 | - 'order' => 5, |
|
168 | - 'name' => $this->l10n->t('Favorites') |
|
169 | - ] |
|
170 | - ); |
|
171 | - |
|
172 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
173 | - usort($navItems, function($item1, $item2) { |
|
174 | - return $item1['order'] - $item2['order']; |
|
175 | - }); |
|
176 | - $nav->assign('navigationItems', $navItems); |
|
177 | - |
|
178 | - $contentItems = []; |
|
179 | - |
|
180 | - // render the container content for every navigation item |
|
181 | - foreach ($navItems as $item) { |
|
182 | - $content = ''; |
|
183 | - if (isset($item['script'])) { |
|
184 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
185 | - } |
|
186 | - $contentItem = []; |
|
187 | - $contentItem['id'] = $item['id']; |
|
188 | - $contentItem['content'] = $content; |
|
189 | - $contentItems[] = $contentItem; |
|
190 | - } |
|
191 | - |
|
192 | - $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
|
193 | - |
|
194 | - $params = []; |
|
195 | - $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
196 | - $params['owner'] = $storageInfo['owner']; |
|
197 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
198 | - $params['isPublic'] = false; |
|
199 | - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
200 | - $user = $this->userSession->getUser()->getUID(); |
|
201 | - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
202 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
203 | - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
204 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
205 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
206 | - $params['appNavigation'] = $nav; |
|
207 | - $params['appContents'] = $contentItems; |
|
208 | - |
|
209 | - $response = new TemplateResponse( |
|
210 | - $this->appName, |
|
211 | - 'index', |
|
212 | - $params |
|
213 | - ); |
|
214 | - $policy = new ContentSecurityPolicy(); |
|
215 | - $policy->addAllowedFrameDomain('\'self\''); |
|
216 | - $response->setContentSecurityPolicy($policy); |
|
217 | - |
|
218 | - return $response; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Redirects to the file list and highlight the given file id |
|
223 | - * |
|
224 | - * @param string $fileId file id to show |
|
225 | - * @return RedirectResponse redirect response or not found response |
|
226 | - * @throws \OCP\Files\NotFoundException |
|
227 | - */ |
|
228 | - private function showFile($fileId) { |
|
229 | - $uid = $this->userSession->getUser()->getUID(); |
|
230 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
231 | - $files = $baseFolder->getById($fileId); |
|
232 | - $params = []; |
|
233 | - |
|
234 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
235 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
236 | - $files = $baseFolder->getById($fileId); |
|
237 | - $params['view'] = 'trashbin'; |
|
238 | - } |
|
239 | - |
|
240 | - if (!empty($files)) { |
|
241 | - $file = current($files); |
|
242 | - if ($file instanceof Folder) { |
|
243 | - // set the full path to enter the folder |
|
244 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
245 | - } else { |
|
246 | - // set parent path as dir |
|
247 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
248 | - // and scroll to the entry |
|
249 | - $params['scrollto'] = $file->getName(); |
|
250 | - } |
|
251 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
252 | - } |
|
253 | - throw new \OCP\Files\NotFoundException(); |
|
254 | - } |
|
52 | + /** @var string */ |
|
53 | + protected $appName; |
|
54 | + /** @var IRequest */ |
|
55 | + protected $request; |
|
56 | + /** @var IURLGenerator */ |
|
57 | + protected $urlGenerator; |
|
58 | + /** @var IL10N */ |
|
59 | + protected $l10n; |
|
60 | + /** @var IConfig */ |
|
61 | + protected $config; |
|
62 | + /** @var EventDispatcherInterface */ |
|
63 | + protected $eventDispatcher; |
|
64 | + /** @var IUserSession */ |
|
65 | + protected $userSession; |
|
66 | + /** @var IAppManager */ |
|
67 | + protected $appManager; |
|
68 | + /** @var IRootFolder */ |
|
69 | + protected $rootFolder; |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $appName |
|
73 | + * @param IRequest $request |
|
74 | + * @param IURLGenerator $urlGenerator |
|
75 | + * @param IL10N $l10n |
|
76 | + * @param IConfig $config |
|
77 | + * @param EventDispatcherInterface $eventDispatcherInterface |
|
78 | + * @param IUserSession $userSession |
|
79 | + * @param IAppManager $appManager |
|
80 | + * @param IRootFolder $rootFolder |
|
81 | + */ |
|
82 | + public function __construct($appName, |
|
83 | + IRequest $request, |
|
84 | + IURLGenerator $urlGenerator, |
|
85 | + IL10N $l10n, |
|
86 | + IConfig $config, |
|
87 | + EventDispatcherInterface $eventDispatcherInterface, |
|
88 | + IUserSession $userSession, |
|
89 | + IAppManager $appManager, |
|
90 | + IRootFolder $rootFolder |
|
91 | + ) { |
|
92 | + parent::__construct($appName, $request); |
|
93 | + $this->appName = $appName; |
|
94 | + $this->request = $request; |
|
95 | + $this->urlGenerator = $urlGenerator; |
|
96 | + $this->l10n = $l10n; |
|
97 | + $this->config = $config; |
|
98 | + $this->eventDispatcher = $eventDispatcherInterface; |
|
99 | + $this->userSession = $userSession; |
|
100 | + $this->appManager = $appManager; |
|
101 | + $this->rootFolder = $rootFolder; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param string $appName |
|
106 | + * @param string $scriptName |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function renderScript($appName, $scriptName) { |
|
110 | + $content = ''; |
|
111 | + $appPath = \OC_App::getAppPath($appName); |
|
112 | + $scriptPath = $appPath . '/' . $scriptName; |
|
113 | + if (file_exists($scriptPath)) { |
|
114 | + // TODO: sanitize path / script name ? |
|
115 | + ob_start(); |
|
116 | + include $scriptPath; |
|
117 | + $content = ob_get_contents(); |
|
118 | + @ob_end_clean(); |
|
119 | + } |
|
120 | + return $content; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * FIXME: Replace with non static code |
|
125 | + * |
|
126 | + * @return array |
|
127 | + * @throws \OCP\Files\NotFoundException |
|
128 | + */ |
|
129 | + protected function getStorageInfo() { |
|
130 | + $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
131 | + return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @NoCSRFRequired |
|
136 | + * @NoAdminRequired |
|
137 | + * |
|
138 | + * @param string $dir |
|
139 | + * @param string $view |
|
140 | + * @param string $fileid |
|
141 | + * @return TemplateResponse|RedirectResponse |
|
142 | + */ |
|
143 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
144 | + if ($fileid !== null) { |
|
145 | + try { |
|
146 | + return $this->showFile($fileid); |
|
147 | + } catch (NotFoundException $e) { |
|
148 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
153 | + |
|
154 | + // Load the files we need |
|
155 | + \OCP\Util::addStyle('files', 'merged'); |
|
156 | + \OCP\Util::addScript('files', 'merged-index'); |
|
157 | + |
|
158 | + // mostly for the home storage's free space |
|
159 | + // FIXME: Make non static |
|
160 | + $storageInfo = $this->getStorageInfo(); |
|
161 | + |
|
162 | + \OCA\Files\App::getNavigationManager()->add( |
|
163 | + [ |
|
164 | + 'id' => 'favorites', |
|
165 | + 'appname' => 'files', |
|
166 | + 'script' => 'simplelist.php', |
|
167 | + 'order' => 5, |
|
168 | + 'name' => $this->l10n->t('Favorites') |
|
169 | + ] |
|
170 | + ); |
|
171 | + |
|
172 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
173 | + usort($navItems, function($item1, $item2) { |
|
174 | + return $item1['order'] - $item2['order']; |
|
175 | + }); |
|
176 | + $nav->assign('navigationItems', $navItems); |
|
177 | + |
|
178 | + $contentItems = []; |
|
179 | + |
|
180 | + // render the container content for every navigation item |
|
181 | + foreach ($navItems as $item) { |
|
182 | + $content = ''; |
|
183 | + if (isset($item['script'])) { |
|
184 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
185 | + } |
|
186 | + $contentItem = []; |
|
187 | + $contentItem['id'] = $item['id']; |
|
188 | + $contentItem['content'] = $content; |
|
189 | + $contentItems[] = $contentItem; |
|
190 | + } |
|
191 | + |
|
192 | + $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
|
193 | + |
|
194 | + $params = []; |
|
195 | + $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
196 | + $params['owner'] = $storageInfo['owner']; |
|
197 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
198 | + $params['isPublic'] = false; |
|
199 | + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
200 | + $user = $this->userSession->getUser()->getUID(); |
|
201 | + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
202 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
203 | + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
204 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
205 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
206 | + $params['appNavigation'] = $nav; |
|
207 | + $params['appContents'] = $contentItems; |
|
208 | + |
|
209 | + $response = new TemplateResponse( |
|
210 | + $this->appName, |
|
211 | + 'index', |
|
212 | + $params |
|
213 | + ); |
|
214 | + $policy = new ContentSecurityPolicy(); |
|
215 | + $policy->addAllowedFrameDomain('\'self\''); |
|
216 | + $response->setContentSecurityPolicy($policy); |
|
217 | + |
|
218 | + return $response; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Redirects to the file list and highlight the given file id |
|
223 | + * |
|
224 | + * @param string $fileId file id to show |
|
225 | + * @return RedirectResponse redirect response or not found response |
|
226 | + * @throws \OCP\Files\NotFoundException |
|
227 | + */ |
|
228 | + private function showFile($fileId) { |
|
229 | + $uid = $this->userSession->getUser()->getUID(); |
|
230 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
231 | + $files = $baseFolder->getById($fileId); |
|
232 | + $params = []; |
|
233 | + |
|
234 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
235 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
236 | + $files = $baseFolder->getById($fileId); |
|
237 | + $params['view'] = 'trashbin'; |
|
238 | + } |
|
239 | + |
|
240 | + if (!empty($files)) { |
|
241 | + $file = current($files); |
|
242 | + if ($file instanceof Folder) { |
|
243 | + // set the full path to enter the folder |
|
244 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
245 | + } else { |
|
246 | + // set parent path as dir |
|
247 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
248 | + // and scroll to the entry |
|
249 | + $params['scrollto'] = $file->getName(); |
|
250 | + } |
|
251 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
252 | + } |
|
253 | + throw new \OCP\Files\NotFoundException(); |
|
254 | + } |
|
255 | 255 | } |
@@ -51,217 +51,217 @@ |
||
51 | 51 | * @package OCA\Files\Controller |
52 | 52 | */ |
53 | 53 | class ApiController extends Controller { |
54 | - /** @var TagService */ |
|
55 | - private $tagService; |
|
56 | - /** @var IManager **/ |
|
57 | - private $shareManager; |
|
58 | - /** @var IPreview */ |
|
59 | - private $previewManager; |
|
60 | - /** IUserSession */ |
|
61 | - private $userSession; |
|
62 | - /** IConfig */ |
|
63 | - private $config; |
|
64 | - /** @var Folder */ |
|
65 | - private $userFolder; |
|
54 | + /** @var TagService */ |
|
55 | + private $tagService; |
|
56 | + /** @var IManager **/ |
|
57 | + private $shareManager; |
|
58 | + /** @var IPreview */ |
|
59 | + private $previewManager; |
|
60 | + /** IUserSession */ |
|
61 | + private $userSession; |
|
62 | + /** IConfig */ |
|
63 | + private $config; |
|
64 | + /** @var Folder */ |
|
65 | + private $userFolder; |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param string $appName |
|
69 | - * @param IRequest $request |
|
70 | - * @param IUserSession $userSession |
|
71 | - * @param TagService $tagService |
|
72 | - * @param IPreview $previewManager |
|
73 | - * @param IManager $shareManager |
|
74 | - * @param IConfig $config |
|
75 | - * @param Folder $userFolder |
|
76 | - */ |
|
77 | - public function __construct($appName, |
|
78 | - IRequest $request, |
|
79 | - IUserSession $userSession, |
|
80 | - TagService $tagService, |
|
81 | - IPreview $previewManager, |
|
82 | - IManager $shareManager, |
|
83 | - IConfig $config, |
|
84 | - Folder $userFolder) { |
|
85 | - parent::__construct($appName, $request); |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->tagService = $tagService; |
|
88 | - $this->previewManager = $previewManager; |
|
89 | - $this->shareManager = $shareManager; |
|
90 | - $this->config = $config; |
|
91 | - $this->userFolder = $userFolder; |
|
92 | - } |
|
67 | + /** |
|
68 | + * @param string $appName |
|
69 | + * @param IRequest $request |
|
70 | + * @param IUserSession $userSession |
|
71 | + * @param TagService $tagService |
|
72 | + * @param IPreview $previewManager |
|
73 | + * @param IManager $shareManager |
|
74 | + * @param IConfig $config |
|
75 | + * @param Folder $userFolder |
|
76 | + */ |
|
77 | + public function __construct($appName, |
|
78 | + IRequest $request, |
|
79 | + IUserSession $userSession, |
|
80 | + TagService $tagService, |
|
81 | + IPreview $previewManager, |
|
82 | + IManager $shareManager, |
|
83 | + IConfig $config, |
|
84 | + Folder $userFolder) { |
|
85 | + parent::__construct($appName, $request); |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->tagService = $tagService; |
|
88 | + $this->previewManager = $previewManager; |
|
89 | + $this->shareManager = $shareManager; |
|
90 | + $this->config = $config; |
|
91 | + $this->userFolder = $userFolder; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Gets a thumbnail of the specified file |
|
96 | - * |
|
97 | - * @since API version 1.0 |
|
98 | - * |
|
99 | - * @NoAdminRequired |
|
100 | - * @NoCSRFRequired |
|
101 | - * @StrictCookieRequired |
|
102 | - * |
|
103 | - * @param int $x |
|
104 | - * @param int $y |
|
105 | - * @param string $file URL-encoded filename |
|
106 | - * @return DataResponse|FileDisplayResponse |
|
107 | - */ |
|
108 | - public function getThumbnail($x, $y, $file) { |
|
109 | - if($x < 1 || $y < 1) { |
|
110 | - return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
111 | - } |
|
94 | + /** |
|
95 | + * Gets a thumbnail of the specified file |
|
96 | + * |
|
97 | + * @since API version 1.0 |
|
98 | + * |
|
99 | + * @NoAdminRequired |
|
100 | + * @NoCSRFRequired |
|
101 | + * @StrictCookieRequired |
|
102 | + * |
|
103 | + * @param int $x |
|
104 | + * @param int $y |
|
105 | + * @param string $file URL-encoded filename |
|
106 | + * @return DataResponse|FileDisplayResponse |
|
107 | + */ |
|
108 | + public function getThumbnail($x, $y, $file) { |
|
109 | + if($x < 1 || $y < 1) { |
|
110 | + return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
111 | + } |
|
112 | 112 | |
113 | - try { |
|
114 | - $file = $this->userFolder->get($file); |
|
115 | - if ($file instanceof Folder) { |
|
116 | - throw new NotFoundException(); |
|
117 | - } |
|
113 | + try { |
|
114 | + $file = $this->userFolder->get($file); |
|
115 | + if ($file instanceof Folder) { |
|
116 | + throw new NotFoundException(); |
|
117 | + } |
|
118 | 118 | |
119 | - /** @var File $file */ |
|
120 | - $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
119 | + /** @var File $file */ |
|
120 | + $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
121 | 121 | |
122 | - return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
123 | - } catch (NotFoundException $e) { |
|
124 | - return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
125 | - } catch (\Exception $e) { |
|
126 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
127 | - } |
|
128 | - } |
|
122 | + return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
123 | + } catch (NotFoundException $e) { |
|
124 | + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
125 | + } catch (\Exception $e) { |
|
126 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Updates the info of the specified file path |
|
132 | - * The passed tags are absolute, which means they will |
|
133 | - * replace the actual tag selection. |
|
134 | - * |
|
135 | - * @NoAdminRequired |
|
136 | - * |
|
137 | - * @param string $path path |
|
138 | - * @param array|string $tags array of tags |
|
139 | - * @return DataResponse |
|
140 | - */ |
|
141 | - public function updateFileTags($path, $tags = null) { |
|
142 | - $result = []; |
|
143 | - // if tags specified or empty array, update tags |
|
144 | - if (!is_null($tags)) { |
|
145 | - try { |
|
146 | - $this->tagService->updateFileTags($path, $tags); |
|
147 | - } catch (\OCP\Files\NotFoundException $e) { |
|
148 | - return new DataResponse([ |
|
149 | - 'message' => $e->getMessage() |
|
150 | - ], Http::STATUS_NOT_FOUND); |
|
151 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
152 | - return new DataResponse([ |
|
153 | - 'message' => $e->getMessage() |
|
154 | - ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
155 | - } catch (\Exception $e) { |
|
156 | - return new DataResponse([ |
|
157 | - 'message' => $e->getMessage() |
|
158 | - ], Http::STATUS_NOT_FOUND); |
|
159 | - } |
|
160 | - $result['tags'] = $tags; |
|
161 | - } |
|
162 | - return new DataResponse($result); |
|
163 | - } |
|
130 | + /** |
|
131 | + * Updates the info of the specified file path |
|
132 | + * The passed tags are absolute, which means they will |
|
133 | + * replace the actual tag selection. |
|
134 | + * |
|
135 | + * @NoAdminRequired |
|
136 | + * |
|
137 | + * @param string $path path |
|
138 | + * @param array|string $tags array of tags |
|
139 | + * @return DataResponse |
|
140 | + */ |
|
141 | + public function updateFileTags($path, $tags = null) { |
|
142 | + $result = []; |
|
143 | + // if tags specified or empty array, update tags |
|
144 | + if (!is_null($tags)) { |
|
145 | + try { |
|
146 | + $this->tagService->updateFileTags($path, $tags); |
|
147 | + } catch (\OCP\Files\NotFoundException $e) { |
|
148 | + return new DataResponse([ |
|
149 | + 'message' => $e->getMessage() |
|
150 | + ], Http::STATUS_NOT_FOUND); |
|
151 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
152 | + return new DataResponse([ |
|
153 | + 'message' => $e->getMessage() |
|
154 | + ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
155 | + } catch (\Exception $e) { |
|
156 | + return new DataResponse([ |
|
157 | + 'message' => $e->getMessage() |
|
158 | + ], Http::STATUS_NOT_FOUND); |
|
159 | + } |
|
160 | + $result['tags'] = $tags; |
|
161 | + } |
|
162 | + return new DataResponse($result); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @param \OCP\Files\Node[] $nodes |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - private function formatNodes(array $nodes) { |
|
170 | - return array_values(array_map(function (Node $node) { |
|
171 | - /** @var \OC\Files\Node\Node $shareTypes */ |
|
172 | - $shareTypes = $this->getShareTypes($node); |
|
173 | - $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
174 | - $parts = explode('/', dirname($node->getPath()), 4); |
|
175 | - if (isset($parts[3])) { |
|
176 | - $file['path'] = '/' . $parts[3]; |
|
177 | - } else { |
|
178 | - $file['path'] = '/'; |
|
179 | - } |
|
180 | - if (!empty($shareTypes)) { |
|
181 | - $file['shareTypes'] = $shareTypes; |
|
182 | - } |
|
183 | - return $file; |
|
184 | - }, $nodes)); |
|
185 | - } |
|
165 | + /** |
|
166 | + * @param \OCP\Files\Node[] $nodes |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + private function formatNodes(array $nodes) { |
|
170 | + return array_values(array_map(function (Node $node) { |
|
171 | + /** @var \OC\Files\Node\Node $shareTypes */ |
|
172 | + $shareTypes = $this->getShareTypes($node); |
|
173 | + $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
174 | + $parts = explode('/', dirname($node->getPath()), 4); |
|
175 | + if (isset($parts[3])) { |
|
176 | + $file['path'] = '/' . $parts[3]; |
|
177 | + } else { |
|
178 | + $file['path'] = '/'; |
|
179 | + } |
|
180 | + if (!empty($shareTypes)) { |
|
181 | + $file['shareTypes'] = $shareTypes; |
|
182 | + } |
|
183 | + return $file; |
|
184 | + }, $nodes)); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Returns a list of recently modifed files. |
|
189 | - * |
|
190 | - * @NoAdminRequired |
|
191 | - * |
|
192 | - * @return DataResponse |
|
193 | - */ |
|
194 | - public function getRecentFiles() { |
|
195 | - $nodes = $this->userFolder->getRecent(100); |
|
196 | - $files = $this->formatNodes($nodes); |
|
197 | - return new DataResponse(['files' => $files]); |
|
198 | - } |
|
187 | + /** |
|
188 | + * Returns a list of recently modifed files. |
|
189 | + * |
|
190 | + * @NoAdminRequired |
|
191 | + * |
|
192 | + * @return DataResponse |
|
193 | + */ |
|
194 | + public function getRecentFiles() { |
|
195 | + $nodes = $this->userFolder->getRecent(100); |
|
196 | + $files = $this->formatNodes($nodes); |
|
197 | + return new DataResponse(['files' => $files]); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Return a list of share types for outgoing shares |
|
202 | - * |
|
203 | - * @param Node $node file node |
|
204 | - * |
|
205 | - * @return int[] array of share types |
|
206 | - */ |
|
207 | - private function getShareTypes(Node $node) { |
|
208 | - $userId = $this->userSession->getUser()->getUID(); |
|
209 | - $shareTypes = []; |
|
210 | - $requestedShareTypes = [ |
|
211 | - \OCP\Share::SHARE_TYPE_USER, |
|
212 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
213 | - \OCP\Share::SHARE_TYPE_LINK, |
|
214 | - \OCP\Share::SHARE_TYPE_REMOTE, |
|
215 | - \OCP\Share::SHARE_TYPE_EMAIL |
|
216 | - ]; |
|
217 | - foreach ($requestedShareTypes as $requestedShareType) { |
|
218 | - // one of each type is enough to find out about the types |
|
219 | - $shares = $this->shareManager->getSharesBy( |
|
220 | - $userId, |
|
221 | - $requestedShareType, |
|
222 | - $node, |
|
223 | - false, |
|
224 | - 1 |
|
225 | - ); |
|
226 | - if (!empty($shares)) { |
|
227 | - $shareTypes[] = $requestedShareType; |
|
228 | - } |
|
229 | - } |
|
230 | - return $shareTypes; |
|
231 | - } |
|
200 | + /** |
|
201 | + * Return a list of share types for outgoing shares |
|
202 | + * |
|
203 | + * @param Node $node file node |
|
204 | + * |
|
205 | + * @return int[] array of share types |
|
206 | + */ |
|
207 | + private function getShareTypes(Node $node) { |
|
208 | + $userId = $this->userSession->getUser()->getUID(); |
|
209 | + $shareTypes = []; |
|
210 | + $requestedShareTypes = [ |
|
211 | + \OCP\Share::SHARE_TYPE_USER, |
|
212 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
213 | + \OCP\Share::SHARE_TYPE_LINK, |
|
214 | + \OCP\Share::SHARE_TYPE_REMOTE, |
|
215 | + \OCP\Share::SHARE_TYPE_EMAIL |
|
216 | + ]; |
|
217 | + foreach ($requestedShareTypes as $requestedShareType) { |
|
218 | + // one of each type is enough to find out about the types |
|
219 | + $shares = $this->shareManager->getSharesBy( |
|
220 | + $userId, |
|
221 | + $requestedShareType, |
|
222 | + $node, |
|
223 | + false, |
|
224 | + 1 |
|
225 | + ); |
|
226 | + if (!empty($shares)) { |
|
227 | + $shareTypes[] = $requestedShareType; |
|
228 | + } |
|
229 | + } |
|
230 | + return $shareTypes; |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Change the default sort mode |
|
235 | - * |
|
236 | - * @NoAdminRequired |
|
237 | - * |
|
238 | - * @param string $mode |
|
239 | - * @param string $direction |
|
240 | - * @return Response |
|
241 | - */ |
|
242 | - public function updateFileSorting($mode, $direction) { |
|
243 | - $allowedMode = ['name', 'size', 'mtime']; |
|
244 | - $allowedDirection = ['asc', 'desc']; |
|
245 | - if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
246 | - $response = new Response(); |
|
247 | - $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
248 | - return $response; |
|
249 | - } |
|
250 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
251 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
252 | - return new Response(); |
|
253 | - } |
|
233 | + /** |
|
234 | + * Change the default sort mode |
|
235 | + * |
|
236 | + * @NoAdminRequired |
|
237 | + * |
|
238 | + * @param string $mode |
|
239 | + * @param string $direction |
|
240 | + * @return Response |
|
241 | + */ |
|
242 | + public function updateFileSorting($mode, $direction) { |
|
243 | + $allowedMode = ['name', 'size', 'mtime']; |
|
244 | + $allowedDirection = ['asc', 'desc']; |
|
245 | + if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
246 | + $response = new Response(); |
|
247 | + $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
248 | + return $response; |
|
249 | + } |
|
250 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
251 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
252 | + return new Response(); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Toggle default for showing/hiding hidden files |
|
257 | - * |
|
258 | - * @NoAdminRequired |
|
259 | - * |
|
260 | - * @param bool $show |
|
261 | - */ |
|
262 | - public function showHiddenFiles($show) { |
|
263 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show); |
|
264 | - return new Response(); |
|
265 | - } |
|
255 | + /** |
|
256 | + * Toggle default for showing/hiding hidden files |
|
257 | + * |
|
258 | + * @NoAdminRequired |
|
259 | + * |
|
260 | + * @param bool $show |
|
261 | + */ |
|
262 | + public function showHiddenFiles($show) { |
|
263 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show); |
|
264 | + return new Response(); |
|
265 | + } |
|
266 | 266 | |
267 | 267 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @return DataResponse|FileDisplayResponse |
107 | 107 | */ |
108 | 108 | public function getThumbnail($x, $y, $file) { |
109 | - if($x < 1 || $y < 1) { |
|
109 | + if ($x < 1 || $y < 1) { |
|
110 | 110 | return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
111 | 111 | } |
112 | 112 | |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @return array |
168 | 168 | */ |
169 | 169 | private function formatNodes(array $nodes) { |
170 | - return array_values(array_map(function (Node $node) { |
|
170 | + return array_values(array_map(function(Node $node) { |
|
171 | 171 | /** @var \OC\Files\Node\Node $shareTypes */ |
172 | 172 | $shareTypes = $this->getShareTypes($node); |
173 | 173 | $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
174 | 174 | $parts = explode('/', dirname($node->getPath()), 4); |
175 | 175 | if (isset($parts[3])) { |
176 | - $file['path'] = '/' . $parts[3]; |
|
176 | + $file['path'] = '/'.$parts[3]; |
|
177 | 177 | } else { |
178 | 178 | $file['path'] = '/'; |
179 | 179 | } |
@@ -31,67 +31,67 @@ |
||
31 | 31 | use OCA\Files\Controller\ViewController; |
32 | 32 | |
33 | 33 | class Application extends App { |
34 | - public function __construct(array $urlParams=array()) { |
|
35 | - parent::__construct('files', $urlParams); |
|
36 | - $container = $this->getContainer(); |
|
37 | - $server = $container->getServer(); |
|
34 | + public function __construct(array $urlParams=array()) { |
|
35 | + parent::__construct('files', $urlParams); |
|
36 | + $container = $this->getContainer(); |
|
37 | + $server = $container->getServer(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Controllers |
|
41 | - */ |
|
42 | - $container->registerService('APIController', function (IContainer $c) use ($server) { |
|
43 | - return new ApiController( |
|
44 | - $c->query('AppName'), |
|
45 | - $c->query('Request'), |
|
46 | - $server->getUserSession(), |
|
47 | - $c->query('TagService'), |
|
48 | - $server->getPreviewManager(), |
|
49 | - $server->getShareManager(), |
|
50 | - $server->getConfig(), |
|
51 | - $server->getUserFolder() |
|
52 | - ); |
|
53 | - }); |
|
39 | + /** |
|
40 | + * Controllers |
|
41 | + */ |
|
42 | + $container->registerService('APIController', function (IContainer $c) use ($server) { |
|
43 | + return new ApiController( |
|
44 | + $c->query('AppName'), |
|
45 | + $c->query('Request'), |
|
46 | + $server->getUserSession(), |
|
47 | + $c->query('TagService'), |
|
48 | + $server->getPreviewManager(), |
|
49 | + $server->getShareManager(), |
|
50 | + $server->getConfig(), |
|
51 | + $server->getUserFolder() |
|
52 | + ); |
|
53 | + }); |
|
54 | 54 | |
55 | - $container->registerService('ViewController', function (IContainer $c) use ($server) { |
|
56 | - return new ViewController( |
|
57 | - $c->query('AppName'), |
|
58 | - $c->query('Request'), |
|
59 | - $server->getURLGenerator(), |
|
60 | - $c->query('L10N'), |
|
61 | - $server->getConfig(), |
|
62 | - $server->getEventDispatcher(), |
|
63 | - $server->getUserSession(), |
|
64 | - $server->getAppManager(), |
|
65 | - $server->getRootFolder() |
|
66 | - ); |
|
67 | - }); |
|
55 | + $container->registerService('ViewController', function (IContainer $c) use ($server) { |
|
56 | + return new ViewController( |
|
57 | + $c->query('AppName'), |
|
58 | + $c->query('Request'), |
|
59 | + $server->getURLGenerator(), |
|
60 | + $c->query('L10N'), |
|
61 | + $server->getConfig(), |
|
62 | + $server->getEventDispatcher(), |
|
63 | + $server->getUserSession(), |
|
64 | + $server->getAppManager(), |
|
65 | + $server->getRootFolder() |
|
66 | + ); |
|
67 | + }); |
|
68 | 68 | |
69 | - /** |
|
70 | - * Core |
|
71 | - */ |
|
72 | - $container->registerService('L10N', function(IContainer $c) { |
|
73 | - return $c->query('ServerContainer')->getL10N($c->query('AppName')); |
|
74 | - }); |
|
69 | + /** |
|
70 | + * Core |
|
71 | + */ |
|
72 | + $container->registerService('L10N', function(IContainer $c) { |
|
73 | + return $c->query('ServerContainer')->getL10N($c->query('AppName')); |
|
74 | + }); |
|
75 | 75 | |
76 | - /** |
|
77 | - * Services |
|
78 | - */ |
|
79 | - $container->registerService('Tagger', function(IContainer $c) { |
|
80 | - return $c->query('ServerContainer')->getTagManager()->load('files'); |
|
81 | - }); |
|
82 | - $container->registerService('TagService', function(IContainer $c) { |
|
83 | - $homeFolder = $c->query('ServerContainer')->getUserFolder(); |
|
84 | - return new TagService( |
|
85 | - $c->query('ServerContainer')->getUserSession(), |
|
86 | - $c->query('ServerContainer')->getActivityManager(), |
|
87 | - $c->query('Tagger'), |
|
88 | - $homeFolder |
|
89 | - ); |
|
90 | - }); |
|
76 | + /** |
|
77 | + * Services |
|
78 | + */ |
|
79 | + $container->registerService('Tagger', function(IContainer $c) { |
|
80 | + return $c->query('ServerContainer')->getTagManager()->load('files'); |
|
81 | + }); |
|
82 | + $container->registerService('TagService', function(IContainer $c) { |
|
83 | + $homeFolder = $c->query('ServerContainer')->getUserFolder(); |
|
84 | + return new TagService( |
|
85 | + $c->query('ServerContainer')->getUserSession(), |
|
86 | + $c->query('ServerContainer')->getActivityManager(), |
|
87 | + $c->query('Tagger'), |
|
88 | + $homeFolder |
|
89 | + ); |
|
90 | + }); |
|
91 | 91 | |
92 | - /* |
|
92 | + /* |
|
93 | 93 | * Register capabilities |
94 | 94 | */ |
95 | - $container->registerCapability('OCA\Files\Capabilities'); |
|
96 | - } |
|
95 | + $container->registerCapability('OCA\Files\Capabilities'); |
|
96 | + } |
|
97 | 97 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | use OCA\Files\Controller\ViewController; |
32 | 32 | |
33 | 33 | class Application extends App { |
34 | - public function __construct(array $urlParams=array()) { |
|
34 | + public function __construct(array $urlParams = array()) { |
|
35 | 35 | parent::__construct('files', $urlParams); |
36 | 36 | $container = $this->getContainer(); |
37 | 37 | $server = $container->getServer(); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * Controllers |
41 | 41 | */ |
42 | - $container->registerService('APIController', function (IContainer $c) use ($server) { |
|
42 | + $container->registerService('APIController', function(IContainer $c) use ($server) { |
|
43 | 43 | return new ApiController( |
44 | 44 | $c->query('AppName'), |
45 | 45 | $c->query('Request'), |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | ); |
53 | 53 | }); |
54 | 54 | |
55 | - $container->registerService('ViewController', function (IContainer $c) use ($server) { |
|
55 | + $container->registerService('ViewController', function(IContainer $c) use ($server) { |
|
56 | 56 | return new ViewController( |
57 | 57 | $c->query('AppName'), |
58 | 58 | $c->query('Request'), |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * Services |
78 | 78 | */ |
79 | - $container->registerService('Tagger', function(IContainer $c) { |
|
79 | + $container->registerService('Tagger', function(IContainer $c) { |
|
80 | 80 | return $c->query('ServerContainer')->getTagManager()->load('files'); |
81 | 81 | }); |
82 | - $container->registerService('TagService', function(IContainer $c) { |
|
82 | + $container->registerService('TagService', function(IContainer $c) { |
|
83 | 83 | $homeFolder = $c->query('ServerContainer')->getUserFolder(); |
84 | 84 | return new TagService( |
85 | 85 | $c->query('ServerContainer')->getUserSession(), |
@@ -75,7 +75,7 @@ |
||
75 | 75 | } elseif ($file->isMounted()) { |
76 | 76 | $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-external'); |
77 | 77 | } |
78 | - }else{ |
|
78 | + } else{ |
|
79 | 79 | $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon($file->getMimetype()); |
80 | 80 | } |
81 | 81 |
@@ -37,234 +37,234 @@ |
||
37 | 37 | * Helper class for manipulating file information |
38 | 38 | */ |
39 | 39 | class Helper { |
40 | - /** |
|
41 | - * @param string $dir |
|
42 | - * @return array |
|
43 | - * @throws \OCP\Files\NotFoundException |
|
44 | - */ |
|
45 | - public static function buildFileStorageStatistics($dir) { |
|
46 | - // information about storage capacities |
|
47 | - $storageInfo = \OC_Helper::getStorageInfo($dir); |
|
48 | - $l = \OC::$server->getL10N('files'); |
|
49 | - $maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); |
|
50 | - $maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize); |
|
51 | - $maxHumanFileSize = $l->t('Upload (max. %s)', array($maxHumanFileSize)); |
|
40 | + /** |
|
41 | + * @param string $dir |
|
42 | + * @return array |
|
43 | + * @throws \OCP\Files\NotFoundException |
|
44 | + */ |
|
45 | + public static function buildFileStorageStatistics($dir) { |
|
46 | + // information about storage capacities |
|
47 | + $storageInfo = \OC_Helper::getStorageInfo($dir); |
|
48 | + $l = \OC::$server->getL10N('files'); |
|
49 | + $maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); |
|
50 | + $maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize); |
|
51 | + $maxHumanFileSize = $l->t('Upload (max. %s)', array($maxHumanFileSize)); |
|
52 | 52 | |
53 | - return [ |
|
54 | - 'uploadMaxFilesize' => $maxUploadFileSize, |
|
55 | - 'maxHumanFilesize' => $maxHumanFileSize, |
|
56 | - 'freeSpace' => $storageInfo['free'], |
|
57 | - 'usedSpacePercent' => (int)$storageInfo['relative'], |
|
58 | - 'owner' => $storageInfo['owner'], |
|
59 | - 'ownerDisplayName' => $storageInfo['ownerDisplayName'], |
|
60 | - ]; |
|
61 | - } |
|
53 | + return [ |
|
54 | + 'uploadMaxFilesize' => $maxUploadFileSize, |
|
55 | + 'maxHumanFilesize' => $maxHumanFileSize, |
|
56 | + 'freeSpace' => $storageInfo['free'], |
|
57 | + 'usedSpacePercent' => (int)$storageInfo['relative'], |
|
58 | + 'owner' => $storageInfo['owner'], |
|
59 | + 'ownerDisplayName' => $storageInfo['ownerDisplayName'], |
|
60 | + ]; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Determine icon for a given file |
|
65 | - * |
|
66 | - * @param \OCP\Files\FileInfo $file file info |
|
67 | - * @return string icon URL |
|
68 | - */ |
|
69 | - public static function determineIcon($file) { |
|
70 | - if($file['type'] === 'dir') { |
|
71 | - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir'); |
|
72 | - // TODO: move this part to the client side, using mountType |
|
73 | - if ($file->isShared()) { |
|
74 | - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-shared'); |
|
75 | - } elseif ($file->isMounted()) { |
|
76 | - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-external'); |
|
77 | - } |
|
78 | - }else{ |
|
79 | - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon($file->getMimetype()); |
|
80 | - } |
|
63 | + /** |
|
64 | + * Determine icon for a given file |
|
65 | + * |
|
66 | + * @param \OCP\Files\FileInfo $file file info |
|
67 | + * @return string icon URL |
|
68 | + */ |
|
69 | + public static function determineIcon($file) { |
|
70 | + if($file['type'] === 'dir') { |
|
71 | + $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir'); |
|
72 | + // TODO: move this part to the client side, using mountType |
|
73 | + if ($file->isShared()) { |
|
74 | + $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-shared'); |
|
75 | + } elseif ($file->isMounted()) { |
|
76 | + $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-external'); |
|
77 | + } |
|
78 | + }else{ |
|
79 | + $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon($file->getMimetype()); |
|
80 | + } |
|
81 | 81 | |
82 | - return substr($icon, 0, -3) . 'svg'; |
|
83 | - } |
|
82 | + return substr($icon, 0, -3) . 'svg'; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Comparator function to sort files alphabetically and have |
|
87 | - * the directories appear first |
|
88 | - * |
|
89 | - * @param \OCP\Files\FileInfo $a file |
|
90 | - * @param \OCP\Files\FileInfo $b file |
|
91 | - * @return int -1 if $a must come before $b, 1 otherwise |
|
92 | - */ |
|
93 | - public static function compareFileNames(FileInfo $a, FileInfo $b) { |
|
94 | - $aType = $a->getType(); |
|
95 | - $bType = $b->getType(); |
|
96 | - if ($aType === 'dir' and $bType !== 'dir') { |
|
97 | - return -1; |
|
98 | - } elseif ($aType !== 'dir' and $bType === 'dir') { |
|
99 | - return 1; |
|
100 | - } else { |
|
101 | - return \OCP\Util::naturalSortCompare($a->getName(), $b->getName()); |
|
102 | - } |
|
103 | - } |
|
85 | + /** |
|
86 | + * Comparator function to sort files alphabetically and have |
|
87 | + * the directories appear first |
|
88 | + * |
|
89 | + * @param \OCP\Files\FileInfo $a file |
|
90 | + * @param \OCP\Files\FileInfo $b file |
|
91 | + * @return int -1 if $a must come before $b, 1 otherwise |
|
92 | + */ |
|
93 | + public static function compareFileNames(FileInfo $a, FileInfo $b) { |
|
94 | + $aType = $a->getType(); |
|
95 | + $bType = $b->getType(); |
|
96 | + if ($aType === 'dir' and $bType !== 'dir') { |
|
97 | + return -1; |
|
98 | + } elseif ($aType !== 'dir' and $bType === 'dir') { |
|
99 | + return 1; |
|
100 | + } else { |
|
101 | + return \OCP\Util::naturalSortCompare($a->getName(), $b->getName()); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Comparator function to sort files by date |
|
107 | - * |
|
108 | - * @param \OCP\Files\FileInfo $a file |
|
109 | - * @param \OCP\Files\FileInfo $b file |
|
110 | - * @return int -1 if $a must come before $b, 1 otherwise |
|
111 | - */ |
|
112 | - public static function compareTimestamp(FileInfo $a, FileInfo $b) { |
|
113 | - $aTime = $a->getMTime(); |
|
114 | - $bTime = $b->getMTime(); |
|
115 | - return ($aTime < $bTime) ? -1 : 1; |
|
116 | - } |
|
105 | + /** |
|
106 | + * Comparator function to sort files by date |
|
107 | + * |
|
108 | + * @param \OCP\Files\FileInfo $a file |
|
109 | + * @param \OCP\Files\FileInfo $b file |
|
110 | + * @return int -1 if $a must come before $b, 1 otherwise |
|
111 | + */ |
|
112 | + public static function compareTimestamp(FileInfo $a, FileInfo $b) { |
|
113 | + $aTime = $a->getMTime(); |
|
114 | + $bTime = $b->getMTime(); |
|
115 | + return ($aTime < $bTime) ? -1 : 1; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Comparator function to sort files by size |
|
120 | - * |
|
121 | - * @param \OCP\Files\FileInfo $a file |
|
122 | - * @param \OCP\Files\FileInfo $b file |
|
123 | - * @return int -1 if $a must come before $b, 1 otherwise |
|
124 | - */ |
|
125 | - public static function compareSize(FileInfo $a, FileInfo $b) { |
|
126 | - $aSize = $a->getSize(); |
|
127 | - $bSize = $b->getSize(); |
|
128 | - return ($aSize < $bSize) ? -1 : 1; |
|
129 | - } |
|
118 | + /** |
|
119 | + * Comparator function to sort files by size |
|
120 | + * |
|
121 | + * @param \OCP\Files\FileInfo $a file |
|
122 | + * @param \OCP\Files\FileInfo $b file |
|
123 | + * @return int -1 if $a must come before $b, 1 otherwise |
|
124 | + */ |
|
125 | + public static function compareSize(FileInfo $a, FileInfo $b) { |
|
126 | + $aSize = $a->getSize(); |
|
127 | + $bSize = $b->getSize(); |
|
128 | + return ($aSize < $bSize) ? -1 : 1; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Formats the file info to be returned as JSON to the client. |
|
133 | - * |
|
134 | - * @param \OCP\Files\FileInfo $i |
|
135 | - * @return array formatted file info |
|
136 | - */ |
|
137 | - public static function formatFileInfo(FileInfo $i) { |
|
138 | - $entry = array(); |
|
131 | + /** |
|
132 | + * Formats the file info to be returned as JSON to the client. |
|
133 | + * |
|
134 | + * @param \OCP\Files\FileInfo $i |
|
135 | + * @return array formatted file info |
|
136 | + */ |
|
137 | + public static function formatFileInfo(FileInfo $i) { |
|
138 | + $entry = array(); |
|
139 | 139 | |
140 | - $entry['id'] = $i['fileid']; |
|
141 | - $entry['parentId'] = $i['parent']; |
|
142 | - $entry['mtime'] = $i['mtime'] * 1000; |
|
143 | - // only pick out the needed attributes |
|
144 | - $entry['name'] = $i->getName(); |
|
145 | - $entry['permissions'] = $i['permissions']; |
|
146 | - $entry['mimetype'] = $i['mimetype']; |
|
147 | - $entry['size'] = $i['size']; |
|
148 | - $entry['type'] = $i['type']; |
|
149 | - $entry['etag'] = $i['etag']; |
|
150 | - if (isset($i['tags'])) { |
|
151 | - $entry['tags'] = $i['tags']; |
|
152 | - } |
|
153 | - if (isset($i['displayname_owner'])) { |
|
154 | - $entry['shareOwner'] = $i['displayname_owner']; |
|
155 | - } |
|
156 | - if (isset($i['is_share_mount_point'])) { |
|
157 | - $entry['isShareMountPoint'] = $i['is_share_mount_point']; |
|
158 | - } |
|
159 | - $mountType = null; |
|
160 | - if ($i->isShared()) { |
|
161 | - $mountType = 'shared'; |
|
162 | - } else if ($i->isMounted()) { |
|
163 | - $mountType = 'external'; |
|
164 | - } |
|
165 | - if ($mountType !== null) { |
|
166 | - if ($i->getInternalPath() === '') { |
|
167 | - $mountType .= '-root'; |
|
168 | - } |
|
169 | - $entry['mountType'] = $mountType; |
|
170 | - } |
|
171 | - if (isset($i['extraData'])) { |
|
172 | - $entry['extraData'] = $i['extraData']; |
|
173 | - } |
|
174 | - return $entry; |
|
175 | - } |
|
140 | + $entry['id'] = $i['fileid']; |
|
141 | + $entry['parentId'] = $i['parent']; |
|
142 | + $entry['mtime'] = $i['mtime'] * 1000; |
|
143 | + // only pick out the needed attributes |
|
144 | + $entry['name'] = $i->getName(); |
|
145 | + $entry['permissions'] = $i['permissions']; |
|
146 | + $entry['mimetype'] = $i['mimetype']; |
|
147 | + $entry['size'] = $i['size']; |
|
148 | + $entry['type'] = $i['type']; |
|
149 | + $entry['etag'] = $i['etag']; |
|
150 | + if (isset($i['tags'])) { |
|
151 | + $entry['tags'] = $i['tags']; |
|
152 | + } |
|
153 | + if (isset($i['displayname_owner'])) { |
|
154 | + $entry['shareOwner'] = $i['displayname_owner']; |
|
155 | + } |
|
156 | + if (isset($i['is_share_mount_point'])) { |
|
157 | + $entry['isShareMountPoint'] = $i['is_share_mount_point']; |
|
158 | + } |
|
159 | + $mountType = null; |
|
160 | + if ($i->isShared()) { |
|
161 | + $mountType = 'shared'; |
|
162 | + } else if ($i->isMounted()) { |
|
163 | + $mountType = 'external'; |
|
164 | + } |
|
165 | + if ($mountType !== null) { |
|
166 | + if ($i->getInternalPath() === '') { |
|
167 | + $mountType .= '-root'; |
|
168 | + } |
|
169 | + $entry['mountType'] = $mountType; |
|
170 | + } |
|
171 | + if (isset($i['extraData'])) { |
|
172 | + $entry['extraData'] = $i['extraData']; |
|
173 | + } |
|
174 | + return $entry; |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Format file info for JSON |
|
179 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - public static function formatFileInfos($fileInfos) { |
|
183 | - $files = array(); |
|
184 | - foreach ($fileInfos as $i) { |
|
185 | - $files[] = self::formatFileInfo($i); |
|
186 | - } |
|
177 | + /** |
|
178 | + * Format file info for JSON |
|
179 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + public static function formatFileInfos($fileInfos) { |
|
183 | + $files = array(); |
|
184 | + foreach ($fileInfos as $i) { |
|
185 | + $files[] = self::formatFileInfo($i); |
|
186 | + } |
|
187 | 187 | |
188 | - return $files; |
|
189 | - } |
|
188 | + return $files; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Retrieves the contents of the given directory and |
|
193 | - * returns it as a sorted array of FileInfo. |
|
194 | - * |
|
195 | - * @param string $dir path to the directory |
|
196 | - * @param string $sortAttribute attribute to sort on |
|
197 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
198 | - * @param string $mimetypeFilter limit returned content to this mimetype or mimepart |
|
199 | - * @return \OCP\Files\FileInfo[] files |
|
200 | - */ |
|
201 | - public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '') { |
|
202 | - $content = \OC\Files\Filesystem::getDirectoryContent($dir, $mimetypeFilter); |
|
191 | + /** |
|
192 | + * Retrieves the contents of the given directory and |
|
193 | + * returns it as a sorted array of FileInfo. |
|
194 | + * |
|
195 | + * @param string $dir path to the directory |
|
196 | + * @param string $sortAttribute attribute to sort on |
|
197 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
198 | + * @param string $mimetypeFilter limit returned content to this mimetype or mimepart |
|
199 | + * @return \OCP\Files\FileInfo[] files |
|
200 | + */ |
|
201 | + public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '') { |
|
202 | + $content = \OC\Files\Filesystem::getDirectoryContent($dir, $mimetypeFilter); |
|
203 | 203 | |
204 | - return self::sortFiles($content, $sortAttribute, $sortDescending); |
|
205 | - } |
|
204 | + return self::sortFiles($content, $sortAttribute, $sortDescending); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Populate the result set with file tags |
|
209 | - * |
|
210 | - * @param array $fileList |
|
211 | - * @param string $fileIdentifier identifier attribute name for values in $fileList |
|
212 | - * @return array file list populated with tags |
|
213 | - */ |
|
214 | - public static function populateTags(array $fileList, $fileIdentifier = 'fileid') { |
|
215 | - $filesById = []; |
|
216 | - foreach ($fileList as $fileData) { |
|
217 | - $filesById[$fileData[$fileIdentifier]] = $fileData; |
|
218 | - } |
|
219 | - $tagger = \OC::$server->getTagManager()->load('files'); |
|
220 | - $tags = $tagger->getTagsForObjects(array_keys($filesById)); |
|
207 | + /** |
|
208 | + * Populate the result set with file tags |
|
209 | + * |
|
210 | + * @param array $fileList |
|
211 | + * @param string $fileIdentifier identifier attribute name for values in $fileList |
|
212 | + * @return array file list populated with tags |
|
213 | + */ |
|
214 | + public static function populateTags(array $fileList, $fileIdentifier = 'fileid') { |
|
215 | + $filesById = []; |
|
216 | + foreach ($fileList as $fileData) { |
|
217 | + $filesById[$fileData[$fileIdentifier]] = $fileData; |
|
218 | + } |
|
219 | + $tagger = \OC::$server->getTagManager()->load('files'); |
|
220 | + $tags = $tagger->getTagsForObjects(array_keys($filesById)); |
|
221 | 221 | |
222 | - if (!is_array($tags)) { |
|
223 | - throw new \UnexpectedValueException('$tags must be an array'); |
|
224 | - } |
|
222 | + if (!is_array($tags)) { |
|
223 | + throw new \UnexpectedValueException('$tags must be an array'); |
|
224 | + } |
|
225 | 225 | |
226 | - if (!empty($tags)) { |
|
227 | - foreach ($tags as $fileId => $fileTags) { |
|
228 | - $filesById[$fileId]['tags'] = $fileTags; |
|
229 | - } |
|
226 | + if (!empty($tags)) { |
|
227 | + foreach ($tags as $fileId => $fileTags) { |
|
228 | + $filesById[$fileId]['tags'] = $fileTags; |
|
229 | + } |
|
230 | 230 | |
231 | - foreach ($filesById as $key => $fileWithTags) { |
|
232 | - foreach($fileList as $key2 => $file){ |
|
233 | - if( $file[$fileIdentifier] == $key){ |
|
234 | - $fileList[$key2] = $fileWithTags; |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
231 | + foreach ($filesById as $key => $fileWithTags) { |
|
232 | + foreach($fileList as $key2 => $file){ |
|
233 | + if( $file[$fileIdentifier] == $key){ |
|
234 | + $fileList[$key2] = $fileWithTags; |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - foreach ($fileList as $key => $file) { |
|
240 | - if (!array_key_exists('tags', $file)) { |
|
241 | - $fileList[$key]['tags'] = []; |
|
242 | - } |
|
243 | - } |
|
239 | + foreach ($fileList as $key => $file) { |
|
240 | + if (!array_key_exists('tags', $file)) { |
|
241 | + $fileList[$key]['tags'] = []; |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - } |
|
246 | - return $fileList; |
|
247 | - } |
|
245 | + } |
|
246 | + return $fileList; |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Sort the given file info array |
|
251 | - * |
|
252 | - * @param \OCP\Files\FileInfo[] $files files to sort |
|
253 | - * @param string $sortAttribute attribute to sort on |
|
254 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
255 | - * @return \OCP\Files\FileInfo[] sorted files |
|
256 | - */ |
|
257 | - public static function sortFiles($files, $sortAttribute = 'name', $sortDescending = false) { |
|
258 | - $sortFunc = 'compareFileNames'; |
|
259 | - if ($sortAttribute === 'mtime') { |
|
260 | - $sortFunc = 'compareTimestamp'; |
|
261 | - } else if ($sortAttribute === 'size') { |
|
262 | - $sortFunc = 'compareSize'; |
|
263 | - } |
|
264 | - usort($files, array('\OCA\Files\Helper', $sortFunc)); |
|
265 | - if ($sortDescending) { |
|
266 | - $files = array_reverse($files); |
|
267 | - } |
|
268 | - return $files; |
|
269 | - } |
|
249 | + /** |
|
250 | + * Sort the given file info array |
|
251 | + * |
|
252 | + * @param \OCP\Files\FileInfo[] $files files to sort |
|
253 | + * @param string $sortAttribute attribute to sort on |
|
254 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
255 | + * @return \OCP\Files\FileInfo[] sorted files |
|
256 | + */ |
|
257 | + public static function sortFiles($files, $sortAttribute = 'name', $sortDescending = false) { |
|
258 | + $sortFunc = 'compareFileNames'; |
|
259 | + if ($sortAttribute === 'mtime') { |
|
260 | + $sortFunc = 'compareTimestamp'; |
|
261 | + } else if ($sortAttribute === 'size') { |
|
262 | + $sortFunc = 'compareSize'; |
|
263 | + } |
|
264 | + usort($files, array('\OCA\Files\Helper', $sortFunc)); |
|
265 | + if ($sortDescending) { |
|
266 | + $files = array_reverse($files); |
|
267 | + } |
|
268 | + return $files; |
|
269 | + } |
|
270 | 270 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'uploadMaxFilesize' => $maxUploadFileSize, |
55 | 55 | 'maxHumanFilesize' => $maxHumanFileSize, |
56 | 56 | 'freeSpace' => $storageInfo['free'], |
57 | - 'usedSpacePercent' => (int)$storageInfo['relative'], |
|
57 | + 'usedSpacePercent' => (int) $storageInfo['relative'], |
|
58 | 58 | 'owner' => $storageInfo['owner'], |
59 | 59 | 'ownerDisplayName' => $storageInfo['ownerDisplayName'], |
60 | 60 | ]; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @return string icon URL |
68 | 68 | */ |
69 | 69 | public static function determineIcon($file) { |
70 | - if($file['type'] === 'dir') { |
|
70 | + if ($file['type'] === 'dir') { |
|
71 | 71 | $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir'); |
72 | 72 | // TODO: move this part to the client side, using mountType |
73 | 73 | if ($file->isShared()) { |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | } elseif ($file->isMounted()) { |
76 | 76 | $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-external'); |
77 | 77 | } |
78 | - }else{ |
|
78 | + } else { |
|
79 | 79 | $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon($file->getMimetype()); |
80 | 80 | } |
81 | 81 | |
82 | - return substr($icon, 0, -3) . 'svg'; |
|
82 | + return substr($icon, 0, -3).'svg'; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | } |
230 | 230 | |
231 | 231 | foreach ($filesById as $key => $fileWithTags) { |
232 | - foreach($fileList as $key2 => $file){ |
|
233 | - if( $file[$fileIdentifier] == $key){ |
|
232 | + foreach ($fileList as $key2 => $file) { |
|
233 | + if ($file[$fileIdentifier] == $key) { |
|
234 | 234 | $fileList[$key2] = $fileWithTags; |
235 | 235 | } |
236 | 236 | } |
@@ -35,51 +35,51 @@ |
||
35 | 35 | */ |
36 | 36 | class DeleteOrphanedFiles extends Command { |
37 | 37 | |
38 | - const CHUNK_SIZE = 200; |
|
38 | + const CHUNK_SIZE = 200; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var IDBConnection |
|
42 | - */ |
|
43 | - protected $connection; |
|
40 | + /** |
|
41 | + * @var IDBConnection |
|
42 | + */ |
|
43 | + protected $connection; |
|
44 | 44 | |
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - parent::__construct(); |
|
48 | - } |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | 49 | |
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('files:cleanup') |
|
53 | - ->setDescription('cleanup filecache'); |
|
54 | - } |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('files:cleanup') |
|
53 | + ->setDescription('cleanup filecache'); |
|
54 | + } |
|
55 | 55 | |
56 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
57 | - $deletedEntries = 0; |
|
56 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
57 | + $deletedEntries = 0; |
|
58 | 58 | |
59 | - $query = $this->connection->getQueryBuilder(); |
|
60 | - $query->select('fc.fileid') |
|
61 | - ->from('filecache', 'fc') |
|
62 | - ->where($query->expr()->isNull('s.numeric_id')) |
|
63 | - ->leftJoin('fc', 'storages', 's', $query->expr()->eq('fc.storage', 's.numeric_id')) |
|
64 | - ->setMaxResults(self::CHUNK_SIZE); |
|
59 | + $query = $this->connection->getQueryBuilder(); |
|
60 | + $query->select('fc.fileid') |
|
61 | + ->from('filecache', 'fc') |
|
62 | + ->where($query->expr()->isNull('s.numeric_id')) |
|
63 | + ->leftJoin('fc', 'storages', 's', $query->expr()->eq('fc.storage', 's.numeric_id')) |
|
64 | + ->setMaxResults(self::CHUNK_SIZE); |
|
65 | 65 | |
66 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
67 | - $deleteQuery->delete('filecache') |
|
68 | - ->where($deleteQuery->expr()->eq('fileid', $deleteQuery->createParameter('objectid'))); |
|
66 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
67 | + $deleteQuery->delete('filecache') |
|
68 | + ->where($deleteQuery->expr()->eq('fileid', $deleteQuery->createParameter('objectid'))); |
|
69 | 69 | |
70 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
71 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
72 | - $deletedInLastChunk = 0; |
|
73 | - $result = $query->execute(); |
|
74 | - while ($row = $result->fetch()) { |
|
75 | - $deletedInLastChunk++; |
|
76 | - $deletedEntries += $deleteQuery->setParameter('objectid', (int) $row['fileid']) |
|
77 | - ->execute(); |
|
78 | - } |
|
79 | - $result->closeCursor(); |
|
80 | - } |
|
70 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
71 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
72 | + $deletedInLastChunk = 0; |
|
73 | + $result = $query->execute(); |
|
74 | + while ($row = $result->fetch()) { |
|
75 | + $deletedInLastChunk++; |
|
76 | + $deletedEntries += $deleteQuery->setParameter('objectid', (int) $row['fileid']) |
|
77 | + ->execute(); |
|
78 | + } |
|
79 | + $result->closeCursor(); |
|
80 | + } |
|
81 | 81 | |
82 | - $output->writeln("$deletedEntries orphaned file cache entries deleted"); |
|
83 | - } |
|
82 | + $output->writeln("$deletedEntries orphaned file cache entries deleted"); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -34,29 +34,29 @@ |
||
34 | 34 | * @package OCA\Files |
35 | 35 | */ |
36 | 36 | class Capabilities implements ICapability { |
37 | - /** @var IConfig */ |
|
38 | - protected $config; |
|
37 | + /** @var IConfig */ |
|
38 | + protected $config; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Capabilities constructor. |
|
42 | - * |
|
43 | - * @param IConfig $config |
|
44 | - */ |
|
45 | - public function __construct(IConfig $config) { |
|
46 | - $this->config = $config; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Capabilities constructor. |
|
42 | + * |
|
43 | + * @param IConfig $config |
|
44 | + */ |
|
45 | + public function __construct(IConfig $config) { |
|
46 | + $this->config = $config; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Return this classes capabilities |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getCapabilities() { |
|
55 | - return [ |
|
56 | - 'files' => [ |
|
57 | - 'bigfilechunking' => true, |
|
58 | - 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), |
|
59 | - ], |
|
60 | - ]; |
|
61 | - } |
|
49 | + /** |
|
50 | + * Return this classes capabilities |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getCapabilities() { |
|
55 | + return [ |
|
56 | + 'files' => [ |
|
57 | + 'bigfilechunking' => true, |
|
58 | + 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), |
|
59 | + ], |
|
60 | + ]; |
|
61 | + } |
|
62 | 62 | } |
@@ -30,29 +30,29 @@ |
||
30 | 30 | */ |
31 | 31 | class CleanupFileLocks extends TimedJob { |
32 | 32 | |
33 | - /** |
|
34 | - * Default interval in minutes |
|
35 | - * |
|
36 | - * @var int $defaultIntervalMin |
|
37 | - **/ |
|
38 | - protected $defaultIntervalMin = 5; |
|
33 | + /** |
|
34 | + * Default interval in minutes |
|
35 | + * |
|
36 | + * @var int $defaultIntervalMin |
|
37 | + **/ |
|
38 | + protected $defaultIntervalMin = 5; |
|
39 | 39 | |
40 | - /** |
|
41 | - * sets the correct interval for this timed job |
|
42 | - */ |
|
43 | - public function __construct() { |
|
44 | - $this->interval = $this->defaultIntervalMin * 60; |
|
45 | - } |
|
40 | + /** |
|
41 | + * sets the correct interval for this timed job |
|
42 | + */ |
|
43 | + public function __construct() { |
|
44 | + $this->interval = $this->defaultIntervalMin * 60; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Makes the background job do its work |
|
49 | - * |
|
50 | - * @param array $argument unused argument |
|
51 | - */ |
|
52 | - public function run($argument) { |
|
53 | - $lockingProvider = \OC::$server->getLockingProvider(); |
|
54 | - if($lockingProvider instanceof DBLockingProvider) { |
|
55 | - $lockingProvider->cleanExpiredLocks(); |
|
56 | - } |
|
57 | - } |
|
47 | + /** |
|
48 | + * Makes the background job do its work |
|
49 | + * |
|
50 | + * @param array $argument unused argument |
|
51 | + */ |
|
52 | + public function run($argument) { |
|
53 | + $lockingProvider = \OC::$server->getLockingProvider(); |
|
54 | + if($lockingProvider instanceof DBLockingProvider) { |
|
55 | + $lockingProvider->cleanExpiredLocks(); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | */ |
52 | 52 | public function run($argument) { |
53 | 53 | $lockingProvider = \OC::$server->getLockingProvider(); |
54 | - if($lockingProvider instanceof DBLockingProvider) { |
|
54 | + if ($lockingProvider instanceof DBLockingProvider) { |
|
55 | 55 | $lockingProvider->cleanExpiredLocks(); |
56 | 56 | } |
57 | 57 | } |