Passed
Push — master ( c92d35...e03bc6 )
by John
17:48
created
apps/files/templates/list.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 		<div class="actions creatable hidden">
3 3
 			<div id="uploadprogresswrapper">
4 4
 				<div id="uploadprogressbar">
5
-					<em class="label outer" style="display:none"><span class="desktop"><?php p($l->t('Uploading …'));?></span><span class="mobile"><?php p($l->t('…'));?></span></em>
5
+					<em class="label outer" style="display:none"><span class="desktop"><?php p($l->t('Uploading …')); ?></span><span class="mobile"><?php p($l->t('…')); ?></span></em>
6 6
 				</div>
7 7
 				<button class="stop icon-close" style="display:none">
8 8
 					<span class="hidden-visually"><?php p($l->t('Cancel upload')) ?></span>
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 	*/ ?>
19 19
 	<input type="hidden" name="permissions" value="" id="permissions">
20 20
 	<input type="hidden" id="free_space" value="<?php isset($_['freeSpace']) ? p($_['freeSpace']) : '' ?>">
21
-	<?php if(isset($_['dirToken'])):?>
21
+	<?php if (isset($_['dirToken'])):?>
22 22
 	<input type="hidden" id="publicUploadRequestToken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
23 23
 	<input type="hidden" id="dirToken" name="dirToken" value="<?php p($_['dirToken']) ?>" />
24
-	<?php endif;?>
24
+	<?php endif; ?>
25 25
 	<input type="hidden" class="max_human_file_size"
26 26
 		   value="(max <?php isset($_['uploadMaxHumanFilesize']) ? p($_['uploadMaxHumanFilesize']) : ''; ?>)">
27 27
 </div>
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 			<th id='headerName' class="hidden column-name">
51 51
 				<div id="headerName-container">
52 52
 					<a class="name sort columntitle" data-sort="name">
53
-                        <span><?php p($l->t( 'Name' )); ?></span>
53
+                        <span><?php p($l->t('Name')); ?></span>
54 54
                         <span class="sort-indicator"></span>
55 55
 
56 56
                     </a>
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 				<a class="size sort columntitle" data-sort="size"><span><?php p($l->t('Size')); ?></span><span class="sort-indicator"></span></a>
67 67
 			</th>
68 68
 			<th id="headerDate" class="hidden column-mtime">
69
-				<a id="modified" class="columntitle" data-sort="mtime"><span><?php p($l->t( 'Modified' )); ?></span><span class="sort-indicator"></span></a>
69
+				<a id="modified" class="columntitle" data-sort="mtime"><span><?php p($l->t('Modified')); ?></span><span class="sort-indicator"></span></a>
70 70
 			</th>
71 71
 		</tr>
72 72
 	</thead>
@@ -82,6 +82,6 @@  discard block
 block discarded – undo
82 82
 <div id="editor"></div><!-- FIXME Do not use this div in your app! It is deprecated and will be removed in the future! -->
83 83
 <div id="uploadsize-message" title="<?php p($l->t('Upload too large'))?>">
84 84
 	<p>
85
-	<?php p($l->t('The files you are trying to upload exceed the maximum size for file uploads on this server.'));?>
85
+	<?php p($l->t('The files you are trying to upload exceed the maximum size for file uploads on this server.')); ?>
86 86
 	</p>
87 87
 </div>
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ShareController.php 1 patch
Indentation   +583 added lines, -584 removed lines patch added patch discarded remove patch
@@ -73,592 +73,591 @@
 block discarded – undo
73 73
  */
