Completed
Pull Request — master (#4303)
by Björn
11:34 queued 20s
created
apps/sharebymail/lib/ShareByMailProvider.php 3 patches
Doc Comments   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	 * publish activity if a file/folder was shared by mail
238 238
 	 *
239 239
 	 * @param $subject
240
-	 * @param $parameters
241
-	 * @param $affectedUser
240
+	 * @param string[] $parameters
241
+	 * @param string $affectedUser
242 242
 	 * @param $fileId
243
-	 * @param $filePath
243
+	 * @param string $filePath
244 244
 	 */
245 245
 	protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
246 246
 		$event = $this->activityManager->generateEvent();
@@ -293,6 +293,12 @@  discard block
 block discarded – undo
293 293
 
294 294
 	}
295 295
 
296
+	/**
297
+	 * @param string $link
298
+	 * @param string $owner
299
+	 * @param string $initiator
300
+	 * @param string $shareWith
301
+	 */
296 302
 	protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
297 303
 		$ownerUser = $this->userManager->get($owner);
298 304
 		$initiatorUser = $this->userManager->get($initiator);
@@ -326,6 +332,7 @@  discard block
 block discarded – undo
326 332
 	 * @param $link
327 333
 	 * @param $owner
328 334
 	 * @param $initiator
335
+	 * @param string $template
329 336
 	 * @return string plain text mail
330 337
 	 * @throws HintException
331 338
 	 */
@@ -497,6 +504,7 @@  discard block
 block discarded – undo
497 504
 	 * @param string $uidOwner
498 505
 	 * @param int $permissions
499 506
 	 * @param string $token
507
+	 * @param string $password
500 508
 	 * @return int
501 509
 	 */
