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