74 74
 class ShareController extends AuthPublicShareController {
75 75
 
76
-	/** @var IConfig */
77
-	protected $config;
78
-	/** @var IUserManager */
79
-	protected $userManager;
80
-	/** @var ILogger */
81
-	protected $logger;
82
-	/** @var \OCP\Activity\IManager */
83
-	protected $activityManager;
84
-	/** @var IPreview */
85
-	protected $previewManager;
86
-	/** @var IRootFolder */
87
-	protected $rootFolder;
88
-	/** @var FederatedShareProvider */
89
-	protected $federatedShareProvider;
90
-	/** @var EventDispatcherInterface */
91
-	protected $eventDispatcher;
92
-	/** @var IL10N */
93
-	protected $l10n;
94
-	/** @var Defaults */
95
-	protected $defaults;
96
-	/** @var ShareManager */
97
-	protected $shareManager;
98
-
99
-	/** @var Share\IShare */
100
-	protected $share;
101
-
102
-	/**
103
-	 * @param string $appName
104
-	 * @param IRequest $request
105
-	 * @param IConfig $config
106
-	 * @param IURLGenerator $urlGenerator
107
-	 * @param IUserManager $userManager
108
-	 * @param ILogger $logger
109
-	 * @param \OCP\Activity\IManager $activityManager
110
-	 * @param \OCP\Share\IManager $shareManager
111
-	 * @param ISession $session
112
-	 * @param IPreview $previewManager
113
-	 * @param IRootFolder $rootFolder
114
-	 * @param FederatedShareProvider $federatedShareProvider
115
-	 * @param EventDispatcherInterface $eventDispatcher
116
-	 * @param IL10N $l10n
117
-	 * @param Defaults $defaults
118
-	 */
119
-	public function __construct(string $appName,
120
-								IRequest $request,
121
-								IConfig $config,
122
-								IURLGenerator $urlGenerator,
123
-								IUserManager $userManager,
124
-								ILogger $logger,
125
-								\OCP\Activity\IManager $activityManager,
126
-								ShareManager $shareManager,
127
-								ISession $session,
128
-								IPreview $previewManager,
129
-								IRootFolder $rootFolder,
130
-								FederatedShareProvider $federatedShareProvider,
131
-								EventDispatcherInterface $eventDispatcher,
132
-								IL10N $l10n,
133
-								Defaults $defaults) {
134
-		parent::__construct($appName, $request, $session, $urlGenerator);
135
-
136
-		$this->config = $config;
137
-		$this->userManager = $userManager;
138
-		$this->logger = $logger;
139
-		$this->activityManager = $activityManager;
140
-		$this->previewManager = $previewManager;
141
-		$this->rootFolder = $rootFolder;
142
-		$this->federatedShareProvider = $federatedShareProvider;
143
-		$this->eventDispatcher = $eventDispatcher;
144
-		$this->l10n = $l10n;
145
-		$this->defaults = $defaults;
146
-		$this->shareManager = $shareManager;
147
-	}
148
-
149
-	/**
150
-	 * @PublicPage
151
-	 * @NoCSRFRequired
152
-	 *
153
-	 * Show the authentication page
154
-	 * The form has to submit to the authenticate method route
155
-	 */
156
-	public function showAuthenticate(): TemplateResponse {
157
-		$templateParameters = ['share' => $this->share];
158
-
159
-		$event = new GenericEvent(null, $templateParameters);
160
-		$this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
161
-
162
-		$response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
163
-		if ($this->share->getSendPasswordByTalk()) {
164
-			$csp = new ContentSecurityPolicy();
165
-			$csp->addAllowedConnectDomain('*');
166
-			$csp->addAllowedMediaDomain('blob:');
167
-			$csp->allowEvalScript(true);
168
-			$response->setContentSecurityPolicy($csp);
169
-		}
170
-
171
-		return $response;
172
-	}
173
-
174
-	/**
175
-	 * The template to show when authentication failed
176
-	 */
177
-	protected function showAuthFailed(): TemplateResponse {
178
-		$templateParameters = ['share' => $this->share, 'wrongpw' => true];
179
-
180
-		$event = new GenericEvent(null, $templateParameters);
181
-		$this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
182
-
183
-		$response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
184
-		if ($this->share->getSendPasswordByTalk()) {
185
-			$csp = new ContentSecurityPolicy();
186
-			$csp->addAllowedConnectDomain('*');
187
-			$csp->addAllowedMediaDomain('blob:');
188
-			$csp->allowEvalScript(true);
189
-			$response->setContentSecurityPolicy($csp);
190
-		}
191
-
192
-		return $response;
193
-	}
194
-
195
-	protected function verifyPassword(string $password): bool {
196
-		return $this->shareManager->checkPassword($this->share, $password);
197
-	}
198
-
199
-	protected function getPasswordHash(): string {
200
-		return $this->share->getPassword();
201
-	}
202
-
203
-	public function isValidToken(): bool {
204
-		try {
205
-			$this->share = $this->shareManager->getShareByToken($this->getToken());
206
-		} catch (ShareNotFound $e) {
207
-			return false;
208
-		}
209
-
210
-		return true;
211
-	}
212
-
213
-	protected function isPasswordProtected(): bool {
214
-		return $this->share->getPassword() !== null;
215
-	}
216
-
217
-	protected function authSucceeded() {
218
-		// For share this was always set so it is still used in other apps
219
-		$this->session->set('public_link_authenticated', (string)$this->share->getId());
220
-	}
221
-
222
-	protected function authFailed() {
223
-		$this->emitAccessShareHook($this->share, 403, 'Wrong password');
224
-	}
225
-
226
-	/**
227
-	 * throws hooks when a share is attempted to be accessed
228
-	 *
229
-	 * @param \OCP\Share\IShare|string $share the Share instance if available,
230
-	 * otherwise token
231
-	 * @param int $errorCode
232
-	 * @param string $errorMessage
233
-	 * @throws \OC\HintException
234
-	 * @throws \OC\ServerNotAvailableException
235
-	 */
236
-	protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') {
237
-		$itemType = $itemSource = $uidOwner = '';
238
-		$token = $share;
239
-		$exception = null;
240
-		if($share instanceof \OCP\Share\IShare) {
241
-			try {
242
-				$token = $share->getToken();
243
-				$uidOwner = $share->getSharedBy();
244
-				$itemType = $share->getNodeType();
245
-				$itemSource = $share->getNodeId();
246
-			} catch (\Exception $e) {
247
-				// we log what we know and pass on the exception afterwards
248
-				$exception = $e;
249
-			}
250
-		}
251
-		\OC_Hook::emit(Share::class, 'share_link_access', [
252
-			'itemType' => $itemType,
253
-			'itemSource' => $itemSource,
254
-			'uidOwner' => $uidOwner,
255
-			'token' => $token,
256
-			'errorCode' => $errorCode,
257
-			'errorMessage' => $errorMessage,
258
-		]);
259
-		if(!is_null($exception)) {
260
-			throw $exception;
261
-		}
262
-	}
263
-
264
-	/**
265
-	 * Validate the permissions of the share
266
-	 *
267
-	 * @param Share\IShare $share
268
-	 * @return bool
269
-	 */
270
-	private function validateShare(\OCP\Share\IShare $share) {
271
-		return $share->getNode()->isReadable() && $share->getNode()->isShareable();
272
-	}
273
-
274
-	/**
275
-	 * @PublicPage
276
-	 * @NoCSRFRequired
277
-	 *
278
-
279
-	 * @param string $path
280
-	 * @return TemplateResponse
281
-	 * @throws NotFoundException
282
-	 * @throws \Exception
283
-	 */
284
-	public function showShare($path = ''): TemplateResponse {
285
-		\OC_User::setIncognitoMode(true);
286
-
287
-		// Check whether share exists
288
-		try {
289
-			$share = $this->shareManager->getShareByToken($this->getToken());
290
-		} catch (ShareNotFound $e) {
291
-			$this->emitAccessShareHook($this->getToken(), 404, 'Share not found');
292
-			throw new NotFoundException();
293
-		}
294
-
295
-		if (!$this->validateShare($share)) {
296
-			throw new NotFoundException();
297
-		}
298
-		// We can't get the path of a file share
299
-		try {
300
-			if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
301
-				$this->emitAccessShareHook($share, 404, 'Share not found');
302
-				throw new NotFoundException();
303
-			}
304
-		} catch (\Exception $e) {
305
-			$this->emitAccessShareHook($share, 404, 'Share not found');
306
-			throw $e;
307
-		}
308
-
309
-		$shareTmpl = [];
310
-		$shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
311
-		$shareTmpl['owner'] = $share->getShareOwner();
312
-		$shareTmpl['filename'] = $share->getNode()->getName();
313
-		$shareTmpl['directory_path'] = $share->getTarget();
314
-		$shareTmpl['note'] = $share->getNote();
315
-		$shareTmpl['mimetype'] = $share->getNode()->getMimetype();
316
-		$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
317
-		$shareTmpl['dirToken'] = $this->getToken();
318
-		$shareTmpl['sharingToken'] = $this->getToken();
319
-		$shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
320
-		$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
321
-		$shareTmpl['dir'] = '';
322
-		$shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
323
-		$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
324
-		$shareTmpl['hideDownload'] = $share->getHideDownload();
325
-
326
-		// Show file list
327
-		$hideFileList = false;
328
-		if ($share->getNode() instanceof \OCP\Files\Folder) {
329
-			/** @var \OCP\Files\Folder $rootFolder */
330
-			$rootFolder = $share->getNode();
331
-
332
-			try {
333
-				$folderNode = $rootFolder->get($path);
334
-			} catch (\OCP\Files\NotFoundException $e) {
335
-				$this->emitAccessShareHook($share, 404, 'Share not found');
336
-				throw new NotFoundException();
337
-			}
338
-
339
-			$shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath());
340
-
341
-			/*
76
+    /** @var IConfig */
77
+    protected $config;
78
+    /** @var IUserManager */
79
+    protected $userManager;
80
+    /** @var ILogger */
81
+    protected $logger;
82
+    /** @var \OCP\Activity\IManager */
83
+    protected $activityManager;
84
+    /** @var IPreview */
85
+    protected $previewManager;
86
+    /** @var IRootFolder */
87
+    protected $rootFolder;
88
+    /** @var FederatedShareProvider */
89
+    protected $federatedShareProvider;
90
+    /** @var EventDispatcherInterface */
91
+    protected $eventDispatcher;
92
+    /** @var IL10N */
93
+    protected $l10n;
94
+    /** @var Defaults */
95
+    protected $defaults;
96
+    /** @var ShareManager */
97
+    protected $shareManager;
98
+
99
+    /** @var Share\IShare */
100
+    protected $share;
101
+
102
+    /**
103
+     * @param string $appName
104
+     * @param IRequest $request
105
+     * @param IConfig $config
106
+     * @param IURLGenerator $urlGenerator
107
+     * @param IUserManager $userManager
108
+     * @param ILogger $logger
109
+     * @param \OCP\Activity\IManager $activityManager
110
+     * @param \OCP\Share\IManager $shareManager
111
+     * @param ISession $session
112
+     * @param IPreview $previewManager
113
+     * @param IRootFolder $rootFolder
114
+     * @param FederatedShareProvider $federatedShareProvider
115
+     * @param EventDispatcherInterface $eventDispatcher
116
+     * @param IL10N $l10n
117
+     * @param Defaults $defaults
118
+     */
119
+    public function __construct(string $appName,
120
+                                IRequest $request,
121
+                                IConfig $config,
122
+                                IURLGenerator $urlGenerator,
123
+                                IUserManager $userManager,
124
+                                ILogger $logger,
125
+                                \OCP\Activity\IManager $activityManager,
126
+                                ShareManager $shareManager,
127
+                                ISession $session,
128
+                                IPreview $previewManager,
129
+                                IRootFolder $rootFolder,
130
+                                FederatedShareProvider $federatedShareProvider,
131
+                                EventDispatcherInterface $eventDispatcher,
132
+                                IL10N $l10n,
133
+                                Defaults $defaults) {
134
+        parent::__construct($appName, $request, $session, $urlGenerator);
135
+
136
+        $this->config = $config;
137
+        $this->userManager = $userManager;
138
+        $this->logger = $logger;
139
+        $this->activityManager = $activityManager;
140
+        $this->previewManager = $previewManager;
141
+        $this->rootFolder = $rootFolder;
142
+        $this->federatedShareProvider = $federatedShareProvider;
143
+        $this->eventDispatcher = $eventDispatcher;
144
+        $this->l10n = $l10n;
145
+        $this->defaults = $defaults;
146
+        $this->shareManager = $shareManager;
147
+    }
148
+
149
+    /**
150
+     * @PublicPage
151
+     * @NoCSRFRequired
152
+     *
153
+     * Show the authentication page
154
+     * The form has to submit to the authenticate method route
155
+     */
156
+    public function showAuthenticate(): TemplateResponse {
157
+        $templateParameters = ['share' => $this->share];
158
+
159
+        $event = new GenericEvent(null, $templateParameters);
160
+        $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
161
+
162
+        $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
163
+        if ($this->share->getSendPasswordByTalk()) {
164
+            $csp = new ContentSecurityPolicy();
165
+            $csp->addAllowedConnectDomain('*');
166
+            $csp->addAllowedMediaDomain('blob:');
167
+            $csp->allowEvalScript(true);
168
+            $response->setContentSecurityPolicy($csp);
169
+        }
170
+
171
+        return $response;
172
+    }
173
+
174
+    /**
175
+     * The template to show when authentication failed
176
+     */
177
+    protected function showAuthFailed(): TemplateResponse {
178
+        $templateParameters = ['share' => $this->share, 'wrongpw' => true];
179
+
180
+        $event = new GenericEvent(null, $templateParameters);
181
+        $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
182
+
183
+        $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
184
+        if ($this->share->getSendPasswordByTalk()) {
185
+            $csp = new ContentSecurityPolicy();
186
+            $csp->addAllowedConnectDomain('*');
187
+            $csp->addAllowedMediaDomain('blob:');
188
+            $csp->allowEvalScript(true);
189
+            $response->setContentSecurityPolicy($csp);
190
+        }
191
+
192
+        return $response;
193
+    }
194
+
195
+    protected function verifyPassword(string $password): bool {
196
+        return $this->shareManager->checkPassword($this->share, $password);
197
+    }
198
+
199
+    protected function getPasswordHash(): string {
200
+        return $this->share->getPassword();
201
+    }
202
+
203
+    public function isValidToken(): bool {
204
+        try {
205
+            $this->share = $this->shareManager->getShareByToken($this->getToken());
206
+        } catch (ShareNotFound $e) {
207
+            return false;
208
+        }
209
+
210
+        return true;
211
+    }
212
+
213
+    protected function isPasswordProtected(): bool {
214
+        return $this->share->getPassword() !== null;
215
+    }
216
+
217
+    protected function authSucceeded() {
218
+        // For share this was always set so it is still used in other apps
219
+        $this->session->set('public_link_authenticated', (string)$this->share->getId());
220
+    }
221
+
222
+    protected function authFailed() {
223
+        $this->emitAccessShareHook($this->share, 403, 'Wrong password');
224
+    }
225
+
226
+    /**
227
+     * throws hooks when a share is attempted to be accessed
228
+     *
229
+     * @param \OCP\Share\IShare|string $share the Share instance if available,
230
+     * otherwise token
231
+     * @param int $errorCode
232
+     * @param string $errorMessage
233
+     * @throws \OC\HintException
234
+     * @throws \OC\ServerNotAvailableException
235
+     */
236
+    protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') {
237
+        $itemType = $itemSource = $uidOwner = '';
238
+        $token = $share;
239
+        $exception = null;
240
+        if($share instanceof \OCP\Share\IShare) {
241
+            try {
242
+                $token = $share->getToken();
243
+                $uidOwner = $share->getSharedBy();
244
+                $itemType = $share->getNodeType();
245
+                $itemSource = $share->getNodeId();
246
+            } catch (\Exception $e) {
247
+                // we log what we know and pass on the exception afterwards
248
+                $exception = $e;
249
+            }
250
+        }
251
+        \OC_Hook::emit(Share::class, 'share_link_access', [
252
+            'itemType' => $itemType,
253
+            'itemSource' => $itemSource,
254
+            'uidOwner' => $uidOwner,
255
+            'token' => $token,
256
+            'errorCode' => $errorCode,
257
+            'errorMessage' => $errorMessage,
258
+        ]);
259
+        if(!is_null($exception)) {
260
+            throw $exception;
261
+        }
262
+    }
263
+
264
+    /**
265
+     * Validate the permissions of the share
266
+     *
267
+     * @param Share\IShare $share
268
+     * @return bool
269
+     */
270
+    private function validateShare(\OCP\Share\IShare $share) {
271
+        return $share->getNode()->isReadable() && $share->getNode()->isShareable();
272
+    }
273
+
274
+    /**
275
+     * @PublicPage
276
+     * @NoCSRFRequired
277
+     *
278
+     * @param string $path
279
+     * @return TemplateResponse
280
+     * @throws NotFoundException
281
+     * @throws \Exception
282
+     */
283
+    public function showShare($path = ''): TemplateResponse {
284
+        \OC_User::setIncognitoMode(true);
285
+
286
+        // Check whether share exists
287
+        try {
288
+            $share = $this->shareManager->getShareByToken($this->getToken());
289
+        } catch (ShareNotFound $e) {
290
+            $this->emitAccessShareHook($this->getToken(), 404, 'Share not found');
291
+            throw new NotFoundException();
292
+        }
293
+
294
+        if (!$this->validateShare($share)) {
295
+            throw new NotFoundException();
296
+        }
297
+        // We can't get the path of a file share
298
+        try {
299
+            if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
300
+                $this->emitAccessShareHook($share, 404, 'Share not found');
301
+                throw new NotFoundException();
302
+            }
303
+        } catch (\Exception $e) {
304
+            $this->emitAccessShareHook($share, 404, 'Share not found');
305
+            throw $e;
306
+        }
307
+
308
+        $shareTmpl = [];
309
+        $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
310
+        $shareTmpl['owner'] = $share->getShareOwner();
311
+        $shareTmpl['filename'] = $share->getNode()->getName();
312
+        $shareTmpl['directory_path'] = $share->getTarget();
313
+        $shareTmpl['note'] = $share->getNote();
314
+        $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
315
+        $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
316
+        $shareTmpl['dirToken'] = $this->getToken();
317
+        $shareTmpl['sharingToken'] = $this->getToken();
318
+        $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
319
+        $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
320
+        $shareTmpl['dir'] = '';
321
+        $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
322
+        $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
323
+        $shareTmpl['hideDownload'] = $share->getHideDownload();
324
+
325
+        // Show file list
326
+        $hideFileList = false;
327
+        if ($share->getNode() instanceof \OCP\Files\Folder) {
328
+            /** @var \OCP\Files\Folder $rootFolder */
329
+            $rootFolder = $share->getNode();
330
+
331
+            try {
332
+                $folderNode = $rootFolder->get($path);
333
+            } catch (\OCP\Files\NotFoundException $e) {
334
+                $this->emitAccessShareHook($share, 404, 'Share not found');
335
+                throw new NotFoundException();
336
+            }
337
+
338
+            $shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath());
339
+
340
+            /*
342 341
 			 * The OC_Util methods require a view. This just uses the node API
343 342
 			 */