502 510
 	protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) {
@@ -890,7 +898,7 @@  discard block
 block discarded – undo
890 898
 	/**
891 899
 	 * get database row of a give share
892 900
 	 *
893
-	 * @param $id
901
+	 * @param integer $id
894 902
 	 * @return array
895 903
 	 * @throws ShareNotFound
896 904
 	 */
Please login to merge, or discard this patch.
Indentation   +889 added lines, -889 removed lines patch added patch discarded remove patch
@@ -51,907 +51,907 @@
 block discarded – undo
51 51
  */
52 52
 class ShareByMailProvider implements IShareProvider {
53 53
 
54
-	/** @var  IDBConnection */
55
-	private $dbConnection;
56
-
57
-	/** @var ILogger */
58
-	private $logger;
59
-
60
-	/** @var ISecureRandom */
61
-	private $secureRandom;
62
-
63
-	/** @var IUserManager */
64
-	private $userManager;
65
-
66
-	/** @var IRootFolder */
67
-	private $rootFolder;
68
-
69
-	/** @var IL10N */
70
-	private $l;
71
-
72
-	/** @var IMailer */
73
-	private $mailer;
74
-
75
-	/** @var IURLGenerator */
76
-	private $urlGenerator;
77
-
78
-	/** @var IManager  */
79
-	private $activityManager;
80
-
81
-	/** @var SettingsManager */
82
-	private $settingsManager;
83
-
84
-	/** @var IHasher */
85
-	private $hasher;
86
-
87
-	/**
88
-	 * Return the identifier of this provider.
89
-	 *
90
-	 * @return string Containing only [a-zA-Z0-9]
91
-	 */
92
-	public function identifier() {
93
-		return 'ocMailShare';
94
-	}
95
-
96
-	/**
97
-	 * DefaultShareProvider constructor.
98
-	 *
99
-	 * @param IDBConnection $connection
100
-	 * @param ISecureRandom $secureRandom
101
-	 * @param IUserManager $userManager
102
-	 * @param IRootFolder $rootFolder
103
-	 * @param IL10N $l
104
-	 * @param ILogger $logger
105
-	 * @param IMailer $mailer
106
-	 * @param IURLGenerator $urlGenerator
107
-	 * @param IManager $activityManager
108
-	 * @param SettingsManager $settingsManager
109
-	 * @param IHasher $hasher
110
-	 */
111
-	public function __construct(
112
-		IDBConnection $connection,
113
-		ISecureRandom $secureRandom,
114
-		IUserManager $userManager,
115
-		IRootFolder $rootFolder,
116
-		IL10N $l,
117
-		ILogger $logger,
118
-		IMailer $mailer,
119
-		IURLGenerator $urlGenerator,
120
-		IManager $activityManager,
121
-		SettingsManager $settingsManager,
122
-		IHasher $hasher
123
-	) {
124
-		$this->dbConnection = $connection;
125
-		$this->secureRandom = $secureRandom;
126
-		$this->userManager = $userManager;
127
-		$this->rootFolder = $rootFolder;
128
-		$this->l = $l;
129
-		$this->logger = $logger;
130
-		$this->mailer = $mailer;
131
-		$this->urlGenerator = $urlGenerator;
132
-		$this->activityManager = $activityManager;
133
-		$this->settingsManager = $settingsManager;
134
-		$this->hasher = $hasher;
135
-	}
136
-
137
-	/**
138
-	 * Share a path
139
-	 *
140
-	 * @param IShare $share
141
-	 * @return IShare The share object
142
-	 * @throws ShareNotFound
143
-	 * @throws \Exception
144
-	 */
145
-	public function create(IShare $share) {
146
-
147
-		$shareWith = $share->getSharedWith();
148
-		/*
54
+    /** @var  IDBConnection */
55
+    private $dbConnection;
56
+
57
+    /** @var ILogger */
58
+    private $logger;
59
+
60
+    /** @var ISecureRandom */
61
+    private $secureRandom;
62
+
63
+    /** @var IUserManager */
64
+    private $userManager;
65
+
66
+    /** @var IRootFolder */
67
+    private $rootFolder;
68
+
69
+    /** @var IL10N */
70
+    private $l;
71
+
72
+    /** @var IMailer */
73
+    private $mailer;
74
+
75
+    /** @var IURLGenerator */
76
+    private $urlGenerator;
77
+
78
+    /** @var IManager  */
79
+    private $activityManager;
80
+
81
+    /** @var SettingsManager */
82
+    private $settingsManager;
83
+
84
+    /** @var IHasher */
85
+    private $hasher;
86
+
87
+    /**
88
+     * Return the identifier of this provider.
89
+     *
90
+     * @return string Containing only [a-zA-Z0-9]
91
+     */
92
+    public function identifier() {
93
+        return 'ocMailShare';
94
+    }
95
+
96
+    /**
97
+     * DefaultShareProvider constructor.
98
+     *
99
+     * @param IDBConnection $connection
100
+     * @param ISecureRandom $secureRandom
101
+     * @param IUserManager $userManager
102
+     * @param IRootFolder $rootFolder
103
+     * @param IL10N $l
104
+     * @param ILogger $logger
105
+     * @param IMailer $mailer
106
+     * @param IURLGenerator $urlGenerator
107
+     * @param IManager $activityManager
108
+     * @param SettingsManager $settingsManager
109
+     * @param IHasher $hasher
110
+     */
111
+    public function __construct(
112
+        IDBConnection $connection,
113
+        ISecureRandom $secureRandom,
114
+        IUserManager $userManager,
115
+        IRootFolder $rootFolder,
116
+        IL10N $l,
117
+        ILogger $logger,
118
+        IMailer $mailer,
119
+        IURLGenerator $urlGenerator,
120
+        IManager $activityManager,
121
+        SettingsManager $settingsManager,
122
+        IHasher $hasher
123
+    ) {
124
+        $this->dbConnection = $connection;
125
+        $this->secureRandom = $secureRandom;
126
+        $this->userManager = $userManager;
127
+        $this->rootFolder = $rootFolder;
128
+        $this->l = $l;
129
+        $this->logger = $logger;
130
+        $this->mailer = $mailer;
131
+        $this->urlGenerator = $urlGenerator;
132
+        $this->activityManager = $activityManager;
133
+        $this->settingsManager = $settingsManager;
134
+        $this->hasher = $hasher;
135
+    }
136
+
137
+    /**
138
+     * Share a path
139
+     *
140
+     * @param IShare $share
141
+     * @return IShare The share object
142
+     * @throws ShareNotFound
143
+     * @throws \Exception
144
+     */
145
+    public function create(IShare $share) {
146
+
147
+        $shareWith = $share->getSharedWith();
148
+        /*
149 149
 		 * Check if file is not already shared with the remote user
150 150
 		 */
151
-		$alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0);
152
-		if (!empty($alreadyShared)) {
153
-			$message = 'Sharing %s failed, this item is already shared with %s';
154
-			$message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
155
-			$this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
156
-			throw new \Exception($message_t);
157
-		}
158
-
159
-		// if the admin enforces a password for all mail shares we create a
160
-		// random password and send it to the recipient
161
-		$password = '';
162
-		$passwordEnforced = $this->settingsManager->enforcePasswordProtection();
163
-		$allowPasswordByMail = $this->settingsManager->sendPasswordByMail();
164
-		if ($passwordEnforced) {
165
-			$password = $this->generateToken(8);
166
-			$share->setPassword($this->hasher->hash($password));
167
-			$initiatorUser = $this->userManager->get($share->getSharedBy());
168
-			$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
169
-		}
170
-
171
-		if ($passwordEnforced && $initiatorEMailAddress === null && !$allowPasswordByMail) {
172
-			throw new \Exception(
173
-				$this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
174
-			);
175
-		}
176
-
177
-		$shareId = $this->createMailShare($share);
178
-		$send = $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $password);
179
-		if ($passwordEnforced && $send === false) {
180
-			$this->sendPasswordToOwner($share->getNode()->getName(), $share->getSharedBy(), $shareWith, $password);
181
-		}
182
-		$this->createActivity($share);
183
-		$data = $this->getRawShare($shareId);
184
-
185
-		return $this->createShareObject($data);
186
-
187
-	}
188
-
189
-	/**
190
-	 * auto generate password in case of password enforcement on mail shares
191
-	 *
192
-	 * @return string
193
-	 */
194
-	protected function autoGeneratePassword() {
195
-		$password = '';
196
-		if ($this->settingsManager->enforcePasswordProtection()) {
197
-			$password = $this->generateToken(8);
198
-		}
199
-
200
-		return $password;
201
-	}
202
-
203
-	/**
204
-	 * create activity if a file/folder was shared by mail
205
-	 *
206
-	 * @param IShare $share
207
-	 */
208
-	protected function createActivity(IShare $share) {
209
-
210
-		$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
211
-
212
-		$this->publishActivity(
213
-			Activity::SUBJECT_SHARED_EMAIL_SELF,
214
-			[$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
215
-			$share->getSharedBy(),
216
-			$share->getNode()->getId(),
217
-			$userFolder->getRelativePath($share->getNode()->getPath())
218
-		);
219
-
220
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
221
-			$ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
222
-			$fileId = $share->getNode()->getId();
223
-			$nodes = $ownerFolder->getById($fileId);
224
-			$ownerPath = $nodes[0]->getPath();
225
-			$this->publishActivity(
226
-				Activity::SUBJECT_SHARED_EMAIL_BY,
227
-				[$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
228
-				$share->getShareOwner(),
229
-				$fileId,
230
-				$ownerFolder->getRelativePath($ownerPath)
231
-			);
232
-		}
233
-
234
-	}
235
-
236
-	/**
237
-	 * publish activity if a file/folder was shared by mail
238
-	 *
239
-	 * @param $subject
240
-	 * @param $parameters
241
-	 * @param $affectedUser
242
-	 * @param $fileId
243
-	 * @param $filePath
244
-	 */
245
-	protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
246
-		$event = $this->activityManager->generateEvent();
247
-		$event->setApp('sharebymail')
248
-			->setType('shared')
249
-			->setSubject($subject, $parameters)
250
-			->setAffectedUser($affectedUser)
251
-			->setObject('files', $fileId, $filePath);
252
-		$this->activityManager->publish($event);
253
-
254
-	}
255
-
256
-	/**
257
-	 * @param IShare $share
258
-	 * @return int
259
-	 * @throws \Exception
260
-	 */
261
-	protected function createMailShare(IShare $share) {
262
-		$share->setToken($this->generateToken());
263
-		$shareId = $this->addShareToDB(
264
-			$share->getNodeId(),
265
-			$share->getNodeType(),
266
-			$share->getSharedWith(),
267
-			$share->getSharedBy(),
268
-			$share->getShareOwner(),
269
-			$share->getPermissions(),
270
-			$share->getToken(),
271
-			$share->getPassword()
272
-		);
273
-
274
-		try {
275
-			$link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
276
-				['token' => $share->getToken()]);
277
-			$this->sendMailNotification($share->getNode()->getName(),
278
-				$link,
279
-				$share->getShareOwner(),
280
-				$share->getSharedBy(), $share->getSharedWith());
281
-		} catch (HintException $hintException) {
282
-			$this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
283
-			$this->removeShareFromTable($shareId);
284
-			throw $hintException;
285
-		} catch (\Exception $e) {
286
-			$this->logger->error('Failed to send share by mail: ' . $e->getMessage());
287
-			$this->removeShareFromTable($shareId);
288
-			throw new HintException('Failed to send share by mail',
289
-				$this->l->t('Failed to send share by E-mail'));
290
-		}
291
-
292
-		return $shareId;
293
-
294
-	}
295
-
296
-	protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
297
-		$ownerUser = $this->userManager->get($owner);
298
-		$initiatorUser = $this->userManager->get($initiator);
299
-		$ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner;
300
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
301
-		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
302
-		if ($owner === $initiator) {
303
-			$subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
304
-		} else {
305
-			$subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
306
-		}
307
-
308
-		$message = $this->mailer->createMessage();
309
-		$htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
310
-		$textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
311
-		$message->setTo([$shareWith]);
312
-		if ($initiatorEmailAddress) {
313
-			$message->setFrom([$initiatorEmailAddress]);
314
-		}
315
-		$message->setSubject($subject);
316
-		$message->setBody($textBody, 'text/plain');
317
-		$message->setHtmlBody($htmlBody);
318
-		$this->mailer->send($message);
319
-
320
-	}
321
-
322
-	/**
323
-	 * create mail body
324
-	 *
325
-	 * @param $filename
326
-	 * @param $link
327
-	 * @param $owner
328
-	 * @param $initiator
329
-	 * @return string plain text mail
330
-	 * @throws HintException
331
-	 */
332
-	protected function createMailBody($template, $filename, $link, $owner, $initiator) {
333
-
334
-		$mailBodyTemplate = new Template('sharebymail', $template, '');
335
-		$mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename));
336
-		$mailBodyTemplate->assign ('link', $link);
337
-		$mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner));
338
-		$mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator));
339
-		$mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
340
-		$mailBody = $mailBodyTemplate->fetchPage();
341
-
342
-		if (is_string($mailBody)) {
343
-			return $mailBody;
344
-		}
345
-
346
-		throw new HintException('Failed to create the E-mail',
347
-			$this->l->t('Failed to create the E-mail'));
348
-	}
349
-
350
-	/**
351
-	 * send password to recipient of a mail share
352
-	 *
353
-	 * @param string $filename
354
-	 * @param string $initiator
355
-	 * @param string $shareWith
356
-	 * @param string $password
357
-	 * @return bool
358
-	 */
359
-	protected function sendPassword($filename, $initiator, $shareWith, $password) {
360
-
361
-		if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) {
362
-			return false;
363
-		}
364
-
365
-		$initiatorUser = $this->userManager->get($initiator);
366
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
367
-		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
368
-		$subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
369
-
370
-		$message = $this->mailer->createMessage();
371
-		$arguments = ['filename' => $filename, 'initiator' => $initiator, 'password' => $password];
372
-		$htmlBody = $this->createMailBodyToSendPassword('mailpassword', $arguments);
373
-		$textBody = $this->createMailBodyToSendPassword('altmailpassword', $arguments);
374
-		$message->setTo([$shareWith]);
375
-		if ($initiatorEmailAddress) {
376
-			$message->setFrom([$initiatorEmailAddress]);
377
-		}
378
-		$message->setSubject($subject);
379
-		$message->setBody($textBody, 'text/plain');
380
-		$message->setHtmlBody($htmlBody);
381
-		$this->mailer->send($message);
382
-
383
-		return true;
384
-	}
385
-
386
-	/**
387
-	 * send auto generated password to the owner. This happens if the admin enforces
388
-	 * a password for mail shares and forbid to send the password by mail to the recipient
389
-	 *
390
-	 * @param string $filename
391
-	 * @param string $initiator
392
-	 * @param string $shareWith
393
-	 * @param string $password
394
-	 * @throws \Exception
395
-	 */
396
-	protected function sendPasswordToOwner($filename, $initiator, $shareWith, $password) {
397
-
398
-		$initiatorUser = $this->userManager->get($initiator);
399
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
400
-		$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
401
-		$initiatorFullMail = $initiatorDisplayName . '<' . $initiatorEMailAddress . '>';
402
-
403
-		if ($initiatorEMailAddress === null) {
404
-			throw new \Exception(
405
-				$this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
406
-			);
407
-		}
408
-
409
-		$subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
410
-
411
-		$message = $this->mailer->createMessage();
412
-		$arguments = ['filename' => $filename, 'recipient' => $shareWith, 'password' => $password];
413
-		$htmlBody = $this->createMailBodyToSendPassword('mailpasswordowner', $arguments);
414
-		$textBody = $this->createMailBodyToSendPassword('altmailpasswordowner', $arguments);
415
-		if ($initiatorEMailAddress) {
416
-			$message->setFrom([$initiatorUser->getEMailAddress()]);
417
-		}
418
-		$message->setTo([$initiatorEMailAddress]);
419
-		$message->setFrom([$initiatorEMailAddress]);
420
-		$message->setSubject($subject);
421
-		$message->setBody($textBody, 'text/plain');
422
-		$message->setHtmlBody($htmlBody);
423
-		$this->mailer->send($message);
424
-
425
-	}
426
-
427
-	/**
428
-	 * create mail body to send password to recipient
429
-	 *
430
-	 * @param string $template
431
-	 * @param array $arguments
432
-	 * @return string plain text mail
433
-	 * @throws HintException
434
-	 */
435
-	protected function createMailBodyToSendPassword($template, array $arguments) {
436
-
437
-		$mailBodyTemplate = new Template('sharebymail', $template, '');
438
-
439
-		foreach ($arguments as $key => $value) {
440
-			$mailBodyTemplate->assign ($key, \OCP\Util::sanitizeHTML($value));
441
-		}
442
-
443
-		$mailBody = $mailBodyTemplate->fetchPage();
444
-
445
-		if (is_string($mailBody)) {
446
-			return $mailBody;
447
-		}
448
-
449
-		throw new HintException('Failed to create the E-mail',
450
-			$this->l->t('Failed to create the E-mail'));
451
-	}
452
-
453
-
454
-	/**
455
-	 * generate share token
456
-	 *
457
-	 * @return string
458
-	 */
459
-	protected function generateToken($size = 15) {
460
-		$token = $this->secureRandom->generate(
461
-			$size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
462
-		return $token;
463
-	}
464
-
465
-	/**
466
-	 * Get all children of this share
467
-	 *
468
-	 * @param IShare $parent
469
-	 * @return IShare[]
470
-	 */
471
-	public function getChildren(IShare $parent) {
472
-		$children = [];
473
-
474
-		$qb = $this->dbConnection->getQueryBuilder();
475
-		$qb->select('*')
476
-			->from('share')
477
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
478
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
479
-			->orderBy('id');
480
-
481
-		$cursor = $qb->execute();
482
-		while($data = $cursor->fetch()) {
483
-			$children[] = $this->createShareObject($data);
484
-		}
485
-		$cursor->closeCursor();
486
-
487
-		return $children;
488
-	}
489
-
490
-	/**
491
-	 * add share to the database and return the ID
492
-	 *
493
-	 * @param int $itemSource
494
-	 * @param string $itemType
495
-	 * @param string $shareWith
496
-	 * @param string $sharedBy
497
-	 * @param string $uidOwner
498
-	 * @param int $permissions
499
-	 * @param string $token
500
-	 * @return int
501
-	 */
502
-	protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) {
503
-		$qb = $this->dbConnection->getQueryBuilder();
504
-		$qb->insert('share')
505
-			->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
506
-			->setValue('item_type', $qb->createNamedParameter($itemType))
507
-			->setValue('item_source', $qb->createNamedParameter($itemSource))
508
-			->setValue('file_source', $qb->createNamedParameter($itemSource))
509
-			->setValue('share_with', $qb->createNamedParameter($shareWith))
510
-			->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
511
-			->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
512
-			->setValue('permissions', $qb->createNamedParameter($permissions))
513
-			->setValue('token', $qb->createNamedParameter($token))
514
-			->setValue('password', $qb->createNamedParameter($password))
515
-			->setValue('stime', $qb->createNamedParameter(time()));
516
-
517
-		/*
151
+        $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0);
152
+        if (!empty($alreadyShared)) {
153
+            $message = 'Sharing %s failed, this item is already shared with %s';
154
+            $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
155
+            $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
156
+            throw new \Exception($message_t);
157
+        }
158
+
159
+        // if the admin enforces a password for all mail shares we create a
160
+        // random password and send it to the recipient
161
+        $password = '';
162
+        $passwordEnforced = $this->settingsManager->enforcePasswordProtection();
163
+        $allowPasswordByMail = $this->settingsManager->sendPasswordByMail();
164
+        if ($passwordEnforced) {
165
+            $password = $this->generateToken(8);
166
+            $share->setPassword($this->hasher->hash($password));
167
+            $initiatorUser = $this->userManager->get($share->getSharedBy());
168
+            $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
169
+        }
170
+
171
+        if ($passwordEnforced && $initiatorEMailAddress === null && !$allowPasswordByMail) {
172
+            throw new \Exception(
173
+                $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
174
+            );
175
+        }
176
+
177
+        $shareId = $this->createMailShare($share);
178
+        $send = $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $password);
179
+        if ($passwordEnforced && $send === false) {
180
+            $this->sendPasswordToOwner($share->getNode()->getName(), $share->getSharedBy(), $shareWith, $password);
181
+        }
182
+        $this->createActivity($share);
183
+        $data = $this->getRawShare($shareId);
184
+
185
+        return $this->createShareObject($data);
186
+
187
+    }
188
+
189
+    /**
190
+     * auto generate password in case of password enforcement on mail shares
191
+     *
192
+     * @return string
193
+     */
194
+    protected function autoGeneratePassword() {
195
+        $password = '';
196
+        if ($this->settingsManager->enforcePasswordProtection()) {
197
+            $password = $this->generateToken(8);
198
+        }
199
+
200
+        return $password;
201
+    }
202
+
203
+    /**
204
+     * create activity if a file/folder was shared by mail
205
+     *
206
+     * @param IShare $share
207
+     */
208
+    protected function createActivity(IShare $share) {
209
+
210
+        $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
211
+
212
+        $this->publishActivity(
213
+            Activity::SUBJECT_SHARED_EMAIL_SELF,
214
+            [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
215
+            $share->getSharedBy(),
216
+            $share->getNode()->getId(),
217
+            $userFolder->getRelativePath($share->getNode()->getPath())
218
+        );
219
+
220
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
221
+            $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
222
+            $fileId = $share->getNode()->getId();
223
+            $nodes = $ownerFolder->getById($fileId);
224
+            $ownerPath = $nodes[0]->getPath();
225
+            $this->publishActivity(
226
+                Activity::SUBJECT_SHARED_EMAIL_BY,
227
+                [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
228
+                $share->getShareOwner(),
229
+                $fileId,
230
+                $ownerFolder->getRelativePath($ownerPath)
231
+            );
232
+        }
233
+
234
+    }
235
+
236
+    /**
237
+     * publish activity if a file/folder was shared by mail
238
+     *
239
+     * @param $subject
240
+     * @param $parameters
241
+     * @param $affectedUser
242
+     * @param $fileId
243
+     * @param $filePath
244
+     */
245
+    protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
246
+        $event = $this->activityManager->generateEvent();
247
+        $event->setApp('sharebymail')
248
+            ->setType('shared')
249
+            ->setSubject($subject, $parameters)
250
+            ->setAffectedUser($affectedUser)
251
+            ->setObject('files', $fileId, $filePath);
252
+        $this->activityManager->publish($event);
253
+
254
+    }
255
+
256
+    /**
257
+     * @param IShare $share
258
+     * @return int
259
+     * @throws \Exception
260
+     */
261
+    protected function createMailShare(IShare $share) {
262
+        $share->setToken($this->generateToken());
263
+        $shareId = $this->addShareToDB(
264
+            $share->getNodeId(),
265
+            $share->getNodeType(),
266
+            $share->getSharedWith(),
267
+            $share->getSharedBy(),
268
+            $share->getShareOwner(),
269
+            $share->getPermissions(),
270
+            $share->getToken(),
271
+            $share->getPassword()
272
+        );
273
+
274
+        try {
275
+            $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
276
+                ['token' => $share->getToken()]);
277
+            $this->sendMailNotification($share->getNode()->getName(),
278
+                $link,
279
+                $share->getShareOwner(),
280
+                $share->getSharedBy(), $share->getSharedWith());
281
+        } catch (HintException $hintException) {
282
+            $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
283
+            $this->removeShareFromTable($shareId);
284
+            throw $hintException;
285
+        } catch (\Exception $e) {
286
+            $this->logger->error('Failed to send share by mail: ' . $e->getMessage());
287
+            $this->removeShareFromTable($shareId);
288
+            throw new HintException('Failed to send share by mail',
289
+                $this->l->t('Failed to send share by E-mail'));
290
+        }
291
+
292
+        return $shareId;
293
+
294
+    }
295
+
296
+    protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
297
+        $ownerUser = $this->userManager->get($owner);
298
+        $initiatorUser = $this->userManager->get($initiator);
299
+        $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner;
300
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
301
+        $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
302
+        if ($owner === $initiator) {
303
+            $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
304
+        } else {
305
+            $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
306
+        }
307
+
308
+        $message = $this->mailer->createMessage();
309
+        $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
310
+        $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
311
+        $message->setTo([$shareWith]);
312
+        if ($initiatorEmailAddress) {
313
+            $message->setFrom([$initiatorEmailAddress]);
314
+        }
315
+        $message->setSubject($subject);
316
+        $message->setBody($textBody, 'text/plain');
317
+        $message->setHtmlBody($htmlBody);
318
+        $this->mailer->send($message);
319
+
320
+    }
321
+
322
+    /**
323
+     * create mail body
324
+     *
325
+     * @param $filename
326
+     * @param $link
327
+     * @param $owner
328
+     * @param $initiator
329
+     * @return string plain text mail
330
+     * @throws HintException
331
+     */
332
+    protected function createMailBody($template, $filename, $link, $owner, $initiator) {
333
+
334
+        $mailBodyTemplate = new Template('sharebymail', $template, '');
335
+        $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename));
336
+        $mailBodyTemplate->assign ('link', $link);
337
+        $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner));
338
+        $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator));
339
+        $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
340
+        $mailBody = $mailBodyTemplate->fetchPage();
341
+
342
+        if (is_string($mailBody)) {
343
+            return $mailBody;
344
+        }
345
+
346
+        throw new HintException('Failed to create the E-mail',
347
+            $this->l->t('Failed to create the E-mail'));
348
+    }
349
+
350
+    /**
351
+     * send password to recipient of a mail share
352
+     *
353
+     * @param string $filename
354
+     * @param string $initiator
355
+     * @param string $shareWith
356
+     * @param string $password
357
+     * @return bool
358
+     */
359
+    protected function sendPassword($filename, $initiator, $shareWith, $password) {
360
+
361
+        if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) {
362
+            return false;
363
+        }
364
+
365
+        $initiatorUser = $this->userManager->get($initiator);
366
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
367
+        $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
368
+        $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
369
+
370
+        $message = $this->mailer->createMessage();
371
+        $arguments = ['filename' => $filename, 'initiator' => $initiator, 'password' => $password];
372
+        $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $arguments);
373
+        $textBody = $this->createMailBodyToSendPassword('altmailpassword', $arguments);
374
+        $message->setTo([$shareWith]);
375
+        if ($initiatorEmailAddress) {
376
+            $message->setFrom([$initiatorEmailAddress]);
377
+        }
378
+        $message->setSubject($subject);
379
+        $message->setBody($textBody, 'text/plain');
380
+        $message->setHtmlBody($htmlBody);
381
+        $this->mailer->send($message);
382
+
383
+        return true;
384
+    }
385
+
386
+    /**
387
+     * send auto generated password to the owner. This happens if the admin enforces
388
+     * a password for mail shares and forbid to send the password by mail to the recipient
389
+     *
390
+     * @param string $filename
391
+     * @param string $initiator
392
+     * @param string $shareWith
393
+     * @param string $password
394
+     * @throws \Exception
395
+     */
396
+    protected function sendPasswordToOwner($filename, $initiator, $shareWith, $password) {
397
+
398
+        $initiatorUser = $this->userManager->get($initiator);
399
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
400
+        $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
401
+        $initiatorFullMail = $initiatorDisplayName . '<' . $initiatorEMailAddress . '>';
402
+
403
+        if ($initiatorEMailAddress === null) {
404
+            throw new \Exception(
405
+                $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
406
+            );
407
+        }
408
+
409
+        $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
410
+
411
+        $message = $this->mailer->createMessage();
412
+        $arguments = ['filename' => $filename, 'recipient' => $shareWith, 'password' => $password];
413
+        $htmlBody = $this->createMailBodyToSendPassword('mailpasswordowner', $arguments);
414
+        $textBody = $this->createMailBodyToSendPassword('altmailpasswordowner', $arguments);
415
+        if ($initiatorEMailAddress) {
416
+            $message->setFrom([$initiatorUser->getEMailAddress()]);
417
+        }
418
+        $message->setTo([$initiatorEMailAddress]);
419
+        $message->setFrom([$initiatorEMailAddress]);
420
+        $message->setSubject($subject);
421
+        $message->setBody($textBody, 'text/plain');
422
+        $message->setHtmlBody($htmlBody);
423
+        $this->mailer->send($message);
424
+
425
+    }
426
+
427
+    /**
428
+     * create mail body to send password to recipient
429
+     *
430
+     * @param string $template
431
+     * @param array $arguments
432
+     * @return string plain text mail
433
+     * @throws HintException
434
+     */
435
+    protected function createMailBodyToSendPassword($template, array $arguments) {
436
+
437
+        $mailBodyTemplate = new Template('sharebymail', $template, '');
438
+
439
+        foreach ($arguments as $key => $value) {
440
+            $mailBodyTemplate->assign ($key, \OCP\Util::sanitizeHTML($value));
441
+        }
442
+
443
+        $mailBody = $mailBodyTemplate->fetchPage();
444
+
445
+        if (is_string($mailBody)) {
446
+            return $mailBody;
447
+        }
448
+
449
+        throw new HintException('Failed to create the E-mail',
450
+            $this->l->t('Failed to create the E-mail'));
451
+    }
452
+
453
+
454
+    /**
455
+     * generate share token
456
+     *
457
+     * @return string
458
+     */
459
+    protected function generateToken($size = 15) {
460
+        $token = $this->secureRandom->generate(
461
+            $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
462
+        return $token;
463
+    }
464
+
465
+    /**
466
+     * Get all children of this share
467
+     *
468
+     * @param IShare $parent
469
+     * @return IShare[]
470
+     */
471
+    public function getChildren(IShare $parent) {
472
+        $children = [];
473
+
474
+        $qb = $this->dbConnection->getQueryBuilder();
475
+        $qb->select('*')
476
+            ->from('share')
477
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
478
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
479
+            ->orderBy('id');
480
+
481
+        $cursor = $qb->execute();
482
+        while($data = $cursor->fetch()) {
483
+            $children[] = $this->createShareObject($data);
484
+        }
485
+        $cursor->closeCursor();
486
+
487
+        return $children;
488
+    }
489
+
490
+    /**
491
+     * add share to the database and return the ID
492
+     *
493
+     * @param int $itemSource
494
+     * @param string $itemType
495
+     * @param string $shareWith
496
+     * @param string $sharedBy
497
+     * @param string $uidOwner
498
+     * @param int $permissions
499
+     * @param string $token
500
+     * @return int
501
+     */
502
+    protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) {
503
+        $qb = $this->dbConnection->getQueryBuilder();
504
+        $qb->insert('share')
505
+            ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
506
+            ->setValue('item_type', $qb->createNamedParameter($itemType))
507
+            ->setValue('item_source', $qb->createNamedParameter($itemSource))
508
+            ->setValue('file_source', $qb->createNamedParameter($itemSource))
509
+            ->setValue('share_with', $qb->createNamedParameter($shareWith))
510
+            ->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
511
+            ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
512
+            ->setValue('permissions', $qb->createNamedParameter($permissions))
513
+            ->setValue('token', $qb->createNamedParameter($token))
514
+            ->setValue('password', $qb->createNamedParameter($password))
515
+            ->setValue('stime', $qb->createNamedParameter(time()));
516
+
517
+        /*
518 518
 		 * Added to fix https://github.com/owncloud/core/issues/22215
519 519
 		 * Can be removed once we get rid of ajax/share.php
520 520
 		 */
521
-		$qb->setValue('file_target', $qb->createNamedParameter(''));
521
+        $qb->setValue('file_target', $qb->createNamedParameter(''));
522 522
 
523
-		$qb->execute();
524
-		$id = $qb->getLastInsertId();
523
+        $qb->execute();
524
+        $id = $qb->getLastInsertId();
525 525
 
526
-		return (int)$id;
527
-	}
526
+        return (int)$id;
527
+    }
528 528
 
