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