344
-			$freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
345
-			if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
346
-				$freeSpace = max($freeSpace, 0);
347
-			} else {
348
-				$freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
349
-			}
350
-
351
-			$hideFileList = !($share->getPermissions() & \OCP\Constants::PERMISSION_READ);
352
-			$maxUploadFilesize = $freeSpace;
353
-
354
-			$folder = new Template('files', 'list', '');
355
-			$folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath()));
356
-			$folder->assign('dirToken', $this->getToken());
357
-			$folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
358
-			$folder->assign('isPublic', true);
359
-			$folder->assign('hideFileList', $hideFileList);
360
-			$folder->assign('publicUploadEnabled', 'no');
361
-			$folder->assign('showgridview', true);
362
-			$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
363
-			$folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize));
364
-			$folder->assign('freeSpace', $freeSpace);
365
-			$folder->assign('usedSpacePercent', 0);
366
-			$folder->assign('trash', false);
367
-			$shareTmpl['folder'] = $folder->fetchPage();
368
-		}
369
-
370
-		$shareTmpl['showgridview'] = true;
371
-
372
-		$shareTmpl['hideFileList'] = $hideFileList;
373
-		$shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
374
-		$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $this->getToken()]);
375
-		$shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $this->getToken()]);
376
-		$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
377
-		$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
378
-		$shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024);
379
-		$shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
380
-		$shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null);
381
-		$shareTmpl['previewURL'] = $shareTmpl['downloadURL'];
382
-		$ogPreview = '';
383
-		if ($shareTmpl['previewSupported']) {
384
-			$shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview',
385
-				['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]);
386
-			$ogPreview = $shareTmpl['previewImage'];
387
-
388
-			// We just have direct previews for image files
389
-			if ($share->getNode()->getMimePart() === 'image') {
390
-				$shareTmpl['previewURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.publicpreview.directLink', ['token' => $this->getToken()]);
391
-
392
-				$ogPreview = $shareTmpl['previewURL'];
393
-
394
-				//Whatapp is kind of picky about their size requirements
395
-				if ($this->request->isUserAgent(['/^WhatsApp/'])) {
396
-					$ogPreview = $this->urlGenerator->linkToRouteAbsolute('files_sharing.PublicPreview.getPreview', [
397
-						'token' => $this->getToken(),
398
-						'x' => 256,
399
-						'y' => 256,
400
-						'a' => true,
401
-					]);
402
-				}
403
-			}
404
-		} else {
405
-			$shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png'));
406
-			$ogPreview = $shareTmpl['previewImage'];
407
-		}
408
-
409
-		// Load files we need
410
-		\OCP\Util::addScript('files', 'file-upload');
411
-		\OCP\Util::addStyle('files_sharing', 'publicView');
412
-		\OCP\Util::addScript('files_sharing', 'public');
413
-		\OCP\Util::addScript('files_sharing', 'templates');
414
-		\OCP\Util::addScript('files_sharing', 'public_note');
415
-		\OCP\Util::addScript('files', 'fileactions');
416
-		\OCP\Util::addScript('files', 'fileactionsmenu');
417
-		\OCP\Util::addScript('files', 'jquery.fileupload');
418
-		\OCP\Util::addScript('files_sharing', 'files_drop');
419
-
420
-		if (isset($shareTmpl['folder'])) {
421
-			// JS required for folders
422
-			\OCP\Util::addStyle('files', 'merged');
423
-			\OCP\Util::addScript('files', 'filesummary');
424
-			\OCP\Util::addScript('files', 'templates');
425
-			\OCP\Util::addScript('files', 'breadcrumb');
426
-			\OCP\Util::addScript('files', 'fileinfomodel');
427
-			\OCP\Util::addScript('files', 'newfilemenu');
428
-			\OCP\Util::addScript('files', 'files');
429
-			\OCP\Util::addScript('files', 'filemultiselectmenu');
430
-			\OCP\Util::addScript('files', 'filelist');
431
-			\OCP\Util::addScript('files', 'keyboardshortcuts');
432
-		}
433
-
434
-		// OpenGraph Support: http://ogp.me/
435
-		\OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $shareTmpl['filename']]);
436
-		\OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->defaults->getName() . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')]);
437
-		\OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]);
438
-		\OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]);
439
-		\OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
440
-		\OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $ogPreview]);
441
-
442
-		$this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts');
443
-
444
-		$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
445
-		$csp->addAllowedFrameDomain('\'self\'');
446
-
447
-		$response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
448
-		$response->setHeaderTitle($shareTmpl['filename']);
449
-		$response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
450
-		if (!$share->getHideDownload()) {
451
-			$response->setHeaderActions([
452
-				new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),
453
-				new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']),
454
-				new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']),
455
-				new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']),
456
-			]);
457
-		}
458
-
459
-		$response->setContentSecurityPolicy($csp);
460
-
461
-		$this->emitAccessShareHook($share);
462
-
463
-		return $response;
464
-	}
465
-
466
-	/**
467
-	 * @PublicPage
468
-	 * @NoCSRFRequired
469
-	 *
470
-	 * @param string $token
471
-	 * @param string $files
472
-	 * @param string $path
473
-	 * @param string $downloadStartSecret
474
-	 * @return void|\OCP\AppFramework\Http\Response
475
-	 * @throws NotFoundException
476
-	 */
477
-	public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
478
-		\OC_User::setIncognitoMode(true);
479
-
480
-		$share = $this->shareManager->getShareByToken($token);
481
-
482
-		if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
483
-			return new \OCP\AppFramework\Http\DataResponse('Share is read-only');
484
-		}
485
-
486
-		$files_list = null;
487
-		if (!is_null($files)) { // download selected files
488
-			$files_list = json_decode($files);
489
-			// in case we get only a single file
490
-			if ($files_list === null) {
491
-				$files_list = [$files];
492
-			}
493
-			// Just in case $files is a single int like '1234'
494
-			if (!is_array($files_list)) {
495
-				$files_list = [$files_list];
496
-			}
497
-		}
498
-
499
-
500
-		if (!$this->validateShare($share)) {
501
-			throw new NotFoundException();
502
-		}
503
-
504
-		$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
505
-		$originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
506
-
507
-
508
-		// Single file share
509
-		if ($share->getNode() instanceof \OCP\Files\File) {
510
-			// Single file download
511
-			$this->singleFileDownloaded($share, $share->getNode());
512
-		}
513
-		// Directory share
514
-		else {
515
-			/** @var \OCP\Files\Folder $node */
516
-			$node = $share->getNode();
517
-
518
-			// Try to get the path
519
-			if ($path !== '') {
520
-				try {
521
-					$node = $node->get($path);
522
-				} catch (NotFoundException $e) {
523
-					$this->emitAccessShareHook($share, 404, 'Share not found');
524
-					return new NotFoundResponse();
525
-				}
526
-			}
527
-
528
-			$originalSharePath = $userFolder->getRelativePath($node->getPath());
529
-
530
-			if ($node instanceof \OCP\Files\File) {
531
-				// Single file download
532
-				$this->singleFileDownloaded($share, $share->getNode());
533
-			} else if (!empty($files_list)) {
534
-				$this->fileListDownloaded($share, $files_list, $node);
535
-			} else {
536
-				// The folder is downloaded
537
-				$this->singleFileDownloaded($share, $share->getNode());
538
-			}
539
-		}
540
-
541
-		/* FIXME: We should do this all nicely in OCP */
542
-		OC_Util::tearDownFS();
543
-		OC_Util::setupFS($share->getShareOwner());
544
-
545
-		/**
546
-		 * this sets a cookie to be able to recognize the start of the download
547
-		 * the content must not be longer than 32 characters and must only contain
548
-		 * alphanumeric characters
549
-		 */
550
-		if (!empty($downloadStartSecret)
551
-			&& !isset($downloadStartSecret[32])
552
-			&& preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
553
-
554
-			// FIXME: set on the response once we use an actual app framework response
555
-			setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
556
-		}
557
-
558
-		$this->emitAccessShareHook($share);
559
-
560
-		$server_params = array( 'head' => $this->request->getMethod() === 'HEAD' );
561
-
562
-		/**
563
-		 * Http range requests support
564
-		 */
565
-		if (isset($_SERVER['HTTP_RANGE'])) {
566
-			$server_params['range'] = $this->request->getHeader('Range');
567
-		}
568
-
569
-		// download selected files
570
-		if (!is_null($files) && $files !== '') {
571
-			// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
572
-			// after dispatching the request which results in a "Cannot modify header information" notice.
573
-			OC_Files::get($originalSharePath, $files_list, $server_params);
574
-			exit();
575
-		} else {
576
-			// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
577
-			// after dispatching the request which results in a "Cannot modify header information" notice.
578
-			OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params);
579
-			exit();
580
-		}
581
-	}
582
-
583
-	/**
584
-	 * create activity for every downloaded file
585
-	 *
586
-	 * @param Share\IShare $share
587
-	 * @param array $files_list
588
-	 * @param \OCP\Files\Folder $node
589
-	 */
590
-	protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
591
-		foreach ($files_list as $file) {
592
-			$subNode = $node->get($file);
593
-			$this->singleFileDownloaded($share, $subNode);
594
-		}
595
-
596
-	}
597
-
598
-	/**
599
-	 * create activity if a single file was downloaded from a link share
600
-	 *
601
-	 * @param Share\IShare $share
602
-	 */
603
-	protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
604
-
605
-		$fileId = $node->getId();
606
-
607
-		$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
608
-		$userNodeList = $userFolder->getById($fileId);
609
-		$userNode = $userNodeList[0];
610
-		$ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
611
-		$userPath = $userFolder->getRelativePath($userNode->getPath());
612
-		$ownerPath = $ownerFolder->getRelativePath($node->getPath());
613
-
614
-		$parameters = [$userPath];
615
-
616
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
617
-			if ($node instanceof \OCP\Files\File) {
618
-				$subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
619
-			} else {
620
-				$subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
621
-			}
622
-			$parameters[] = $share->getSharedWith();
623
-		} else {
624
-			if ($node instanceof \OCP\Files\File) {
625
-				$subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
626
-			} else {
627
-				$subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
628
-			}
629
-		}
630
-
631
-		$this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);
632
-
633
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
634
-			$parameters[0] = $ownerPath;
635
-			$this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath);
636
-		}
637
-	}
638
-
639
-	/**
640
-	 * publish activity
641
-	 *
642
-	 * @param string $subject
643
-	 * @param array $parameters
644
-	 * @param string $affectedUser
645
-	 * @param int $fileId
646
-	 * @param string $filePath
647
-	 */
648
-	protected function publishActivity($subject,
649
-										array $parameters,
650
-										$affectedUser,
651
-										$fileId,
652
-										$filePath) {
653
-
654
-		$event = $this->activityManager->generateEvent();
655
-		$event->setApp('files_sharing')
656
-			->setType('public_links')
657
-			->setSubject($subject, $parameters)
658
-			->setAffectedUser($affectedUser)
659
-			->setObject('files', $fileId, $filePath);
660
-		$this->activityManager->publish($event);
661
-	}
343
+            $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
344
+            if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
345
+                $freeSpace = max($freeSpace, 0);
346
+            } else {
347
+                $freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
348
+            }
349
+
350
+            $hideFileList = !($share->getPermissions() & \OCP\Constants::PERMISSION_READ);
351
+            $maxUploadFilesize = $freeSpace;
352
+
353
+            $folder = new Template('files', 'list', '');
354
+            $folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath()));
355
+            $folder->assign('dirToken', $this->getToken());
356
+            $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
357
+            $folder->assign('isPublic', true);
358
+            $folder->assign('hideFileList', $hideFileList);
359
+            $folder->assign('publicUploadEnabled', 'no');
360
+            $folder->assign('showgridview', true);
361
+            $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
362
+            $folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize));
363
+            $folder->assign('freeSpace', $freeSpace);
364
+            $folder->assign('usedSpacePercent', 0);
365
+            $folder->assign('trash', false);
366
+            $shareTmpl['folder'] = $folder->fetchPage();
367
+        }
368
+
369
+        $shareTmpl['showgridview'] = true;
370
+
371
+        $shareTmpl['hideFileList'] = $hideFileList;
372
+        $shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
373
+        $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $this->getToken()]);
374
+        $shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $this->getToken()]);
375
+        $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
376
+        $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
377
+        $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024);
378
+        $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
379
+        $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null);
380
+        $shareTmpl['previewURL'] = $shareTmpl['downloadURL'];
381
+        $ogPreview = '';
382
+        if ($shareTmpl['previewSupported']) {
383
+            $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview',
384
+                ['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]);
385
+            $ogPreview = $shareTmpl['previewImage'];
386
+
387
+            // We just have direct previews for image files
388
+            if ($share->getNode()->getMimePart() === 'image') {
389
+                $shareTmpl['previewURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.publicpreview.directLink', ['token' => $this->getToken()]);
390
+
391
+                $ogPreview = $shareTmpl['previewURL'];
392
+
393
+                //Whatapp is kind of picky about their size requirements
394
+                if ($this->request->isUserAgent(['/^WhatsApp/'])) {
395
+                    $ogPreview = $this->urlGenerator->linkToRouteAbsolute('files_sharing.PublicPreview.getPreview', [
396
+                        'token' => $this->getToken(),
397
+                        'x' => 256,
398
+                        'y' => 256,
399
+                        'a' => true,
400
+                    ]);
401
+                }
402
+            }
403
+        } else {
404
+            $shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png'));
405
+            $ogPreview = $shareTmpl['previewImage'];
406
+        }
407
+
408
+        // Load files we need
409
+        \OCP\Util::addScript('files', 'file-upload');
410
+        \OCP\Util::addStyle('files_sharing', 'publicView');
411
+        \OCP\Util::addScript('files_sharing', 'public');
412
+        \OCP\Util::addScript('files_sharing', 'templates');
413
+        \OCP\Util::addScript('files_sharing', 'public_note');
414
+        \OCP\Util::addScript('files', 'fileactions');
415
+        \OCP\Util::addScript('files', 'fileactionsmenu');
416
+        \OCP\Util::addScript('files', 'jquery.fileupload');
417
+        \OCP\Util::addScript('files_sharing', 'files_drop');
418
+
419
+        if (isset($shareTmpl['folder'])) {
420
+            // JS required for folders
421
+            \OCP\Util::addStyle('files', 'merged');
422
+            \OCP\Util::addScript('files', 'filesummary');
423
+            \OCP\Util::addScript('files', 'templates');
424
+            \OCP\Util::addScript('files', 'breadcrumb');
425
+            \OCP\Util::addScript('files', 'fileinfomodel');
426
+            \OCP\Util::addScript('files', 'newfilemenu');
427
+            \OCP\Util::addScript('files', 'files');
428
+            \OCP\Util::addScript('files', 'filemultiselectmenu');
429
+            \OCP\Util::addScript('files', 'filelist');
430
+            \OCP\Util::addScript('files', 'keyboardshortcuts');
431
+        }
432
+
433
+        // OpenGraph Support: http://ogp.me/
434
+        \OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $shareTmpl['filename']]);
435
+        \OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->defaults->getName() . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')]);
436
+        \OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]);
437
+        \OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]);
438
+        \OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
439
+        \OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $ogPreview]);
440
+
441
+        $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts');
442
+
443
+        $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
444
+        $csp->addAllowedFrameDomain('\'self\'');
445
+
446
+        $response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
447
+        $response->setHeaderTitle($shareTmpl['filename']);
448
+        $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
449
+        if (!$share->getHideDownload()) {
450
+            $response->setHeaderActions([
451
+                new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),
452
+                new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']),
453
+                new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']),
454
+                new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']),
455
+            ]);
456
+        }
457
+
458
+        $response->setContentSecurityPolicy($csp);
459
+
460
+        $this->emitAccessShareHook($share);
461
+
462
+        return $response;
463
+    }
464
+
465
+    /**
466
+     * @PublicPage
467
+     * @NoCSRFRequired
468
+     *
469
+     * @param string $token
470
+     * @param string $files
471
+     * @param string $path
472
+     * @param string $downloadStartSecret
473
+     * @return void|\OCP\AppFramework\Http\Response
474
+     * @throws NotFoundException
475
+     */
476
+    public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
477
+        \OC_User::setIncognitoMode(true);
478
+
479
+        $share = $this->shareManager->getShareByToken($token);
480
+
481
+        if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
482
+            return new \OCP\AppFramework\Http\DataResponse('Share is read-only');
483
+        }
484
+
485
+        $files_list = null;
486
+        if (!is_null($files)) { // download selected files
487
+            $files_list = json_decode($files);
488
+            // in case we get only a single file
489
+            if ($files_list === null) {
490
+                $files_list = [$files];
491
+            }
492
+            // Just in case $files is a single int like '1234'
493
+            if (!is_array($files_list)) {
494
+                $files_list = [$files_list];
495
+            }
496
+        }
497
+
498
+
499
+        if (!$this->validateShare($share)) {
500
+            throw new NotFoundException();
501
+        }
502
+
503
+        $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
504
+        $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
505
+
506
+
507
+        // Single file share
508
+        if ($share->getNode() instanceof \OCP\Files\File) {
509
+            // Single file download
510
+            $this->singleFileDownloaded($share, $share->getNode());
511
+        }
512
+        // Directory share
513
+        else {
514
+            /** @var \OCP\Files\Folder $node */
515
+            $node = $share->getNode();
516
+
517
+            // Try to get the path
518
+            if ($path !== '') {
519
+                try {
520
+                    $node = $node->get($path);
521
+                } catch (NotFoundException $e) {
522
+                    $this->emitAccessShareHook($share, 404, 'Share not found');
523
+                    return new NotFoundResponse();
524
+                }
525
+            }
526
+
527
+            $originalSharePath = $userFolder->getRelativePath($node->getPath());
528
+
529
+            if ($node instanceof \OCP\Files\File) {
530
+                // Single file download
531
+                $this->singleFileDownloaded($share, $share->getNode());
532
+            } else if (!empty($files_list)) {
533
+                $this->fileListDownloaded($share, $files_list, $node);
534
+            } else {
535
+                // The folder is downloaded
536
+                $this->singleFileDownloaded($share, $share->getNode());
537
+            }
538
+        }
539
+
540
+        /* FIXME: We should do this all nicely in OCP */
541
+        OC_Util::tearDownFS();
542
+        OC_Util::setupFS($share->getShareOwner());
543
+
544
+        /**
545
+         * this sets a cookie to be able to recognize the start of the download
546
+         * the content must not be longer than 32 characters and must only contain
547
+         * alphanumeric characters
548
+         */
549
+        if (!empty($downloadStartSecret)
550
+            && !isset($downloadStartSecret[32])
551
+            && preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
552
+
553
+            // FIXME: set on the response once we use an actual app framework response
554
+            setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
555
+        }
556
+
557
+        $this->emitAccessShareHook($share);
558
+
559
+        $server_params = array( 'head' => $this->request->getMethod() === 'HEAD' );
560
+
561
+        /**
562
+         * Http range requests support
563
+         */
564
+        if (isset($_SERVER['HTTP_RANGE'])) {
565
+            $server_params['range'] = $this->request->getHeader('Range');
566
+        }
567
+
568
+        // download selected files
569
+        if (!is_null($files) && $files !== '') {
570
+            // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
571
+            // after dispatching the request which results in a "Cannot modify header information" notice.
572
+            OC_Files::get($originalSharePath, $files_list, $server_params);
573
+            exit();
574
+        } else {
575
+            // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
576
+            // after dispatching the request which results in a "Cannot modify header information" notice.
577
+            OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params);
578
+            exit();
579
+        }
580
+    }
581
+
582
+    /**
583
+     * create activity for every downloaded file
584
+     *
585
+     * @param Share\IShare $share
586
+     * @param array $files_list
587
+     * @param \OCP\Files\Folder $node
588
+     */
589
+    protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
590
+        foreach ($files_list as $file) {
591
+            $subNode = $node->get($file);
592
+            $this->singleFileDownloaded($share, $subNode);
593
+        }
594
+
595
+    }
596
+
597
+    /**
598
+     * create activity if a single file was downloaded from a link share
599
+     *
600
+     * @param Share\IShare $share
601
+     */
602
+    protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
603
+
604
+        $fileId = $node->getId();
605
+
606
+        $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
607
+        $userNodeList = $userFolder->getById($fileId);
608
+        $userNode = $userNodeList[0];
609
+        $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
610
+        $userPath = $userFolder->getRelativePath($userNode->getPath());
611
+        $ownerPath = $ownerFolder->getRelativePath($node->getPath());
612
+
613
+        $parameters = [$userPath];
614
+
615
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
616
+            if ($node instanceof \OCP\Files\File) {
617
+                $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
618
+            } else {
619
+                $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
620
+            }
621
+            $parameters[] = $share->getSharedWith();
622
+        } else {
623
+            if ($node instanceof \OCP\Files\File) {
624
+                $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
625
+            } else {
626
+                $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
627
+            }
628
+        }
629
+
630
+        $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);
631
+
632
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
633
+            $parameters[0] = $ownerPath;
634
+            $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath);
635
+        }
636
+    }
637
+
638
+    /**
639
+     * publish activity
640
+     *
641
+     * @param string $subject
642
+     * @param array $parameters
643
+     * @param string $affectedUser
644
+     * @param int $fileId
645
+     * @param string $filePath
646
+     */
647
+    protected function publishActivity($subject,
648
+                                        array $parameters,
649
+                                        $affectedUser,
650
+                                        $fileId,
651
+                                        $filePath) {
652
+
653
+        $event = $this->activityManager->generateEvent();
654
+        $event->setApp('files_sharing')
655
+            ->setType('public_links')
656
+            ->setSubject($subject, $parameters)
657
+            ->setAffectedUser($affectedUser)
658
+            ->setObject('files', $fileId, $filePath);
659
+        $this->activityManager->publish($event);
660
+    }
662 661
 