529
-	/**
530
-	 * Update a share
531
-	 *
532
-	 * @param IShare $share
533
-	 * @param string|null $plainTextPassword
534
-	 * @return IShare The share object
535
-	 */
536
-	public function update(IShare $share, $plainTextPassword = null) {
529
+    /**
530
+     * Update a share
531
+     *
532
+     * @param IShare $share
533
+     * @param string|null $plainTextPassword
534
+     * @return IShare The share object
535
+     */
536
+    public function update(IShare $share, $plainTextPassword = null) {
537 537
 
538
-		$originalShare = $this->getShareById($share->getId());
538
+        $originalShare = $this->getShareById($share->getId());
539 539
 
540
-		// a real password was given
541
-		$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
540
+        // a real password was given
541
+        $validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
542 542
 
543
-		if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
544
-			$this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
545
-		}
546
-		/*
543
+        if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
544
+            $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
545
+        }
546
+        /*
547 547
 		 * We allow updating the permissions and password of mail shares
548 548
 		 */
549
-		$qb = $this->dbConnection->getQueryBuilder();
550
-		$qb->update('share')
551
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
552
-			->set('permissions', $qb->createNamedParameter($share->getPermissions()))
553
-			->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
554
-			->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
555
-			->set('password', $qb->createNamedParameter($share->getPassword()))
556
-			->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
557
-			->execute();
558
-
559
-		return $share;
560
-	}
561
-
562
-	/**
563
-	 * @inheritdoc
564
-	 */
565
-	public function move(IShare $share, $recipient) {
566
-		/**
567
-		 * nothing to do here, mail shares are only outgoing shares
568
-		 */
569
-		return $share;
570
-	}
571
-
572
-	/**
573
-	 * Delete a share (owner unShares the file)
574
-	 *
575
-	 * @param IShare $share
576
-	 */
577
-	public function delete(IShare $share) {
578
-		$this->removeShareFromTable($share->getId());
579
-	}
580
-
581
-	/**
582
-	 * @inheritdoc
583
-	 */
584
-	public function deleteFromSelf(IShare $share, $recipient) {
585
-		// nothing to do here, mail shares are only outgoing shares
586
-		return;
587
-	}
588
-
589
-	/**
590
-	 * @inheritdoc
591
-	 */
592
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
593
-		$qb = $this->dbConnection->getQueryBuilder();
594
-		$qb->select('*')
595
-			->from('share');
596
-
597
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
598
-
599
-		/**
600
-		 * Reshares for this user are shares where they are the owner.
601
-		 */
602
-		if ($reshares === false) {
603
-			//Special case for old shares created via the web UI
604
-			$or1 = $qb->expr()->andX(
605
-				$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
606
-				$qb->expr()->isNull('uid_initiator')
607
-			);
608
-
609
-			$qb->andWhere(
610
-				$qb->expr()->orX(
611
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
612
-					$or1
613
-				)
614
-			);
615
-		} else {
616
-			$qb->andWhere(
617
-				$qb->expr()->orX(
618
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
619
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
620
-				)
621
-			);
622
-		}
623
-
624
-		if ($node !== null) {
625
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
626
-		}
627
-
628
-		if ($limit !== -1) {
629
-			$qb->setMaxResults($limit);
630
-		}
631
-
632
-		$qb->setFirstResult($offset);
633
-		$qb->orderBy('id');
634
-
635
-		$cursor = $qb->execute();
636
-		$shares = [];
637
-		while($data = $cursor->fetch()) {
638
-			$shares[] = $this->createShareObject($data);
639
-		}
640
-		$cursor->closeCursor();
641
-
642
-		return $shares;
643
-	}
644
-
645
-	/**
646
-	 * @inheritdoc
647
-	 */
648
-	public function getShareById($id, $recipientId = null) {
649
-		$qb = $this->dbConnection->getQueryBuilder();
650
-
651
-		$qb->select('*')
652
-			->from('share')
653
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
654
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
655
-
656
-		$cursor = $qb->execute();
657
-		$data = $cursor->fetch();
658
-		$cursor->closeCursor();
659
-
660
-		if ($data === false) {
661
-			throw new ShareNotFound();
662
-		}
663
-
664
-		try {
665
-			$share = $this->createShareObject($data);
666
-		} catch (InvalidShare $e) {
667
-			throw new ShareNotFound();
668
-		}
669
-
670
-		return $share;
671
-	}
672
-
673
-	/**
674
-	 * Get shares for a given path
675
-	 *
676
-	 * @param \OCP\Files\Node $path
677
-	 * @return IShare[]
678
-	 */
679
-	public function getSharesByPath(Node $path) {
680
-		$qb = $this->dbConnection->getQueryBuilder();
681
-
682
-		$cursor = $qb->select('*')
683
-			->from('share')
684
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
685
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
686
-			->execute();
687
-
688
-		$shares = [];
689
-		while($data = $cursor->fetch()) {
690
-			$shares[] = $this->createShareObject($data);
691
-		}
692
-		$cursor->closeCursor();
693
-
694
-		return $shares;
695
-	}
696
-
697
-	/**
698
-	 * @inheritdoc
699
-	 */
700
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
701
-		/** @var IShare[] $shares */
702
-		$shares = [];
703
-
704
-		//Get shares directly with this user
705
-		$qb = $this->dbConnection->getQueryBuilder();
706
-		$qb->select('*')
707
-			->from('share');
708
-
709
-		// Order by id
710
-		$qb->orderBy('id');
711
-
712
-		// Set limit and offset
713
-		if ($limit !== -1) {
714
-			$qb->setMaxResults($limit);
715
-		}
716
-		$qb->setFirstResult($offset);
717
-
718
-		$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
719
-		$qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
720
-
721
-		// Filter by node if provided
722
-		if ($node !== null) {
723
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
724
-		}
725
-
726
-		$cursor = $qb->execute();
727
-
728
-		while($data = $cursor->fetch()) {
729
-			$shares[] = $this->createShareObject($data);
730
-		}
731
-		$cursor->closeCursor();
732
-
733
-
734
-		return $shares;
735
-	}
736
-
737
-	/**
738
-	 * Get a share by token
739
-	 *
740
-	 * @param string $token
741
-	 * @return IShare
742
-	 * @throws ShareNotFound
743
-	 */
744
-	public function getShareByToken($token) {
745
-		$qb = $this->dbConnection->getQueryBuilder();
746
-
747
-		$cursor = $qb->select('*')
748
-			->from('share')
749
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
750
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
751
-			->execute();
752
-
753
-		$data = $cursor->fetch();
754
-
755
-		if ($data === false) {
756
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
757
-		}
758
-
759
-		try {
760
-			$share = $this->createShareObject($data);
761
-		} catch (InvalidShare $e) {
762
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
763
-		}
764
-
765
-		return $share;
766
-	}
767
-
768
-	/**
769
-	 * remove share from table
770
-	 *
771
-	 * @param string $shareId
772
-	 */
773
-	protected function removeShareFromTable($shareId) {
774
-		$qb = $this->dbConnection->getQueryBuilder();
775
-		$qb->delete('share')
776
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
777
-		$qb->execute();
778
-	}
779
-
780
-	/**
781
-	 * Create a share object from an database row
782
-	 *
783
-	 * @param array $data
784
-	 * @return IShare
785
-	 * @throws InvalidShare
786
-	 * @throws ShareNotFound
787
-	 */
788
-	protected function createShareObject($data) {
789
-
790
-		$share = new Share($this->rootFolder, $this->userManager);
791
-		$share->setId((int)$data['id'])
792
-			->setShareType((int)$data['share_type'])
793
-			->setPermissions((int)$data['permissions'])
794
-			->setTarget($data['file_target'])
795
-			->setMailSend((bool)$data['mail_send'])
796
-			->setToken($data['token']);
797
-
798
-		$shareTime = new \DateTime();
799
-		$shareTime->setTimestamp((int)$data['stime']);
800
-		$share->setShareTime($shareTime);
801
-		$share->setSharedWith($data['share_with']);
802
-		$share->setPassword($data['password']);
803
-
804
-		if ($data['uid_initiator'] !== null) {
805
-			$share->setShareOwner($data['uid_owner']);
806
-			$share->setSharedBy($data['uid_initiator']);
807
-		} else {
808
-			//OLD SHARE
809
-			$share->setSharedBy($data['uid_owner']);
810
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
811
-
812
-			$owner = $path->getOwner();
813
-			$share->setShareOwner($owner->getUID());
814
-		}
815
-
816
-		if ($data['expiration'] !== null) {
817
-			$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
818
-			if ($expiration !== false) {
819
-				$share->setExpirationDate($expiration);
820
-			}
821
-		}
822
-
823
-		$share->setNodeId((int)$data['file_source']);
824
-		$share->setNodeType($data['item_type']);
825
-
826
-		$share->setProviderId($this->identifier());
827
-
828
-		return $share;
829
-	}
830
-
831
-	/**
832
-	 * Get the node with file $id for $user
833
-	 *
834
-	 * @param string $userId
835
-	 * @param int $id
836
-	 * @return \OCP\Files\File|\OCP\Files\Folder
837
-	 * @throws InvalidShare
838
-	 */
839
-	private function getNode($userId, $id) {
840
-		try {
841
-			$userFolder = $this->rootFolder->getUserFolder($userId);
842
-		} catch (NotFoundException $e) {
843
-			throw new InvalidShare();
844
-		}
845
-
846
-		$nodes = $userFolder->getById($id);
847
-
848
-		if (empty($nodes)) {
849
-			throw new InvalidShare();
850
-		}
851
-
852
-		return $nodes[0];
853
-	}
854
-
855
-	/**
856
-	 * A user is deleted from the system
857
-	 * So clean up the relevant shares.
858
-	 *
859
-	 * @param string $uid
860
-	 * @param int $shareType
861
-	 */
862
-	public function userDeleted($uid, $shareType) {
863
-		$qb = $this->dbConnection->getQueryBuilder();
864
-
865
-		$qb->delete('share')
866
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
867
-			->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
868
-			->execute();
869
-	}
870
-
871
-	/**
872
-	 * This provider does not support group shares
873
-	 *
874
-	 * @param string $gid
875
-	 */
876
-	public function groupDeleted($gid) {
877
-		return;
878
-	}
879
-
880
-	/**
881
-	 * This provider does not support group shares
882
-	 *
883
-	 * @param string $uid
884
-	 * @param string $gid
885
-	 */
886
-	public function userDeletedFromGroup($uid, $gid) {
887
-		return;
888
-	}
889
-
890
-	/**
891
-	 * get database row of a give share
892
-	 *
893
-	 * @param $id
894
-	 * @return array
895
-	 * @throws ShareNotFound
896
-	 */
897
-	protected function getRawShare($id) {
898
-
899
-		// Now fetch the inserted share and create a complete share object
900
-		$qb = $this->dbConnection->getQueryBuilder();
901
-		$qb->select('*')
902
-			->from('share')
903
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
904
-
905
-		$cursor = $qb->execute();
906
-		$data = $cursor->fetch();
907
-		$cursor->closeCursor();
908
-
909
-		if ($data === false) {
910
-			throw new ShareNotFound;
911
-		}
912
-
913
-		return $data;
914
-	}
915
-
916
-	public function getSharesInFolder($userId, Folder $node, $reshares) {
917
-		$qb = $this->dbConnection->getQueryBuilder();
918
-		$qb->select('*')
919
-			->from('share', 's')
920
-			->andWhere($qb->expr()->orX(
921
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
922
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
923
-			))
924
-			->andWhere(
925
-				$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
926
-			);
927
-
928
-		/**
929
-		 * Reshares for this user are shares where they are the owner.
930
-		 */
931
-		if ($reshares === false) {
932
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
933
-		} else {
934
-			$qb->andWhere(
935
-				$qb->expr()->orX(
936
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
937
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
938
-				)
939
-			);
940
-		}
941
-
942
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
943
-		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
944
-
945
-		$qb->orderBy('id');
946
-
947
-		$cursor = $qb->execute();
948
-		$shares = [];
949
-		while ($data = $cursor->fetch()) {
950
-			$shares[$data['fileid']][] = $this->createShareObject($data);
951
-		}
952
-		$cursor->closeCursor();
953
-
954
-		return $shares;
955
-	}
549
+        $qb = $this->dbConnection->getQueryBuilder();
550
+        $qb->update('share')
551
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
552
+            ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
553
+            ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
554
+            ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
555
+            ->set('password', $qb->createNamedParameter($share->getPassword()))
556
+            ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
557
+            ->execute();
558
+
559
+        return $share;
560
+    }
561
+
562
+    /**
563
+     * @inheritdoc
564
+     */
565
+    public function move(IShare $share, $recipient) {
566
+        /**
567
+         * nothing to do here, mail shares are only outgoing shares
568
+         */
569
+        return $share;
570
+    }
571
+
572
+    /**
573
+     * Delete a share (owner unShares the file)
574
+     *
575
+     * @param IShare $share
576
+     */
577
+    public function delete(IShare $share) {
578
+        $this->removeShareFromTable($share->getId());
579
+    }
580
+
581
+    /**
582
+     * @inheritdoc
583
+     */
584
+    public function deleteFromSelf(IShare $share, $recipient) {
585
+        // nothing to do here, mail shares are only outgoing shares
586
+        return;
587
+    }
588
+
589
+    /**
590
+     * @inheritdoc
591
+     */
592
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
593
+        $qb = $this->dbConnection->getQueryBuilder();
594
+        $qb->select('*')
595
+            ->from('share');
596
+
597
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
598
+
599
+        /**
600
+         * Reshares for this user are shares where they are the owner.
601
+         */
602
+        if ($reshares === false) {
603
+            //Special case for old shares created via the web UI
604
+            $or1 = $qb->expr()->andX(
605
+                $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
606
+                $qb->expr()->isNull('uid_initiator')
607
+            );
608
+
609
+            $qb->andWhere(
610
+                $qb->expr()->orX(
611
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
612
+                    $or1
613
+                )
614
+            );
615
+        } else {
616
+            $qb->andWhere(
617
+                $qb->expr()->orX(
618
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
619
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
620
+                )
621
+            );
622
+        }
623
+
624
+        if ($node !== null) {
625
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
626
+        }
627
+
628
+        if ($limit !== -1) {
629
+            $qb->setMaxResults($limit);
630
+        }
631
+
632
+        $qb->setFirstResult($offset);
633
+        $qb->orderBy('id');
634
+
635
+        $cursor = $qb->execute();
636
+        $shares = [];
637
+        while($data = $cursor->fetch()) {
638
+            $shares[] = $this->createShareObject($data);
639
+        }
640
+        $cursor->closeCursor();
641
+
642
+        return $shares;
643
+    }
644
+
645
+    /**
646
+     * @inheritdoc
647
+     */
648
+    public function getShareById($id, $recipientId = null) {
649
+        $qb = $this->dbConnection->getQueryBuilder();
650
+
651
+        $qb->select('*')
652
+            ->from('share')
653
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
654
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
655
+
656
+        $cursor = $qb->execute();
657
+        $data = $cursor->fetch();
658
+        $cursor->closeCursor();
659
+
660
+        if ($data === false) {
661
+            throw new ShareNotFound();
662
+        }
663
+
664
+        try {
665
+            $share = $this->createShareObject($data);
666
+        } catch (InvalidShare $e) {
667
+            throw new ShareNotFound();
668
+        }
669
+
670
+        return $share;
671
+    }
672
+
673
+    /**
674
+     * Get shares for a given path
675
+     *
676
+     * @param \OCP\Files\Node $path
677
+     * @return IShare[]
678
+     */
679
+    public function getSharesByPath(Node $path) {
680
+        $qb = $this->dbConnection->getQueryBuilder();
681
+
682
+        $cursor = $qb->select('*')
683
+            ->from('share')
684
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
685
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
686
+            ->execute();
687
+
688
+        $shares = [];
689
+        while($data = $cursor->fetch()) {
690
+            $shares[] = $this->createShareObject($data);
691
+        }
692
+        $cursor->closeCursor();
693
+
694
+        return $shares;
695
+    }
696
+
697
+    /**
698
+     * @inheritdoc
699
+     */
700
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
701
+        /** @var IShare[] $shares */
702
+        $shares = [];
703
+
704
+        //Get shares directly with this user
705
+        $qb = $this->dbConnection->getQueryBuilder();
706
+        $qb->select('*')
707
+            ->from('share');
708
+
709
+        // Order by id
710
+        $qb->orderBy('id');
711
+
712
+        // Set limit and offset
713
+        if ($limit !== -1) {
714
+            $qb->setMaxResults($limit);
715
+        }
716
+        $qb->setFirstResult($offset);
717
+
718
+        $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
719
+        $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
720
+
721
+        // Filter by node if provided
722
+        if ($node !== null) {
723
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
724
+        }
725
+
726
+        $cursor = $qb->execute();
727
+
728
+        while($data = $cursor->fetch()) {
729
+            $shares[] = $this->createShareObject($data);
730
+        }
731
+        $cursor->closeCursor();
732
+
733
+
734
+        return $shares;
735
+    }
736
+
737
+    /**
738
+     * Get a share by token
739
+     *
740
+     * @param string $token
741
+     * @return IShare
742
+     * @throws ShareNotFound
743
+     */
744
+    public function getShareByToken($token) {
745
+        $qb = $this->dbConnection->getQueryBuilder();
746
+
747
+        $cursor = $qb->select('*')
748
+            ->from('share')
749
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
750
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
751
+            ->execute();
752
+
753
+        $data = $cursor->fetch();
754
+
755
+        if ($data === false) {
756
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
757
+        }
758
+
759
+        try {
760
+            $share = $this->createShareObject($data);
761
+        } catch (InvalidShare $e) {
762
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
763
+        }
764
+
765
+        return $share;
766
+    }
767
+
768
+    /**
769
+     * remove share from table
770
+     *
771
+     * @param string $shareId
772
+     */
773
+    protected function removeShareFromTable($shareId) {
774
+        $qb = $this->dbConnection->getQueryBuilder();
775
+        $qb->delete('share')
776
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
777
+        $qb->execute();
778
+    }
779
+
780
+    /**
781
+     * Create a share object from an database row
782
+     *
783
+     * @param array $data
784
+     * @return IShare
785
+     * @throws InvalidShare
786
+     * @throws ShareNotFound
787
+     */
788
+    protected function createShareObject($data) {
789
+
790
+        $share = new Share($this->rootFolder, $this->userManager);
791
+        $share->setId((int)$data['id'])
792
+            ->setShareType((int)$data['share_type'])
793
+            ->setPermissions((int)$data['permissions'])
794
+            ->setTarget($data['file_target'])
795
+            ->setMailSend((bool)$data['mail_send'])
796
+            ->setToken($data['token']);
797
+
798
+        $shareTime = new \DateTime();
799
+        $shareTime->setTimestamp((int)$data['stime']);
800
+        $share->setShareTime($shareTime);
801
+        $share->setSharedWith($data['share_with']);
802
+        $share->setPassword($data['password']);
803
+
804
+        if ($data['uid_initiator'] !== null) {
805
+            $share->setShareOwner($data['uid_owner']);
806
+            $share->setSharedBy($data['uid_initiator']);
807
+        } else {
808
+            //OLD SHARE
809
+            $share->setSharedBy($data['uid_owner']);
810
+            $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
811
+
812
+            $owner = $path->getOwner();
813
+            $share->setShareOwner($owner->getUID());
814
+        }
815
+
816
+        if ($data['expiration'] !== null) {
817
+            $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
818
+            if ($expiration !== false) {
819
+                $share->setExpirationDate($expiration);
820
+            }
821
+        }
822
+
823
+        $share->setNodeId((int)$data['file_source']);
824
+        $share->setNodeType($data['item_type']);
825
+
826
+        $share->setProviderId($this->identifier());
827
+
828
+        return $share;
829
+    }
830
+
831
+    /**
832
+     * Get the node with file $id for $user
833
+     *
834
+     * @param string $userId
835
+     * @param int $id
836
+     * @return \OCP\Files\File|\OCP\Files\Folder
837
+     * @throws InvalidShare
838
+     */
839
+    private function getNode($userId, $id) {
840
+        try {
841
+            $userFolder = $this->rootFolder->getUserFolder($userId);
842
+        } catch (NotFoundException $e) {
843
+            throw new InvalidShare();
844
+        }
845
+
846
+        $nodes = $userFolder->getById($id);
847
+
848
+        if (empty($nodes)) {
849
+            throw new InvalidShare();
850
+        }
851
+
852
+        return $nodes[0];
853
+    }
854
+
855
+    /**
856
+     * A user is deleted from the system
857
+     * So clean up the relevant shares.
858
+     *
859
+     * @param string $uid
860
+     * @param int $shareType
861
+     */
862
+    public function userDeleted($uid, $shareType) {
863
+        $qb = $this->dbConnection->getQueryBuilder();
864
+
865
+        $qb->delete('share')
866
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
867
+            ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
868
+            ->execute();
869
+    }
870
+
871
+    /**
872
+     * This provider does not support group shares
873
+     *
874
+     * @param string $gid
875
+     */
876
+    public function groupDeleted($gid) {
877
+        return;
878
+    }
879
+
880
+    /**
881
+     * This provider does not support group shares
882
+     *
883
+     * @param string $uid
884
+     * @param string $gid
885
+     */
886
+    public function userDeletedFromGroup($uid, $gid) {
887
+        return;
888
+    }
889
+
890
+    /**
891
+     * get database row of a give share
892
+     *
893
+     * @param $id
894
+     * @return array
895
+     * @throws ShareNotFound
896
+     */
897
+    protected function getRawShare($id) {
898
+
899
+        // Now fetch the inserted share and create a complete share object
900
+        $qb = $this->dbConnection->getQueryBuilder();
901
+        $qb->select('*')
902
+            ->from('share')
903
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
904
+
905
+        $cursor = $qb->execute();
906
+        $data = $cursor->fetch();
907
+        $cursor->closeCursor();
908
+
909
+        if ($data === false) {
910
+            throw new ShareNotFound;
911
+        }
912
+
913
+        return $data;
914
+    }
915
+
916
+    public function getSharesInFolder($userId, Folder $node, $reshares) {
917
+        $qb = $this->dbConnection->getQueryBuilder();
918
+        $qb->select('*')
919
+            ->from('share', 's')
920
+            ->andWhere($qb->expr()->orX(
921
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
922
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
923
+            ))
924
+            ->andWhere(
925
+                $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
926
+            );
927
+
928
+        /**
929
+         * Reshares for this user are shares where they are the owner.
930
+         */
931
+        if ($reshares === false) {
932
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
933
+        } else {
934
+            $qb->andWhere(
935
+                $qb->expr()->orX(
936
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
937
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
938
+                )
939
+            );
940
+        }
941
+
942
+        $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
943
+        $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
944
+
945
+        $qb->orderBy('id');
946
+
947
+        $cursor = $qb->execute();
948
+        $shares = [];
949
+        while ($data = $cursor->fetch()) {
950
+            $shares[$data['fileid']][] = $this->createShareObject($data);
951
+        }
952
+        $cursor->closeCursor();
953
+
954
+        return $shares;
955
+    }
956 956
 
957 957
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -279,11 +279,11 @@  discard block
 block discarded – undo
279 279
 				$share->getShareOwner(),
280 280
 				$share->getSharedBy(), $share->getSharedWith());
281 281
 		} catch (HintException $hintException) {
282
-			$this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
282
+			$this->logger->error('Failed to send share by mail: '.$hintException->getMessage());
283 283
 			$this->removeShareFromTable($shareId);
284 284
 			throw $hintException;
285 285
 		} catch (\Exception $e) {
286
-			$this->logger->error('Failed to send share by mail: ' . $e->getMessage());
286
+			$this->logger->error('Failed to send share by mail: '.$e->getMessage());
287 287
 			$this->removeShareFromTable($shareId);
288 288
 			throw new HintException('Failed to send share by mail',
289 289
 				$this->l->t('Failed to send share by E-mail'));
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
 		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
301 301
 		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
302 302
 		if ($owner === $initiator) {
303
-			$subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
303
+			$subject = (string) $this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
304 304
 		} else {
305
-			$subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
305
+			$subject = (string) $this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
306 306
 		}
307 307
 
308 308
 		$message = $this->mailer->createMessage();
@@ -332,11 +332,11 @@  discard block
 block discarded – undo
332 332
 	protected function createMailBody($template, $filename, $link, $owner, $initiator) {
333 333
 
334 334
 		$mailBodyTemplate = new Template('sharebymail', $template, '');
335
-		$mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename));
336
-		$mailBodyTemplate->assign ('link', $link);
337
-		$mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner));
338
-		$mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator));
339
-		$mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
335
+		$mailBodyTemplate->assign('filename', \OCP\Util::sanitizeHTML($filename));
336
+		$mailBodyTemplate->assign('link', $link);
337
+		$mailBodyTemplate->assign('owner', \OCP\Util::sanitizeHTML($owner));
338
+		$mailBodyTemplate->assign('initiator', \OCP\Util::sanitizeHTML($initiator));
339
+		$mailBodyTemplate->assign('onBehalfOf', $initiator !== $owner);
340 340
 		$mailBody = $mailBodyTemplate->fetchPage();