663 662
 
664 663
 }
Please login to merge, or discard this patch.
apps/files_sharing/templates/public.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 
48 48
 <?php if (!$_['isIE']) { ?>
49 49
 	<input type="checkbox" class="hidden-visually" id="showgridview"
50
-		<?php if($_['showgridview']) { ?>checked="checked" <?php } ?>/>
50
+		<?php if ($_['showgridview']) { ?>checked="checked" <?php } ?>/>
51 51
 	<label id="view-toggle" for="showgridview" class="button <?php p($_['showgridview'] ? 'icon-toggle-filelist' : 'icon-toggle-pictures') ?>"
52 52
 		title="<?php p($l->t('Toggle grid view'))?>"></label>
53 53
 <?php } ?>
Please login to merge, or discard this patch.
apps/files/lib/Controller/ViewController.php 2 patches
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -51,266 +51,266 @@
 block discarded – undo
51 51
  * @package OCA\Files\Controller
52 52
  */
53 53
 class ViewController extends Controller {
54
-	/** @var string */
55
-	protected $appName;
56
-	/** @var IRequest */
57
-	protected $request;
58
-	/** @var IURLGenerator */
59
-	protected $urlGenerator;
60
-	/** @var IL10N */
61
-	protected $l10n;
62
-	/** @var IConfig */
63
-	protected $config;
64
-	/** @var EventDispatcherInterface */
65
-	protected $eventDispatcher;
66
-	/** @var IUserSession */
67
-	protected $userSession;
68
-	/** @var IAppManager */
69
-	protected $appManager;
70
-	/** @var IRootFolder */
71
-	protected $rootFolder;
72
-	/** @var Helper */
73
-	protected $activityHelper;
74
-
75
-	public function __construct(string $appName,
76
-		IRequest $request,
77
-		IURLGenerator $urlGenerator,
78
-		IL10N $l10n,
79
-		IConfig $config,
80
-		EventDispatcherInterface $eventDispatcherInterface,
81
-		IUserSession $userSession,
82
-		IAppManager $appManager,
83
-		IRootFolder $rootFolder,
84
-		Helper $activityHelper
85
-	) {
86
-		parent::__construct($appName, $request);
87
-		$this->appName         = $appName;
88
-		$this->request         = $request;
89
-		$this->urlGenerator    = $urlGenerator;
90
-		$this->l10n            = $l10n;
91
-		$this->config          = $config;
92
-		$this->eventDispatcher = $eventDispatcherInterface;
93
-		$this->userSession     = $userSession;
94
-		$this->appManager      = $appManager;
95
-		$this->rootFolder      = $rootFolder;
96
-		$this->activityHelper  = $activityHelper;
97
-	}
98
-
99
-	/**
100
-	 * @param string $appName
101
-	 * @param string $scriptName
102
-	 * @return string
103
-	 */
104
-	protected function renderScript($appName, $scriptName) {
105
-		$content    = '';
106
-		$appPath    = \OC_App::getAppPath($appName);
107
-		$scriptPath = $appPath . '/' . $scriptName;
108
-		if (file_exists($scriptPath)) {
109
-			// TODO: sanitize path / script name ?
110
-			ob_start();
111
-			include $scriptPath;
112
-			$content = ob_get_contents();
113
-			@ob_end_clean();
114
-		}
115
-
116
-		return $content;
117
-	}
118
-
119
-	/**
120
-	 * FIXME: Replace with non static code
121
-	 *
122
-	 * @return array
123
-	 * @throws \OCP\Files\NotFoundException
124
-	 */
125
-	protected function getStorageInfo() {
126
-		$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
127
-
128
-		return \OC_Helper::getStorageInfo('/', $dirInfo);
129
-	}
130
-
131
-	/**
132
-	 * @NoCSRFRequired
133
-	 * @NoAdminRequired
134
-	 *
135
-	 * @param string $dir
136
-	 * @param string $view
137
-	 * @param string $fileid
138
-	 * @return TemplateResponse|RedirectResponse
139
-	 */
140
-	public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
141
-		if ($fileid !== null) {
142
-			try {
143
-				return $this->showFile($fileid);
144
-			} catch (NotFoundException $e) {
145
-				return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
146
-			}
147
-		}
148
-
149
-		$nav = new \OCP\Template('files', 'appnavigation', '');
150
-
151
-		// Load the files we need
152
-		\OCP\Util::addStyle('files', 'merged');
153
-		\OCP\Util::addScript('files', 'merged-index');
154
-
155
-		// mostly for the home storage's free space
156
-		// FIXME: Make non static
157
-		$storageInfo = $this->getStorageInfo();
158
-
159
-		$user = $this->userSession->getUser()->getUID();
160
-
161
-		// Get all the user favorites to create a submenu
162
-		try {
163
-			$favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
164
-		} catch (\RuntimeException $e) {
165
-			$favElements['folders'] = [];
166
-		}
167
-
168
-		$collapseClasses = '';
169
-		if (count($favElements['folders']) > 0) {
170
-			$collapseClasses = 'collapsible';
171
-		}
172
-
173
-		$favoritesSublistArray = Array();
174
-
175
-		$navBarPositionPosition = 6;
176
-		$currentCount           = 0;
177
-		foreach ($favElements['folders'] as $dir) {
178
-
179
-			$link         = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
180
-			$sortingValue = ++$currentCount;
181
-			$element      = [
182
-				'id'                 => str_replace('/', '-', $dir),
183
-				'view'               => 'files',
184
-				'href'               => $link,
185
-				'dir'                => $dir,
186
-				'order'              => $navBarPositionPosition,
187
-				'folderPosition'     => $sortingValue,
188
-				'name'               => basename($dir),
189
-				'icon'               => 'files',
190
-				'quickaccesselement' => 'true'
191
-			];
192
-
193
-			array_push($favoritesSublistArray, $element);
194
-			$navBarPositionPosition++;
195
-		}
196
-
197
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
198
-
199
-		// add the favorites entry in menu
200
-		$navItems['favorites']['sublist'] = $favoritesSublistArray;
201
-		$navItems['favorites']['classes'] = $collapseClasses;
202
-
203
-		// parse every menu and add the expandedState user value
204
-		foreach ($navItems as $key => $item) {
205
-			if (isset($item['expandedState'])) {
206
-				$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
207
-			}
208
-		}
209
-
210
-		$nav->assign('navigationItems', $navItems);
211
-
212
-		$nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
213
-		if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
214
-			$totalSpace = $this->l10n->t('Unlimited');
215
-		} else {
216
-			$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
217
-		}
218
-		$nav->assign('total_space', $totalSpace);
219
-		$nav->assign('quota', $storageInfo['quota']);
220
-		$nav->assign('usage_relative', $storageInfo['relative']);
221
-
222
-		$contentItems = [];
223
-
224
-		// render the container content for every navigation item
225
-		foreach ($navItems as $item) {
226
-			$content = '';
227
-			if (isset($item['script'])) {
228
-				$content = $this->renderScript($item['appname'], $item['script']);
229
-			}
230
-			// parse submenus
231
-			if (isset($item['sublist'])) {
232
-				foreach ($item['sublist'] as $subitem) {
233
-					$subcontent = '';
234
-					if (isset($subitem['script'])) {
235
-						$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
236
-					}
237
-					$contentItems[$subitem['id']] = [
238
-						'id'      => $subitem['id'],
239
-						'content' => $subcontent
240
-					];
241
-				}
242
-			}
243
-			$contentItems[$item['id']] = [
244
-				'id'      => $item['id'],
245
-				'content' => $content
246
-			];
247
-		}
248
-
249
-		$event = new GenericEvent(null, ['hiddenFields' => []]);
250
-		$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
251
-
252
-		$params                                = [];
253
-		$params['usedSpacePercent']            = (int) $storageInfo['relative'];
254
-		$params['owner']                       = $storageInfo['owner'];
255
-		$params['ownerDisplayName']            = $storageInfo['ownerDisplayName'];
256
-		$params['isPublic']                    = false;
257
-		$params['allowShareWithLink']          = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
258
-		$params['defaultFileSorting']          = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
259
-		$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
260
-		$params['showgridview']				   = $this->config->getUserValue($user, 'files', 'show_grid', true);
261
-		$params['isIE']						   = \OCP\Util::isIE();
262
-		$showHidden                            = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
263
-		$params['showHiddenFiles']             = $showHidden ? 1 : 0;
264
-		$params['fileNotFound']                = $fileNotFound ? 1 : 0;
265
-		$params['appNavigation']               = $nav;
266
-		$params['appContents']                 = $contentItems;
267
-		$params['hiddenFields']                = $event->getArgument('hiddenFields');
268
-
269
-		$response = new TemplateResponse(
270
-			$this->appName,
271
-			'index',
272
-			$params
273
-		);
274
-		$policy = new ContentSecurityPolicy();
275
-		$policy->addAllowedFrameDomain('\'self\'');
276
-		$response->setContentSecurityPolicy($policy);
277
-
278
-		return $response;
279
-	}
280
-
281
-	/**
282
-	 * Redirects to the file list and highlight the given file id
283
-	 *
284
-	 * @param string $fileId file id to show
285
-	 * @return RedirectResponse redirect response or not found response
286
-	 * @throws \OCP\Files\NotFoundException
287
-	 */
288
-	private function showFile($fileId) {
289
-		$uid        = $this->userSession->getUser()->getUID();
290
-		$baseFolder = $this->rootFolder->getUserFolder($uid);
291
-		$files      = $baseFolder->getById($fileId);
292
-		$params     = [];
293
-
294
-		if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
295
-			$baseFolder     = $this->rootFolder->get($uid . '/files_trashbin/files/');
296
-			$files          = $baseFolder->getById($fileId);
297
-			$params['view'] = 'trashbin';
298
-		}
299
-
300
-		if (!empty($files)) {
301
-			$file = current($files);
302
-			if ($file instanceof Folder) {
303
-				// set the full path to enter the folder
304
-				$params['dir'] = $baseFolder->getRelativePath($file->getPath());
305
-			} else {
306
-				// set parent path as dir
307
-				$params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
308
-				// and scroll to the entry
309
-				$params['scrollto'] = $file->getName();
310
-			}
311
-
312
-			return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
313
-		}
314
-		throw new \OCP\Files\NotFoundException();
315
-	}
54
+    /** @var string */
55
+    protected $appName;
56
+    /** @var IRequest */
57
+    protected $request;
58
+    /** @var IURLGenerator */
59
+    protected $urlGenerator;
60
+    /** @var IL10N */
61
+    protected $l10n;
62
+    /** @var IConfig */
63
+    protected $config;
64
+    /** @var EventDispatcherInterface */
65
+    protected $eventDispatcher;
66
+    /** @var IUserSession */
67
+    protected $userSession;
68
+    /** @var IAppManager */
69
+    protected $appManager;
70
+    /** @var IRootFolder */
71
+    protected $rootFolder;
72
+    /** @var Helper */
73
+    protected $activityHelper;
74
+
75
+    public function __construct(string $appName,
76
+        IRequest $request,
77
+        IURLGenerator $urlGenerator,
78
+        IL10N $l10n,
79
+        IConfig $config,
80
+        EventDispatcherInterface $eventDispatcherInterface,
81
+        IUserSession $userSession,
82
+        IAppManager $appManager,
83
+        IRootFolder $rootFolder,
84
+        Helper $activityHelper
85
+    ) {
86
+        parent::__construct($appName, $request);
87
+        $this->appName         = $appName;
88
+        $this->request         = $request;
89
+        $this->urlGenerator    = $urlGenerator;
90
+        $this->l10n            = $l10n;
91
+        $this->config          = $config;
92
+        $this->eventDispatcher = $eventDispatcherInterface;
93
+        $this->userSession     = $userSession;
94
+        $this->appManager      = $appManager;
95
+        $this->rootFolder      = $rootFolder;
96
+        $this->activityHelper  = $activityHelper;
97
+    }
98
+
99
+    /**
100
+     * @param string $appName
101
+     * @param string $scriptName
102
+     * @return string
103
+     */
104
+    protected function renderScript($appName, $scriptName) {
105
+        $content    = '';
106
+        $appPath    = \OC_App::getAppPath($appName);
107
+        $scriptPath = $appPath . '/' . $scriptName;
108
+        if (file_exists($scriptPath)) {
109
+            // TODO: sanitize path / script name ?
110
+            ob_start();
111
+            include $scriptPath;
112
+            $content = ob_get_contents();
113
+            @ob_end_clean();
114
+        }
115
+
116
+        return $content;
117
+    }
118
+
119
+    /**
120
+     * FIXME: Replace with non static code
121
+     *
122
+     * @return array
123
+     * @throws \OCP\Files\NotFoundException
124
+     */
125
+    protected function getStorageInfo() {
126
+        $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
127
+
128
+        return \OC_Helper::getStorageInfo('/', $dirInfo);
129
+    }
130
+
131
+    /**
132
+     * @NoCSRFRequired
133
+     * @NoAdminRequired
134
+     *
135
+     * @param string $dir
136
+     * @param string $view
137
+     * @param string $fileid
138
+     * @return TemplateResponse|RedirectResponse
139
+     */
140
+    public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
141
+        if ($fileid !== null) {
142
+            try {
143
+                return $this->showFile($fileid);
144
+            } catch (NotFoundException $e) {
145
+                return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
146
+            }
147
+        }
148
+
149
+        $nav = new \OCP\Template('files', 'appnavigation', '');
150
+
151
+        // Load the files we need
152
+        \OCP\Util::addStyle('files', 'merged');
153
+        \OCP\Util::addScript('files', 'merged-index');
154
+
155
+        // mostly for the home storage's free space
156
+        // FIXME: Make non static
157
+        $storageInfo = $this->getStorageInfo();
158
+
159
+        $user = $this->userSession->getUser()->getUID();
160
+
161
+        // Get all the user favorites to create a submenu
162
+        try {
163
+            $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
164
+        } catch (\RuntimeException $e) {
165
+            $favElements['folders'] = [];
166
+        }
167
+
168
+        $collapseClasses = '';
169
+        if (count($favElements['folders']) > 0) {
170
+            $collapseClasses = 'collapsible';
171
+        }
172
+
173
+        $favoritesSublistArray = Array();
174
+
175
+        $navBarPositionPosition = 6;
176
+        $currentCount           = 0;
177
+        foreach ($favElements['folders'] as $dir) {
178
+
179
+            $link         = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
180
+            $sortingValue = ++$currentCount;
181
+            $element      = [
182
+                'id'                 => str_replace('/', '-', $dir),
183
+                'view'               => 'files',
184
+                'href'               => $link,
185
+                'dir'                => $dir,
186
+                'order'              => $navBarPositionPosition,
187
+                'folderPosition'     => $sortingValue,
188
+                'name'               => basename($dir),
189
+                'icon'               => 'files',
190
+                'quickaccesselement' => 'true'
191
+            ];
192
+
193
+            array_push($favoritesSublistArray, $element);
194
+            $navBarPositionPosition++;
195
+        }
196
+
197
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
198
+
199
+        // add the favorites entry in menu
200
+        $navItems['favorites']['sublist'] = $favoritesSublistArray;
201
+        $navItems['favorites']['classes'] = $collapseClasses;
202
+
203
+        // parse every menu and add the expandedState user value
204
+        foreach ($navItems as $key => $item) {
205
+            if (isset($item['expandedState'])) {
206
+                $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
207
+            }
208
+        }
209
+
210
+        $nav->assign('navigationItems', $navItems);
211
+
212
+        $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
213
+        if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
214
+            $totalSpace = $this->l10n->t('Unlimited');
215
+        } else {
216
+            $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
217
+        }
218
+        $nav->assign('total_space', $totalSpace);
219
+        $nav->assign('quota', $storageInfo['quota']);
220
+        $nav->assign('usage_relative', $storageInfo['relative']);
221
+
222
+        $contentItems = [];
223
+
224
+        // render the container content for every navigation item
225
+        foreach ($navItems as $item) {
226
+            $content = '';
227
+            if (isset($item['script'])) {
228
+                $content = $this->renderScript($item['appname'], $item['script']);
229
+            }
230
+            // parse submenus
231
+            if (isset($item['sublist'])) {
232
+                foreach ($item['sublist'] as $subitem) {
233
+                    $subcontent = '';
234
+                    if (isset($subitem['script'])) {
235
+                        $subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
236
+                    }
237
+                    $contentItems[$subitem['id']] = [
238
+                        'id'      => $subitem['id'],
239
+                        'content' => $subcontent
240
+                    ];
241
+                }
242
+            }
243
+            $contentItems[$item['id']] = [
244
+                'id'      => $item['id'],
245
+                'content' => $content
246
+            ];
247
+        }
248
+
249
+        $event = new GenericEvent(null, ['hiddenFields' => []]);
250
+        $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
251
+
252
+        $params                                = [];
253
+        $params['usedSpacePercent']            = (int) $storageInfo['relative'];
254
+        $params['owner']                       = $storageInfo['owner'];
255
+        $params['ownerDisplayName']            = $storageInfo['ownerDisplayName'];
256
+        $params['isPublic']                    = false;
257
+        $params['allowShareWithLink']          = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
258
+        $params['defaultFileSorting']          = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
259
+        $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
260
+        $params['showgridview']				   = $this->config->getUserValue($user, 'files', 'show_grid', true);
261
+        $params['isIE']						   = \OCP\Util::isIE();
262
+        $showHidden                            = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
263
+        $params['showHiddenFiles']             = $showHidden ? 1 : 0;
264
+        $params['fileNotFound']                = $fileNotFound ? 1 : 0;
265
+        $params['appNavigation']               = $nav;
266
+        $params['appContents']                 = $contentItems;
267
+        $params['hiddenFields']                = $event->getArgument('hiddenFields');
268
+
269
+        $response = new TemplateResponse(
270
+            $this->appName,
271
+            'index',
272
+            $params
273
+        );
274
+        $policy = new ContentSecurityPolicy();
275
+        $policy->addAllowedFrameDomain('\'self\'');
276
+        $response->setContentSecurityPolicy($policy);
277
+
278
+        return $response;
279
+    }
280
+
281
+    /**
282
+     * Redirects to the file list and highlight the given file id
283
+     *
284
+     * @param string $fileId file id to show
285
+     * @return RedirectResponse redirect response or not found response
286
+     * @throws \OCP\Files\NotFoundException
287
+     */
288
+    private function showFile($fileId) {
289
+        $uid        = $this->userSession->getUser()->getUID();
290
+        $baseFolder = $this->rootFolder->getUserFolder($uid);
291
+        $files      = $baseFolder->getById($fileId);
292
+        $params     = [];
293
+
294
+        if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
295
+            $baseFolder     = $this->rootFolder->get($uid . '/files_trashbin/files/');
296
+            $files          = $baseFolder->getById($fileId);
297
+            $params['view'] = 'trashbin';
298
+        }
299
+
300
+        if (!empty($files)) {
301
+            $file = current($files);
302
+            if ($file instanceof Folder) {
303
+                // set the full path to enter the folder
304
+                $params['dir'] = $baseFolder->getRelativePath($file->getPath());
305
+            } else {
306
+                // set parent path as dir
307
+                $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
308
+                // and scroll to the entry
309
+                $params['scrollto'] = $file->getName();
310
+            }
311
+
312
+            return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
313
+        }
314
+        throw new \OCP\Files\NotFoundException();
315
+    }
316 316
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	protected function renderScript($appName, $scriptName) {
105 105
 		$content    = '';
106 106
 		$appPath    = \OC_App::getAppPath($appName);
107
-		$scriptPath = $appPath . '/' . $scriptName;
107
+		$scriptPath = $appPath.'/'.$scriptName;
108 108
 		if (file_exists($scriptPath)) {
109 109
 			// TODO: sanitize path / script name ?
110 110
 			ob_start();
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 		$params['allowShareWithLink']          = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
258 258
 		$params['defaultFileSorting']          = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
259 259
 		$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
260
-		$params['showgridview']				   = $this->config->getUserValue($user, 'files', 'show_grid', true);
261
-		$params['isIE']						   = \OCP\Util::isIE();
260
+		$params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', true);
261
+		$params['isIE'] = \OCP\Util::isIE();
262 262
 		$showHidden                            = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
263 263
 		$params['showHiddenFiles']             = $showHidden ? 1 : 0;
264 264
 		$params['fileNotFound']                = $fileNotFound ? 1 : 0;
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		$params     = [];
293 293
 
294 294
 		if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
295
-			$baseFolder     = $this->rootFolder->get($uid . '/files_trashbin/files/');
295
+			$baseFolder     = $this->rootFolder->get($uid.'/files_trashbin/files/');
296 296
 			$files          = $baseFolder->getById($fileId);
297 297
 			$params['view'] = 'trashbin';
298 298
 		}
Please login to merge, or discard this patch.
apps/files/templates/index.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 	<?php if (!$_['isIE']) { ?>
6 6
 		<input type="checkbox" class="hidden-visually" id="showgridview"
7
-			<?php if($_['showgridview']) { ?>checked="checked" <?php } ?>/>
7
+			<?php if ($_['showgridview']) { ?>checked="checked" <?php } ?>/>
8 8
 		<label id="view-toggle" for="showgridview" class="button <?php p($_['showgridview'] ? 'icon-toggle-filelist' : 'icon-toggle-pictures') ?>"
9 9
 			title="<?php p($l->t('Toggle grid view'))?>"></label>
10 10
 	<?php } ?>
Please login to merge, or discard this patch.