341 341
 
342 342
 		if (is_string($mailBody)) {
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		$initiatorUser = $this->userManager->get($initiator);
366 366
 		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
367 367
 		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
368
-		$subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
368
+		$subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
369 369
 
370 370
 		$message = $this->mailer->createMessage();
371 371
 		$arguments = ['filename' => $filename, 'initiator' => $initiator, 'password' => $password];
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 		$initiatorUser = $this->userManager->get($initiator);
399 399
 		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
400 400
 		$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
401
-		$initiatorFullMail = $initiatorDisplayName . '<' . $initiatorEMailAddress . '>';
401
+		$initiatorFullMail = $initiatorDisplayName.'<'.$initiatorEMailAddress.'>';
402 402
 
403 403
 		if ($initiatorEMailAddress === null) {
404 404
 			throw new \Exception(
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 			);
407 407
 		}
408 408
 
409
-		$subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
409
+		$subject = (string) $this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
410 410
 
411 411
 		$message = $this->mailer->createMessage();
412 412
 		$arguments = ['filename' => $filename, 'recipient' => $shareWith, 'password' => $password];
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 		$mailBodyTemplate = new Template('sharebymail', $template, '');
438 438
 
439 439
 		foreach ($arguments as $key => $value) {
440
-			$mailBodyTemplate->assign ($key, \OCP\Util::sanitizeHTML($value));
440
+			$mailBodyTemplate->assign($key, \OCP\Util::sanitizeHTML($value));
441 441
 		}
442 442
 
443 443
 		$mailBody = $mailBodyTemplate->fetchPage();
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 	 */
459 459
 	protected function generateToken($size = 15) {
460 460
 		$token = $this->secureRandom->generate(
461
-			$size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
461
+			$size, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS);
462 462
 		return $token;
463 463
 	}
464 464
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 			->orderBy('id');
480 480
 
481 481
 		$cursor = $qb->execute();
482
-		while($data = $cursor->fetch()) {
482
+		while ($data = $cursor->fetch()) {
483 483
 			$children[] = $this->createShareObject($data);
484 484
 		}
485 485
 		$cursor->closeCursor();
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 		$qb->execute();
524 524
 		$id = $qb->getLastInsertId();
525 525
 
526
-		return (int)$id;
526
+		return (int) $id;
527 527
 	}
528 528
 
529 529
 	/**
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 		// a real password was given
541 541
 		$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
542 542
 
543
-		if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
543
+		if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
544 544
 			$this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
545 545
 		}
546 546
 		/*
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 
635 635
 		$cursor = $qb->execute();
636 636
 		$shares = [];
637
-		while($data = $cursor->fetch()) {
637
+		while ($data = $cursor->fetch()) {
638 638
 			$shares[] = $this->createShareObject($data);
639 639
 		}
640 640
 		$cursor->closeCursor();
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 			->execute();
687 687
 
688 688
 		$shares = [];
689
-		while($data = $cursor->fetch()) {
689
+		while ($data = $cursor->fetch()) {
690 690
 			$shares[] = $this->createShareObject($data);
691 691
 		}
692 692
 		$cursor->closeCursor();
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 
726 726
 		$cursor = $qb->execute();
727 727
 
728
-		while($data = $cursor->fetch()) {
728
+		while ($data = $cursor->fetch()) {
729 729
 			$shares[] = $this->createShareObject($data);
730 730
 		}
731 731
 		$cursor->closeCursor();
@@ -788,15 +788,15 @@  discard block
 block discarded – undo
788 788
 	protected function createShareObject($data) {
789 789
 
790 790
 		$share = new Share($this->rootFolder, $this->userManager);
791
-		$share->setId((int)$data['id'])
792
-			->setShareType((int)$data['share_type'])
793
-			->setPermissions((int)$data['permissions'])
791
+		$share->setId((int) $data['id'])
792
+			->setShareType((int) $data['share_type'])
793
+			->setPermissions((int) $data['permissions'])
794 794
 			->setTarget($data['file_target'])
795
-			->setMailSend((bool)$data['mail_send'])
795
+			->setMailSend((bool) $data['mail_send'])
796 796
 			->setToken($data['token']);
797 797
 
798 798
 		$shareTime = new \DateTime();
799
-		$shareTime->setTimestamp((int)$data['stime']);
799
+		$shareTime->setTimestamp((int) $data['stime']);
800 800
 		$share->setShareTime($shareTime);
801 801
 		$share->setSharedWith($data['share_with']);
802 802
 		$share->setPassword($data['password']);
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
 		} else {
808 808
 			//OLD SHARE
809 809
 			$share->setSharedBy($data['uid_owner']);
810
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
810
+			$path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
811 811
 
812 812
 			$owner = $path->getOwner();
813 813
 			$share->setShareOwner($owner->getUID());
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 			}
821 821
 		}
822 822
 
823
-		$share->setNodeId((int)$data['file_source']);
823
+		$share->setNodeId((int) $data['file_source']);
824 824
 		$share->setNodeType($data['item_type']);
825 825
 
826 826
 		$share->setProviderId($this->identifier());
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 			);
940 940
 		}
941 941
 
942
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
942
+		$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
943 943
 		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
944 944
 
945 945
 		$qb->orderBy('id');
Please login to merge, or discard this patch.
lib/private/Share20/ProviderFactory.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -41,226 +41,226 @@
 block discarded – undo
41 41
  */
42 42
 class ProviderFactory implements IProviderFactory {
43 43
 
44
-	/** @var IServerContainer */
45
-	private $serverContainer;
46
-	/** @var DefaultShareProvider */
47
-	private $defaultProvider = null;
48
-	/** @var FederatedShareProvider */
49
-	private $federatedProvider = null;
50
-	/** @var  ShareByMailProvider */
51
-	private $shareByMailProvider;
52
-	/** @var  \OCA\Circles\ShareByCircleProvider;
53
-	 * ShareByCircleProvider */
54
-	private $shareByCircleProvider;
55
-
56
-	/**
57
-	 * IProviderFactory constructor.
58
-	 *
59
-	 * @param IServerContainer $serverContainer
60
-	 */
61
-	public function __construct(IServerContainer $serverContainer) {
62
-		$this->serverContainer = $serverContainer;
63
-	}
64
-
65
-	/**
66
-	 * Create the default share provider.
67
-	 *
68
-	 * @return DefaultShareProvider
69
-	 */
70
-	protected function defaultShareProvider() {
71
-		if ($this->defaultProvider === null) {
72
-			$this->defaultProvider = new DefaultShareProvider(
73
-				$this->serverContainer->getDatabaseConnection(),
74
-				$this->serverContainer->getUserManager(),
75
-				$this->serverContainer->getGroupManager(),
76
-				$this->serverContainer->getLazyRootFolder()
77
-			);
78
-		}
79
-
80
-		return $this->defaultProvider;
81
-	}
82
-
83
-	/**
84
-	 * Create the federated share provider
85
-	 *
86
-	 * @return FederatedShareProvider
87
-	 */
88
-	protected function federatedShareProvider() {
89
-		if ($this->federatedProvider === null) {
90
-			/*
44
+    /** @var IServerContainer */
45
+    private $serverContainer;
46
+    /** @var DefaultShareProvider */
47
+    private $defaultProvider = null;
48
+    /** @var FederatedShareProvider */
49
+    private $federatedProvider = null;
50
+    /** @var  ShareByMailProvider */
51
+    private $shareByMailProvider;
52
+    /** @var  \OCA\Circles\ShareByCircleProvider;
53
+     * ShareByCircleProvider */
54
+    private $shareByCircleProvider;
55
+
56
+    /**
57
+     * IProviderFactory constructor.
58
+     *
59
+     * @param IServerContainer $serverContainer
60
+     */
61
+    public function __construct(IServerContainer $serverContainer) {
62
+        $this->serverContainer = $serverContainer;
63
+    }
64
+
65
+    /**
66
+     * Create the default share provider.
67
+     *
68
+     * @return DefaultShareProvider
69
+     */
70
+    protected function defaultShareProvider() {
71
+        if ($this->defaultProvider === null) {
72
+            $this->defaultProvider = new DefaultShareProvider(
73
+                $this->serverContainer->getDatabaseConnection(),
74
+                $this->serverContainer->getUserManager(),
75
+                $this->serverContainer->getGroupManager(),
76
+                $this->serverContainer->getLazyRootFolder()
77
+            );
78
+        }
79
+
80
+        return $this->defaultProvider;
81
+    }
82
+
83
+    /**
84
+     * Create the federated share provider
85
+     *
86
+     * @return FederatedShareProvider
87
+     */
88
+    protected function federatedShareProvider() {
89
+        if ($this->federatedProvider === null) {
90
+            /*
91 91
 			 * Check if the app is enabled
92 92
 			 */
93
-			$appManager = $this->serverContainer->getAppManager();
94
-			if (!$appManager->isEnabledForUser('federatedfilesharing')) {
95
-				return null;
96
-			}
93
+            $appManager = $this->serverContainer->getAppManager();
94
+            if (!$appManager->isEnabledForUser('federatedfilesharing')) {
95
+                return null;
96
+            }
97 97
 
98
-			/*
98
+            /*
99 99
 			 * TODO: add factory to federated sharing app
100 100
 			 */
101
-			$l = $this->serverContainer->getL10N('federatedfilessharing');
102
-			$addressHandler = new AddressHandler(
103
-				$this->serverContainer->getURLGenerator(),
104
-				$l,
105
-				$this->serverContainer->getCloudIdManager()
106
-			);
107
-			$discoveryManager = new DiscoveryManager(
108
-				$this->serverContainer->getMemCacheFactory(),
109
-				$this->serverContainer->getHTTPClientService()
110
-			);
111
-			$notifications = new Notifications(
112
-				$addressHandler,
113
-				$this->serverContainer->getHTTPClientService(),
114
-				$discoveryManager,
115
-				$this->serverContainer->getJobList()
116
-			);
117
-			$tokenHandler = new TokenHandler(
118
-				$this->serverContainer->getSecureRandom()
119
-			);
120
-
121
-			$this->federatedProvider = new FederatedShareProvider(
122
-				$this->serverContainer->getDatabaseConnection(),
123
-				$addressHandler,
124
-				$notifications,
125
-				$tokenHandler,
126
-				$l,
127
-				$this->serverContainer->getLogger(),
128
-				$this->serverContainer->getLazyRootFolder(),
129
-				$this->serverContainer->getConfig(),
130
-				$this->serverContainer->getUserManager(),
131
-				$this->serverContainer->getCloudIdManager()
132
-			);
133
-		}
134
-
135
-		return $this->federatedProvider;
136
-	}
137
-
138
-	/**
139
-	 * Create the federated share provider
140
-	 *
141
-	 * @return ShareByMailProvider
142
-	 */
143
-	protected function getShareByMailProvider() {
144
-		if ($this->shareByMailProvider === null) {
145
-			/*
101
+            $l = $this->serverContainer->getL10N('federatedfilessharing');
102
+            $addressHandler = new AddressHandler(
103
+                $this->serverContainer->getURLGenerator(),
104
+                $l,
105
+                $this->serverContainer->getCloudIdManager()
106
+            );
107
+            $discoveryManager = new DiscoveryManager(
108
+                $this->serverContainer->getMemCacheFactory(),
109
+                $this->serverContainer->getHTTPClientService()
110
+            );
111
+            $notifications = new Notifications(
112
+                $addressHandler,
113
+                $this->serverContainer->getHTTPClientService(),
114
+                $discoveryManager,
115
+                $this->serverContainer->getJobList()
116
+            );
117
+            $tokenHandler = new TokenHandler(
118
+                $this->serverContainer->getSecureRandom()
119
+            );
120
+
121
+            $this->federatedProvider = new FederatedShareProvider(
122
+                $this->serverContainer->getDatabaseConnection(),
123
+                $addressHandler,
124
+                $notifications,
125
+                $tokenHandler,
126
+                $l,
127
+                $this->serverContainer->getLogger(),
128
+                $this->serverContainer->getLazyRootFolder(),
129
+                $this->serverContainer->getConfig(),
130
+                $this->serverContainer->getUserManager(),
131
+                $this->serverContainer->getCloudIdManager()
132
+            );
133
+        }
134
+
135
+        return $this->federatedProvider;
136
+    }
137
+
138
+    /**
139
+     * Create the federated share provider
140
+     *
141
+     * @return ShareByMailProvider
142
+     */
143
+    protected function getShareByMailProvider() {
144
+        if ($this->shareByMailProvider === null) {
145
+            /*
146 146
 			 * Check if the app is enabled
147 147
 			 */
148
-			$appManager = $this->serverContainer->getAppManager();
149
-			if (!$appManager->isEnabledForUser('sharebymail')) {
150
-				return null;
151
-			}
152
-
153
-			$settingsManager = new SettingsManager($this->serverContainer->getConfig());
154
-
155
-			$this->shareByMailProvider = new ShareByMailProvider(
156
-				$this->serverContainer->getDatabaseConnection(),
157
-				$this->serverContainer->getSecureRandom(),
158
-				$this->serverContainer->getUserManager(),
159
-				$this->serverContainer->getLazyRootFolder(),
160
-				$this->serverContainer->getL10N('sharebymail'),
161
-				$this->serverContainer->getLogger(),
162
-				$this->serverContainer->getMailer(),
163
-				$this->serverContainer->getURLGenerator(),
164
-				$this->serverContainer->getActivityManager(),
165
-				$settingsManager,
166
-				$this->serverContainer->getHasher()
167
-			);
168
-		}
169
-
170
-		return $this->shareByMailProvider;
171
-	}
172
-
173
-
174
-	/**
175
-	 * Create the circle share provider
176
-	 *
177
-	 * @return FederatedShareProvider
178
-	 */
179
-	protected function getShareByCircleProvider() {
180
-
181
-		$appManager = $this->serverContainer->getAppManager();
182
-		if (!$appManager->isEnabledForUser('circles')) {
183
-			return null;
184
-		}
185
-
186
-
187
-		if ($this->shareByCircleProvider === null) {
188
-
189
-			$this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
190
-				$this->serverContainer->getDatabaseConnection(),
191
-				$this->serverContainer->getSecureRandom(),
192
-				$this->serverContainer->getUserManager(),
193
-				$this->serverContainer->getLazyRootFolder(),
194
-				$this->serverContainer->getL10N('circles'),
195
-				$this->serverContainer->getLogger(),
196
-				$this->serverContainer->getURLGenerator()
197
-			);
198
-		}
199
-
200
-		return $this->shareByCircleProvider;
201
-	}
202
-
203
-
204
-	/**
205
-	 * @inheritdoc
206
-	 */
207
-	public function getProvider($id) {
208
-		$provider = null;
209
-		if ($id === 'ocinternal') {
210
-			$provider = $this->defaultShareProvider();
211
-		} else if ($id === 'ocFederatedSharing') {
212
-			$provider = $this->federatedShareProvider();
213
-		} else if ($id === 'ocMailShare') {
214
-			$provider = $this->getShareByMailProvider();
215
-		} else if ($id === 'ocCircleShare') {
216
-			$provider = $this->getShareByCircleProvider();
217
-		}
218
-
219
-		if ($provider === null) {
220
-			throw new ProviderException('No provider with id .' . $id . ' found.');
221
-		}
222
-
223
-		return $provider;
224
-	}
225
-
226
-	/**
227
-	 * @inheritdoc
228
-	 */
229
-	public function getProviderForType($shareType) {
230
-		$provider = null;
231
-
232
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
233
-			$shareType === \OCP\Share::SHARE_TYPE_GROUP ||
234
-			$shareType === \OCP\Share::SHARE_TYPE_LINK
235
-		) {
236
-			$provider = $this->defaultShareProvider();
237
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
238
-			$provider = $this->federatedShareProvider();
239
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
240
-			$provider = $this->getShareByMailProvider();
241
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
242
-			$provider = $this->getShareByCircleProvider();
243
-		}
244
-
245
-
246
-		if ($provider === null) {
247
-			throw new ProviderException('No share provider for share type ' . $shareType);
248
-		}
249
-
250
-		return $provider;
251
-	}
252
-
253
-	public function getAllProviders() {
254
-		$shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];
255
-		$shareByMail = $this->getShareByMailProvider();
256
-		if ($shareByMail !== null) {
257
-			$shares[] = $shareByMail;
258
-		}
259
-		$shareByCircle = $this->getShareByCircleProvider();
260
-		if ($shareByCircle !== null) {
261
-			$shares[] = $shareByCircle;
262
-		}
263
-
264
-		return $shares;
265
-	}
148
+            $appManager = $this->serverContainer->getAppManager();
149
+            if (!$appManager->isEnabledForUser('sharebymail')) {
150
+                return null;
151
+            }
152
+
153
+            $settingsManager = new SettingsManager($this->serverContainer->getConfig());
154
+
155
+            $this->shareByMailProvider = new ShareByMailProvider(
156
+                $this->serverContainer->getDatabaseConnection(),
157
+                $this->serverContainer->getSecureRandom(),
158
+                $this->serverContainer->getUserManager(),
159
+                $this->serverContainer->getLazyRootFolder(),
160
+                $this->serverContainer->getL10N('sharebymail'),
161
+                $this->serverContainer->getLogger(),
162
+                $this->serverContainer->getMailer(),
163
+                $this->serverContainer->getURLGenerator(),
164
+                $this->serverContainer->getActivityManager(),
165
+                $settingsManager,
166
+                $this->serverContainer->getHasher()
167
+            );
168
+        }
169
+
170
+        return $this->shareByMailProvider;
171
+    }
172
+
173
+
174
+    /**
175
+     * Create the circle share provider
176
+     *
177
+     * @return FederatedShareProvider
178
+     */
179
+    protected function getShareByCircleProvider() {
180
+
181
+        $appManager = $this->serverContainer->getAppManager();
182
+        if (!$appManager->isEnabledForUser('circles')) {
183
+            return null;
184
+        }
185
+
186
+
187
+        if ($this->shareByCircleProvider === null) {
188
+
189
+            $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
190
+                $this->serverContainer->getDatabaseConnection(),
191
+                $this->serverContainer->getSecureRandom(),
192
+                $this->serverContainer->getUserManager(),
193
+                $this->serverContainer->getLazyRootFolder(),
194
+                $this->serverContainer->getL10N('circles'),
195
+                $this->serverContainer->getLogger(),
196
+                $this->serverContainer->getURLGenerator()
197
+            );
198
+        }
199
+
200
+        return $this->shareByCircleProvider;
201
+    }
202
+
203
+
204
+    /**
205
+     * @inheritdoc
206
+     */
207
+    public function getProvider($id) {
208
+        $provider = null;
209
+        if ($id === 'ocinternal') {
210
+            $provider = $this->defaultShareProvider();
211
+        } else if ($id === 'ocFederatedSharing') {
212
+            $provider = $this->federatedShareProvider();
213
+        } else if ($id === 'ocMailShare') {
214
+            $provider = $this->getShareByMailProvider();
215
+        } else if ($id === 'ocCircleShare') {
216
+            $provider = $this->getShareByCircleProvider();
217
+        }
218
+
219
+        if ($provider === null) {
220
+            throw new ProviderException('No provider with id .' . $id . ' found.');
221
+        }
222
+
223
+        return $provider;
224
+    }
225
+
226
+    /**
227
+     * @inheritdoc
228
+     */
229
+    public function getProviderForType($shareType) {
230
+        $provider = null;
231
+
232
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
233
+            $shareType === \OCP\Share::SHARE_TYPE_GROUP ||
234
+            $shareType === \OCP\Share::SHARE_TYPE_LINK
235
+        ) {
236
+            $provider = $this->defaultShareProvider();
237
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
238
+            $provider = $this->federatedShareProvider();
239
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
240
+            $provider = $this->getShareByMailProvider();
241
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
242
+            $provider = $this->getShareByCircleProvider();
243
+        }
244
+
245
+
246
+        if ($provider === null) {
247
+            throw new ProviderException('No share provider for share type ' . $shareType);
248
+        }
249
+
250
+        return $provider;
251
+    }
252
+
253
+    public function getAllProviders() {
254
+        $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];
255
+        $shareByMail = $this->getShareByMailProvider();
256
+        if ($shareByMail !== null) {
257
+            $shares[] = $shareByMail;
258
+        }
259
+        $shareByCircle = $this->getShareByCircleProvider();
260
+        if ($shareByCircle !== null) {
261
+            $shares[] = $shareByCircle;
262
+        }
263
+
264
+        return $shares;
265
+    }
266 266
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings/SettingsManager.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,35 +27,35 @@
 block discarded – undo
27 27
 
28 28
 class SettingsManager {
29 29
 
30
-	/** @var IConfig */
31
-	private $config;
32
-
33
-	private $sendPasswordByMailDefault = 'yes';
34
-
35
-	private $enforcePasswordProtectionDefault = 'no';
36
-
37
-	public function __construct(IConfig $config) {
38
-		$this->config = $config;
39
-	}
40
-
41
-	/**
42
-	 * should the password for a mail share be send to the recipient
43
-	 *
44
-	 * @return bool
45
-	 */
46
-	public function sendPasswordByMail() {
47
-		$sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
48
-		return $sendPasswordByMail === 'yes';
49
-	}
50
-
51
-	/**
52
-	 * do we require a share by mail to be password protected
53
-	 *
54
-	 * @return bool
55
-	 */
56
-	public function enforcePasswordProtection() {
57
-		$enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
58
-		return $enforcePassword === 'yes';
59
-	}
30
+    /** @var IConfig */
31
+    private $config;
32
+
33
+    private $sendPasswordByMailDefault = 'yes';
34
+
35
+    private $enforcePasswordProtectionDefault = 'no';
36
+
37
+    public function __construct(IConfig $config) {
38
+        $this->config = $config;
39
+    }
40
+
41
+    /**
42
+     * should the password for a mail share be send to the recipient
43
+     *
44
+     * @return bool
45
+     */
46
+    public function sendPasswordByMail() {
47
+        $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
48
+        return $sendPasswordByMail === 'yes';
49
+    }
50
+
51
+    /**
52
+     * do we require a share by mail to be password protected
53
+     *
54
+     * @return bool
55
+     */
56
+    public function enforcePasswordProtection() {
57
+        $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
58
+        return $enforcePassword === 'yes';
59
+    }
60 60
 
61 61
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings/Admin.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -27,42 +27,42 @@
 block discarded – undo
27 27
 
28 28
 class Admin implements ISettings {
29 29
 
30
-	/** @var SettingsManager */
31
-	private $settingsManager;
30
+    /** @var SettingsManager */
31
+    private $settingsManager;
32 32
 
33
-	public function __construct(SettingsManager $settingsManager) {
34
-		$this->settingsManager = $settingsManager;
35
-	}
33
+    public function __construct(SettingsManager $settingsManager) {
34
+        $this->settingsManager = $settingsManager;
35
+    }
36 36
 
37
-	/**
38
-	 * @return TemplateResponse
39
-	 */
40
-	public function getForm() {
37
+    /**
38
+     * @return TemplateResponse
39
+     */
40
+    public function getForm() {
41 41
 
42
-		$parameters = [
43
-			'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
44
-			'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
45
-		];
42
+        $parameters = [
43
+            'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
44
+            'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
45
+        ];
46 46
 
47
-		return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
48
-	}
47
+        return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
48
+    }
49 49
 
50
-	/**
51
-	 * @return string the section ID, e.g. 'sharing'
52
-	 */
53
-	public function getSection() {
54
-		return 'sharing';
55
-	}
50
+    /**
51
+     * @return string the section ID, e.g. 'sharing'
52
+     */
53
+    public function getSection() {
54
+        return 'sharing';
55
+    }
56 56
 
57
-	/**
58
-	 * @return int whether the form should be rather on the top or bottom of
59
-	 * the admin section. The forms are arranged in ascending order of the
60
-	 * priority values. It is required to return a value between 0 and 100.
61
-	 *
62
-	 * E.g.: 70
63
-	 */
64
-	public function getPriority() {
65
-		return 40;
66
-	}
57
+    /**
58
+     * @return int whether the form should be rather on the top or bottom of
59
+     * the admin section. The forms are arranged in ascending order of the
60
+     * priority values. It is required to return a value between 0 and 100.
61
+     *
62
+     * E.g.: 70
63
+     */
64
+    public function getPriority() {
65
+        return 40;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/AppInfo/Application.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,19 +29,19 @@
 block discarded – undo
29 29
 
30 30
 class Application extends App {
31 31
 
32
-	public function __construct(array $urlParams = array()) {
33
-		parent::__construct('sharebymail', $urlParams);
32
+    public function __construct(array $urlParams = array()) {
33
+        parent::__construct('sharebymail', $urlParams);
34 34
 
35
-		$settingsManager = new Settings\SettingsManager(\OC::$server->getConfig());
36
-		$settings = new Settings($settingsManager);
35
+        $settingsManager = new Settings\SettingsManager(\OC::$server->getConfig());
36
+        $settings = new Settings($settingsManager);
37 37
 
38
-		/** register capabilities */
39
-		$container = $this->getContainer();
40
-		$container->registerCapability('OCA\ShareByMail\Capabilities');
38
+        /** register capabilities */
39
+        $container = $this->getContainer();
40
+        $container->registerCapability('OCA\ShareByMail\Capabilities');
41 41
 
42
-		/** register hooks */
43
-		Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider');
44
-		Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings');
45
-	}
42
+        /** register hooks */
43
+        Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider');
44
+        Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings');
45
+    }
46 46
 
47 47
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -27,27 +27,27 @@
 block discarded – undo
27 27
 
28 28
 class Settings {
29 29
 
30
-	/** @var SettingsManager */
31
-	private $settingsManager;
32
-
33
-	public function __construct(SettingsManager $settingsManager) {
34
-		$this->settingsManager = $settingsManager;
35
-	}
36
-
37
-	/**
38
-	 * announce that the share-by-mail share provider is enabled
39
-	 *
40
-	 * @param array $settings
41
-	 */
42
-	public function announceShareProvider(array $settings) {
43
-		$array = json_decode($settings['array']['oc_appconfig'], true);
44
-		$array['shareByMailEnabled'] = true;
45
-		$settings['array']['oc_appconfig'] = json_encode($array);
46
-	}
47
-
48
-	public function announceShareByMailSettings(array $settings) {
49
-		$array = json_decode($settings['array']['oc_appconfig'], true);
50
-		$array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
51
-		$settings['array']['oc_appconfig'] = json_encode($array);
52
-	}
30
+    /** @var SettingsManager */
31
+    private $settingsManager;
32
+
33
+    public function __construct(SettingsManager $settingsManager) {
34
+        $this->settingsManager = $settingsManager;
35
+    }
36
+
37
+    /**
38
+     * announce that the share-by-mail share provider is enabled
39
+     *
40
+     * @param array $settings
41
+     */
42
+    public function announceShareProvider(array $settings) {
43
+        $array = json_decode($settings['array']['oc_appconfig'], true);
44
+        $array['shareByMailEnabled'] = true;
45
+        $settings['array']['oc_appconfig'] = json_encode($array);
46
+    }
47
+
48
+    public function announceShareByMailSettings(array $settings) {
49
+        $array = json_decode($settings['array']['oc_appconfig'], true);
50
+        $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
51
+        $settings['array']['oc_appconfig'] = json_encode($array);
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/sharebymail/templates/settings-admin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 	<em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em>
12 12
 
13 13
 	<p>
14
-		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> />
14
+		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if ($_['sendPasswordMail']) p('checked'); ?> />
15 15
 		<label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/>
16
-		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> />
16
+		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) p('checked'); ?> />
17 17
 		<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
18 18
 	</p>
19 19
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,15 @@
 block discarded – undo
11 11
 	<em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em>
12 12
 
13 13
 	<p>
14
-		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> />
14
+		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) {
15
+    p('checked');
16
+}
17
+?> />
15 18
 		<label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/>
16
-		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> />
19
+		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) {
20
+    p('checked');
21
+}
22
+?> />
17 23
 		<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
18 24
 	</p>
19 25
 
Please login to merge, or discard this patch.
apps/sharebymail/templates/mailpasswordowner.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@
 block discarded – undo
36 36
 					<td width="20px">&nbsp;</td>
37 37
 					<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
38 38
 						<?php
39
-						print_unescaped($l->t('Hey there,<br><br>you just shared »%s« with %s.<br>The share was already send to the recipient. Due to the security policies each share needs to be protected by email and it is not allowed to send the password directly by mail to the recipient. Therefore you need to forward the password manually to the recipient.<br><br>This is the password: %s<br><br>You can chose a different password at any time in the share dialog.<br><br>', [$_['filename'], $_['recipient'], $_['password']]));
40
-						// TRANSLATORS term at the end of a mail
41
-						p($l->t('Cheers!'));
42
-						?>
39
+                        print_unescaped($l->t('Hey there,<br><br>you just shared »%s« with %s.<br>The share was already send to the recipient. Due to the security policies each share needs to be protected by email and it is not allowed to send the password directly by mail to the recipient. Therefore you need to forward the password manually to the recipient.<br><br>This is the password: %s<br><br>You can chose a different password at any time in the share dialog.<br><br>', [$_['filename'], $_['recipient'], $_['password']]));
40
+                        // TRANSLATORS term at the end of a mail
41
+                        p($l->t('Cheers!'));
42
+                        ?>
43 43
 					</td>
44 44
 				</tr>
45 45
 				<tr><td colspan="2">&nbsp;</td></tr>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	<tr><td>
28 28
 			<table cellspacing="0" cellpadding="0" border="0" width="600px">
29 29
 				<tr>
30
-					<td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>">
30
+					<td colspan="2" bgcolor="<?php p($theme->getColorPrimary()); ?>">
31 31
 						<img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
32 32
 					</td>
33 33
 				</tr>
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 					<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
53 53
 						<?php p($theme->getName()); ?> -
54 54
 						<?php p($theme->getSlogan()); ?>
55
-						<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a>
55
+						<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl()); ?></a>
56 56
 					</td>
57 57
 				</tr>
58 58
 				<tr>
Please login to merge, or discard this patch.
apps/sharebymail/templates/altmail.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,5 +32,5 @@
 block discarded – undo
32 32
 ?>
33 33
 
34 34
 <?php print_unescaped("-- \n"); ?>
35
-<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
35
+<?php p($theme->getName().' - '.$theme->getSlogan()); ?>
36 36
 <?php print_unescaped("\n".$theme->getBaseUrl());
Please login to merge, or discard this patch.