@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * publish activity if a file/folder was shared by mail |
194 | 194 | * |
195 | 195 | * @param $subject |
196 | - * @param $parameters |
|
197 | - * @param $affectedUser |
|
196 | + * @param string[] $parameters |
|
197 | + * @param string $affectedUser |
|
198 | 198 | * @param $fileId |
199 | - * @param $filePath |
|
199 | + * @param string $filePath |
|
200 | 200 | */ |
201 | 201 | protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
202 | 202 | $event = $this->activityManager->generateEvent(); |
@@ -248,6 +248,12 @@ discard block |
||
248 | 248 | |
249 | 249 | } |
250 | 250 | |
251 | + /** |
|
252 | + * @param string $link |
|
253 | + * @param string $owner |
|
254 | + * @param string $initiator |
|
255 | + * @param string $shareWith |
|
256 | + */ |
|
251 | 257 | protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
252 | 258 | $ownerUser = $this->userManager->get($owner); |
253 | 259 | $initiatorUser = $this->userManager->get($initiator); |
@@ -296,6 +302,7 @@ discard block |
||
296 | 302 | * @param string $filename |
297 | 303 | * @param string $initiator |
298 | 304 | * @param string $shareWith |
305 | + * @param string $password |
|
299 | 306 | */ |
300 | 307 | protected function sendPassword($filename, $initiator, $shareWith, $password) { |
301 | 308 | |
@@ -769,7 +776,7 @@ discard block |
||
769 | 776 | /** |
770 | 777 | * get database row of a give share |
771 | 778 | * |
772 | - * @param $id |
|
779 | + * @param integer $id |
|
773 | 780 | * @return array |
774 | 781 | * @throws ShareNotFound |
775 | 782 | */ |
@@ -41,7 +41,6 @@ |
||
41 | 41 | use OCP\Share\Exceptions\ShareNotFound; |
42 | 42 | use OCP\Share\IShare; |
43 | 43 | use OCP\Share\IShareProvider; |
44 | -use OCP\Template; |
|
45 | 44 | |
46 | 45 | /** |
47 | 46 | * Class ShareByMail |
@@ -50,787 +50,787 @@ |
||
50 | 50 | */ |
51 | 51 | class ShareByMailProvider implements IShareProvider { |
52 | 52 | |
53 | - /** @var IDBConnection */ |
|
54 | - private $dbConnection; |
|
55 | - |
|
56 | - /** @var ILogger */ |
|
57 | - private $logger; |
|
58 | - |
|
59 | - /** @var ISecureRandom */ |
|
60 | - private $secureRandom; |
|
61 | - |
|
62 | - /** @var IUserManager */ |
|
63 | - private $userManager; |
|
64 | - |
|
65 | - /** @var IRootFolder */ |
|
66 | - private $rootFolder; |
|
67 | - |
|
68 | - /** @var IL10N */ |
|
69 | - private $l; |
|
70 | - |
|
71 | - /** @var IMailer */ |
|
72 | - private $mailer; |
|
73 | - |
|
74 | - /** @var IURLGenerator */ |
|
75 | - private $urlGenerator; |
|
76 | - |
|
77 | - /** @var IManager */ |
|
78 | - private $activityManager; |
|
79 | - |
|
80 | - /** @var SettingsManager */ |
|
81 | - private $settingsManager; |
|
82 | - |
|
83 | - /** |
|
84 | - * Return the identifier of this provider. |
|
85 | - * |
|
86 | - * @return string Containing only [a-zA-Z0-9] |
|
87 | - */ |
|
88 | - public function identifier() { |
|
89 | - return 'ocMailShare'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * DefaultShareProvider constructor. |
|
94 | - * |
|
95 | - * @param IDBConnection $connection |
|
96 | - * @param ISecureRandom $secureRandom |
|
97 | - * @param IUserManager $userManager |
|
98 | - * @param IRootFolder $rootFolder |
|
99 | - * @param IL10N $l |
|
100 | - * @param ILogger $logger |
|
101 | - * @param IMailer $mailer |
|
102 | - * @param IURLGenerator $urlGenerator |
|
103 | - * @param IManager $activityManager |
|
104 | - * @param SettingsManager $settingsManager |
|
105 | - */ |
|
106 | - public function __construct( |
|
107 | - IDBConnection $connection, |
|
108 | - ISecureRandom $secureRandom, |
|
109 | - IUserManager $userManager, |
|
110 | - IRootFolder $rootFolder, |
|
111 | - IL10N $l, |
|
112 | - ILogger $logger, |
|
113 | - IMailer $mailer, |
|
114 | - IURLGenerator $urlGenerator, |
|
115 | - IManager $activityManager, |
|
116 | - SettingsManager $settingsManager |
|
117 | - ) { |
|
118 | - $this->dbConnection = $connection; |
|
119 | - $this->secureRandom = $secureRandom; |
|
120 | - $this->userManager = $userManager; |
|
121 | - $this->rootFolder = $rootFolder; |
|
122 | - $this->l = $l; |
|
123 | - $this->logger = $logger; |
|
124 | - $this->mailer = $mailer; |
|
125 | - $this->urlGenerator = $urlGenerator; |
|
126 | - $this->activityManager = $activityManager; |
|
127 | - $this->settingsManager = $settingsManager; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Share a path |
|
132 | - * |
|
133 | - * @param IShare $share |
|
134 | - * @return IShare The share object |
|
135 | - * @throws ShareNotFound |
|
136 | - * @throws \Exception |
|
137 | - */ |
|
138 | - public function create(IShare $share) { |
|
139 | - |
|
140 | - $shareWith = $share->getSharedWith(); |
|
141 | - /* |
|
53 | + /** @var IDBConnection */ |
|
54 | + private $dbConnection; |
|
55 | + |
|
56 | + /** @var ILogger */ |
|
57 | + private $logger; |
|
58 | + |
|
59 | + /** @var ISecureRandom */ |
|
60 | + private $secureRandom; |
|
61 | + |
|
62 | + /** @var IUserManager */ |
|
63 | + private $userManager; |
|
64 | + |
|
65 | + /** @var IRootFolder */ |
|
66 | + private $rootFolder; |
|
67 | + |
|
68 | + /** @var IL10N */ |
|
69 | + private $l; |
|
70 | + |
|
71 | + /** @var IMailer */ |
|
72 | + private $mailer; |
|
73 | + |
|
74 | + /** @var IURLGenerator */ |
|
75 | + private $urlGenerator; |
|
76 | + |
|
77 | + /** @var IManager */ |
|
78 | + private $activityManager; |
|
79 | + |
|
80 | + /** @var SettingsManager */ |
|
81 | + private $settingsManager; |
|
82 | + |
|
83 | + /** |
|
84 | + * Return the identifier of this provider. |
|
85 | + * |
|
86 | + * @return string Containing only [a-zA-Z0-9] |
|
87 | + */ |
|
88 | + public function identifier() { |
|
89 | + return 'ocMailShare'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * DefaultShareProvider constructor. |
|
94 | + * |
|
95 | + * @param IDBConnection $connection |
|
96 | + * @param ISecureRandom $secureRandom |
|
97 | + * @param IUserManager $userManager |
|
98 | + * @param IRootFolder $rootFolder |
|
99 | + * @param IL10N $l |
|
100 | + * @param ILogger $logger |
|
101 | + * @param IMailer $mailer |
|
102 | + * @param IURLGenerator $urlGenerator |
|
103 | + * @param IManager $activityManager |
|
104 | + * @param SettingsManager $settingsManager |
|
105 | + */ |
|
106 | + public function __construct( |
|
107 | + IDBConnection $connection, |
|
108 | + ISecureRandom $secureRandom, |
|
109 | + IUserManager $userManager, |
|
110 | + IRootFolder $rootFolder, |
|
111 | + IL10N $l, |
|
112 | + ILogger $logger, |
|
113 | + IMailer $mailer, |
|
114 | + IURLGenerator $urlGenerator, |
|
115 | + IManager $activityManager, |
|
116 | + SettingsManager $settingsManager |
|
117 | + ) { |
|
118 | + $this->dbConnection = $connection; |
|
119 | + $this->secureRandom = $secureRandom; |
|
120 | + $this->userManager = $userManager; |
|
121 | + $this->rootFolder = $rootFolder; |
|
122 | + $this->l = $l; |
|
123 | + $this->logger = $logger; |
|
124 | + $this->mailer = $mailer; |
|
125 | + $this->urlGenerator = $urlGenerator; |
|
126 | + $this->activityManager = $activityManager; |
|
127 | + $this->settingsManager = $settingsManager; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Share a path |
|
132 | + * |
|
133 | + * @param IShare $share |
|
134 | + * @return IShare The share object |
|
135 | + * @throws ShareNotFound |
|
136 | + * @throws \Exception |
|
137 | + */ |
|
138 | + public function create(IShare $share) { |
|
139 | + |
|
140 | + $shareWith = $share->getSharedWith(); |
|
141 | + /* |
|
142 | 142 | * Check if file is not already shared with the remote user |
143 | 143 | */ |
144 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
145 | - if (!empty($alreadyShared)) { |
|
146 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
147 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
148 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
149 | - throw new \Exception($message_t); |
|
150 | - } |
|
151 | - |
|
152 | - $shareId = $this->createMailShare($share); |
|
153 | - $this->createActivity($share); |
|
154 | - $data = $this->getRawShare($shareId); |
|
155 | - return $this->createShareObject($data); |
|
156 | - |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * create activity if a file/folder was shared by mail |
|
161 | - * |
|
162 | - * @param IShare $share |
|
163 | - */ |
|
164 | - protected function createActivity(IShare $share) { |
|
165 | - |
|
166 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
167 | - |
|
168 | - $this->publishActivity( |
|
169 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
170 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
171 | - $share->getSharedBy(), |
|
172 | - $share->getNode()->getId(), |
|
173 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
174 | - ); |
|
175 | - |
|
176 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
177 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
178 | - $fileId = $share->getNode()->getId(); |
|
179 | - $nodes = $ownerFolder->getById($fileId); |
|
180 | - $ownerPath = $nodes[0]->getPath(); |
|
181 | - $this->publishActivity( |
|
182 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
183 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
184 | - $share->getShareOwner(), |
|
185 | - $fileId, |
|
186 | - $ownerFolder->getRelativePath($ownerPath) |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * publish activity if a file/folder was shared by mail |
|
194 | - * |
|
195 | - * @param $subject |
|
196 | - * @param $parameters |
|
197 | - * @param $affectedUser |
|
198 | - * @param $fileId |
|
199 | - * @param $filePath |
|
200 | - */ |
|
201 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
202 | - $event = $this->activityManager->generateEvent(); |
|
203 | - $event->setApp('sharebymail') |
|
204 | - ->setType('shared') |
|
205 | - ->setSubject($subject, $parameters) |
|
206 | - ->setAffectedUser($affectedUser) |
|
207 | - ->setObject('files', $fileId, $filePath); |
|
208 | - $this->activityManager->publish($event); |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param IShare $share |
|
214 | - * @return int |
|
215 | - * @throws \Exception |
|
216 | - */ |
|
217 | - protected function createMailShare(IShare $share) { |
|
218 | - $share->setToken($this->generateToken()); |
|
219 | - $shareId = $this->addShareToDB( |
|
220 | - $share->getNodeId(), |
|
221 | - $share->getNodeType(), |
|
222 | - $share->getSharedWith(), |
|
223 | - $share->getSharedBy(), |
|
224 | - $share->getShareOwner(), |
|
225 | - $share->getPermissions(), |
|
226 | - $share->getToken() |
|
227 | - ); |
|
228 | - |
|
229 | - try { |
|
230 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
231 | - ['token' => $share->getToken()]); |
|
232 | - $this->sendMailNotification($share->getNode()->getName(), |
|
233 | - $link, |
|
234 | - $share->getShareOwner(), |
|
235 | - $share->getSharedBy(), $share->getSharedWith()); |
|
236 | - } catch (HintException $hintException) { |
|
237 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
238 | - $this->removeShareFromTable($shareId); |
|
239 | - throw $hintException; |
|
240 | - } catch (\Exception $e) { |
|
241 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
242 | - $this->removeShareFromTable($shareId); |
|
243 | - throw new HintException('Failed to send share by mail', |
|
244 | - $this->l->t('Failed to send share by E-mail')); |
|
245 | - } |
|
246 | - |
|
247 | - return $shareId; |
|
248 | - |
|
249 | - } |
|
250 | - |
|
251 | - protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
|
252 | - $ownerUser = $this->userManager->get($owner); |
|
253 | - $initiatorUser = $this->userManager->get($initiator); |
|
254 | - $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
255 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
256 | - if ($owner === $initiator) { |
|
257 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
258 | - } else { |
|
259 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
260 | - } |
|
261 | - |
|
262 | - $message = $this->mailer->createMessage(); |
|
263 | - |
|
264 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
265 | - |
|
266 | - $emailTemplate->addHeader(); |
|
267 | - $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename])); |
|
268 | - |
|
269 | - if ($owner === $initiator) { |
|
270 | - $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
|
271 | - } else { |
|
272 | - $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
273 | - } |
|
274 | - |
|
275 | - $text .= ' ' . $this->l->t('Click the button below to open it.'); |
|
276 | - |
|
277 | - $emailTemplate->addBodyText($text); |
|
278 | - |
|
279 | - $emailTemplate->addBodyButton( |
|
280 | - $this->l->t('Open »%s«', [$filename]), |
|
281 | - $link |
|
282 | - ); |
|
283 | - $emailTemplate->addFooter(); |
|
284 | - |
|
285 | - $message->setTo([$shareWith]); |
|
286 | - $message->setSubject($subject); |
|
287 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
288 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
289 | - $this->mailer->send($message); |
|
290 | - |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * send password to recipient of a mail share |
|
295 | - * |
|
296 | - * @param string $filename |
|
297 | - * @param string $initiator |
|
298 | - * @param string $shareWith |
|
299 | - */ |
|
300 | - protected function sendPassword($filename, $initiator, $shareWith, $password) { |
|
301 | - |
|
302 | - if ($this->settingsManager->sendPasswordByMail() === false) { |
|
303 | - return; |
|
304 | - } |
|
305 | - |
|
306 | - $initiatorUser = $this->userManager->get($initiator); |
|
307 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
308 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
309 | - |
|
310 | - $message = $this->mailer->createMessage(); |
|
311 | - |
|
312 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
313 | - |
|
314 | - $emailTemplate->addHeader(); |
|
315 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); |
|
316 | - |
|
317 | - $emailTemplate->addBodyText($this->l->t( |
|
318 | - '%s shared »%s« with you. You should have already received a separate mail with a link to access it.', |
|
319 | - [$initiatorDisplayName, $filename] |
|
320 | - )); |
|
321 | - $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
322 | - |
|
323 | - $emailTemplate->addFooter(); |
|
324 | - |
|
325 | - $message->setTo([$shareWith]); |
|
326 | - $message->setSubject($subject); |
|
327 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
328 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
329 | - $this->mailer->send($message); |
|
330 | - |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * generate share token |
|
336 | - * |
|
337 | - * @return string |
|
338 | - */ |
|
339 | - protected function generateToken() { |
|
340 | - $token = $this->secureRandom->generate( |
|
341 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
342 | - return $token; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Get all children of this share |
|
347 | - * |
|
348 | - * @param IShare $parent |
|
349 | - * @return IShare[] |
|
350 | - */ |
|
351 | - public function getChildren(IShare $parent) { |
|
352 | - $children = []; |
|
353 | - |
|
354 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
355 | - $qb->select('*') |
|
356 | - ->from('share') |
|
357 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
358 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
359 | - ->orderBy('id'); |
|
360 | - |
|
361 | - $cursor = $qb->execute(); |
|
362 | - while($data = $cursor->fetch()) { |
|
363 | - $children[] = $this->createShareObject($data); |
|
364 | - } |
|
365 | - $cursor->closeCursor(); |
|
366 | - |
|
367 | - return $children; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * add share to the database and return the ID |
|
372 | - * |
|
373 | - * @param int $itemSource |
|
374 | - * @param string $itemType |
|
375 | - * @param string $shareWith |
|
376 | - * @param string $sharedBy |
|
377 | - * @param string $uidOwner |
|
378 | - * @param int $permissions |
|
379 | - * @param string $token |
|
380 | - * @return int |
|
381 | - */ |
|
382 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
383 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
384 | - $qb->insert('share') |
|
385 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
386 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
387 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
388 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
389 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
390 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
391 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
392 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
393 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
394 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
395 | - |
|
396 | - /* |
|
144 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
145 | + if (!empty($alreadyShared)) { |
|
146 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
147 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
148 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
149 | + throw new \Exception($message_t); |
|
150 | + } |
|
151 | + |
|
152 | + $shareId = $this->createMailShare($share); |
|
153 | + $this->createActivity($share); |
|
154 | + $data = $this->getRawShare($shareId); |
|
155 | + return $this->createShareObject($data); |
|
156 | + |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * create activity if a file/folder was shared by mail |
|
161 | + * |
|
162 | + * @param IShare $share |
|
163 | + */ |
|
164 | + protected function createActivity(IShare $share) { |
|
165 | + |
|
166 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
167 | + |
|
168 | + $this->publishActivity( |
|
169 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
170 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
171 | + $share->getSharedBy(), |
|
172 | + $share->getNode()->getId(), |
|
173 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
174 | + ); |
|
175 | + |
|
176 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
177 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
178 | + $fileId = $share->getNode()->getId(); |
|
179 | + $nodes = $ownerFolder->getById($fileId); |
|
180 | + $ownerPath = $nodes[0]->getPath(); |
|
181 | + $this->publishActivity( |
|
182 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
183 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
184 | + $share->getShareOwner(), |
|
185 | + $fileId, |
|
186 | + $ownerFolder->getRelativePath($ownerPath) |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * publish activity if a file/folder was shared by mail |
|
194 | + * |
|
195 | + * @param $subject |
|
196 | + * @param $parameters |
|
197 | + * @param $affectedUser |
|
198 | + * @param $fileId |
|
199 | + * @param $filePath |
|
200 | + */ |
|
201 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
202 | + $event = $this->activityManager->generateEvent(); |
|
203 | + $event->setApp('sharebymail') |
|
204 | + ->setType('shared') |
|
205 | + ->setSubject($subject, $parameters) |
|
206 | + ->setAffectedUser($affectedUser) |
|
207 | + ->setObject('files', $fileId, $filePath); |
|
208 | + $this->activityManager->publish($event); |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param IShare $share |
|
214 | + * @return int |
|
215 | + * @throws \Exception |
|
216 | + */ |
|
217 | + protected function createMailShare(IShare $share) { |
|
218 | + $share->setToken($this->generateToken()); |
|
219 | + $shareId = $this->addShareToDB( |
|
220 | + $share->getNodeId(), |
|
221 | + $share->getNodeType(), |
|
222 | + $share->getSharedWith(), |
|
223 | + $share->getSharedBy(), |
|
224 | + $share->getShareOwner(), |
|
225 | + $share->getPermissions(), |
|
226 | + $share->getToken() |
|
227 | + ); |
|
228 | + |
|
229 | + try { |
|
230 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
231 | + ['token' => $share->getToken()]); |
|
232 | + $this->sendMailNotification($share->getNode()->getName(), |
|
233 | + $link, |
|
234 | + $share->getShareOwner(), |
|
235 | + $share->getSharedBy(), $share->getSharedWith()); |
|
236 | + } catch (HintException $hintException) { |
|
237 | + $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
238 | + $this->removeShareFromTable($shareId); |
|
239 | + throw $hintException; |
|
240 | + } catch (\Exception $e) { |
|
241 | + $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
242 | + $this->removeShareFromTable($shareId); |
|
243 | + throw new HintException('Failed to send share by mail', |
|
244 | + $this->l->t('Failed to send share by E-mail')); |
|
245 | + } |
|
246 | + |
|
247 | + return $shareId; |
|
248 | + |
|
249 | + } |
|
250 | + |
|
251 | + protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) { |
|
252 | + $ownerUser = $this->userManager->get($owner); |
|
253 | + $initiatorUser = $this->userManager->get($initiator); |
|
254 | + $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
255 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
256 | + if ($owner === $initiator) { |
|
257 | + $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
258 | + } else { |
|
259 | + $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
260 | + } |
|
261 | + |
|
262 | + $message = $this->mailer->createMessage(); |
|
263 | + |
|
264 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
265 | + |
|
266 | + $emailTemplate->addHeader(); |
|
267 | + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename])); |
|
268 | + |
|
269 | + if ($owner === $initiator) { |
|
270 | + $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
|
271 | + } else { |
|
272 | + $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
273 | + } |
|
274 | + |
|
275 | + $text .= ' ' . $this->l->t('Click the button below to open it.'); |
|
276 | + |
|
277 | + $emailTemplate->addBodyText($text); |
|
278 | + |
|
279 | + $emailTemplate->addBodyButton( |
|
280 | + $this->l->t('Open »%s«', [$filename]), |
|
281 | + $link |
|
282 | + ); |
|
283 | + $emailTemplate->addFooter(); |
|
284 | + |
|
285 | + $message->setTo([$shareWith]); |
|
286 | + $message->setSubject($subject); |
|
287 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
288 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
289 | + $this->mailer->send($message); |
|
290 | + |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * send password to recipient of a mail share |
|
295 | + * |
|
296 | + * @param string $filename |
|
297 | + * @param string $initiator |
|
298 | + * @param string $shareWith |
|
299 | + */ |
|
300 | + protected function sendPassword($filename, $initiator, $shareWith, $password) { |
|
301 | + |
|
302 | + if ($this->settingsManager->sendPasswordByMail() === false) { |
|
303 | + return; |
|
304 | + } |
|
305 | + |
|
306 | + $initiatorUser = $this->userManager->get($initiator); |
|
307 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
308 | + $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
309 | + |
|
310 | + $message = $this->mailer->createMessage(); |
|
311 | + |
|
312 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
313 | + |
|
314 | + $emailTemplate->addHeader(); |
|
315 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); |
|
316 | + |
|
317 | + $emailTemplate->addBodyText($this->l->t( |
|
318 | + '%s shared »%s« with you. You should have already received a separate mail with a link to access it.', |
|
319 | + [$initiatorDisplayName, $filename] |
|
320 | + )); |
|
321 | + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
322 | + |
|
323 | + $emailTemplate->addFooter(); |
|
324 | + |
|
325 | + $message->setTo([$shareWith]); |
|
326 | + $message->setSubject($subject); |
|
327 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
328 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
329 | + $this->mailer->send($message); |
|
330 | + |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * generate share token |
|
336 | + * |
|
337 | + * @return string |
|
338 | + */ |
|
339 | + protected function generateToken() { |
|
340 | + $token = $this->secureRandom->generate( |
|
341 | + 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
342 | + return $token; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Get all children of this share |
|
347 | + * |
|
348 | + * @param IShare $parent |
|
349 | + * @return IShare[] |
|
350 | + */ |
|
351 | + public function getChildren(IShare $parent) { |
|
352 | + $children = []; |
|
353 | + |
|
354 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
355 | + $qb->select('*') |
|
356 | + ->from('share') |
|
357 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
358 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
359 | + ->orderBy('id'); |
|
360 | + |
|
361 | + $cursor = $qb->execute(); |
|
362 | + while($data = $cursor->fetch()) { |
|
363 | + $children[] = $this->createShareObject($data); |
|
364 | + } |
|
365 | + $cursor->closeCursor(); |
|
366 | + |
|
367 | + return $children; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * add share to the database and return the ID |
|
372 | + * |
|
373 | + * @param int $itemSource |
|
374 | + * @param string $itemType |
|
375 | + * @param string $shareWith |
|
376 | + * @param string $sharedBy |
|
377 | + * @param string $uidOwner |
|
378 | + * @param int $permissions |
|
379 | + * @param string $token |
|
380 | + * @return int |
|
381 | + */ |
|
382 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
383 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
384 | + $qb->insert('share') |
|
385 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
386 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
387 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
388 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
389 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
390 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
391 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
392 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
393 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
394 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
395 | + |
|
396 | + /* |
|
397 | 397 | * Added to fix https://github.com/owncloud/core/issues/22215 |
398 | 398 | * Can be removed once we get rid of ajax/share.php |
399 | 399 | */ |
400 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
400 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
401 | 401 | |
402 | - $qb->execute(); |
|
403 | - $id = $qb->getLastInsertId(); |
|
402 | + $qb->execute(); |
|
403 | + $id = $qb->getLastInsertId(); |
|
404 | 404 | |
405 | - return (int)$id; |
|
406 | - } |
|
405 | + return (int)$id; |
|
406 | + } |
|
407 | 407 | |
408 | - /** |
|
409 | - * Update a share |
|
410 | - * |
|
411 | - * @param IShare $share |
|
412 | - * @param string|null $plainTextPassword |
|
413 | - * @return IShare The share object |
|
414 | - */ |
|
415 | - public function update(IShare $share, $plainTextPassword = null) { |
|
408 | + /** |
|
409 | + * Update a share |
|
410 | + * |
|
411 | + * @param IShare $share |
|
412 | + * @param string|null $plainTextPassword |
|
413 | + * @return IShare The share object |
|
414 | + */ |
|
415 | + public function update(IShare $share, $plainTextPassword = null) { |
|
416 | 416 | |
417 | - $originalShare = $this->getShareById($share->getId()); |
|
417 | + $originalShare = $this->getShareById($share->getId()); |
|
418 | 418 | |
419 | - // a real password was given |
|
420 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
419 | + // a real password was given |
|
420 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
421 | 421 | |
422 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
423 | - $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
|
424 | - } |
|
425 | - /* |
|
422 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
423 | + $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
|
424 | + } |
|
425 | + /* |
|
426 | 426 | * We allow updating the permissions and password of mail shares |
427 | 427 | */ |
428 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
429 | - $qb->update('share') |
|
430 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
431 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
432 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
433 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
434 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
435 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
436 | - ->execute(); |
|
437 | - |
|
438 | - return $share; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * @inheritdoc |
|
443 | - */ |
|
444 | - public function move(IShare $share, $recipient) { |
|
445 | - /** |
|
446 | - * nothing to do here, mail shares are only outgoing shares |
|
447 | - */ |
|
448 | - return $share; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Delete a share (owner unShares the file) |
|
453 | - * |
|
454 | - * @param IShare $share |
|
455 | - */ |
|
456 | - public function delete(IShare $share) { |
|
457 | - $this->removeShareFromTable($share->getId()); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * @inheritdoc |
|
462 | - */ |
|
463 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
464 | - // nothing to do here, mail shares are only outgoing shares |
|
465 | - return; |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * @inheritdoc |
|
470 | - */ |
|
471 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
472 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
473 | - $qb->select('*') |
|
474 | - ->from('share'); |
|
475 | - |
|
476 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
477 | - |
|
478 | - /** |
|
479 | - * Reshares for this user are shares where they are the owner. |
|
480 | - */ |
|
481 | - if ($reshares === false) { |
|
482 | - //Special case for old shares created via the web UI |
|
483 | - $or1 = $qb->expr()->andX( |
|
484 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
485 | - $qb->expr()->isNull('uid_initiator') |
|
486 | - ); |
|
487 | - |
|
488 | - $qb->andWhere( |
|
489 | - $qb->expr()->orX( |
|
490 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
491 | - $or1 |
|
492 | - ) |
|
493 | - ); |
|
494 | - } else { |
|
495 | - $qb->andWhere( |
|
496 | - $qb->expr()->orX( |
|
497 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
498 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
499 | - ) |
|
500 | - ); |
|
501 | - } |
|
502 | - |
|
503 | - if ($node !== null) { |
|
504 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
505 | - } |
|
506 | - |
|
507 | - if ($limit !== -1) { |
|
508 | - $qb->setMaxResults($limit); |
|
509 | - } |
|
510 | - |
|
511 | - $qb->setFirstResult($offset); |
|
512 | - $qb->orderBy('id'); |
|
513 | - |
|
514 | - $cursor = $qb->execute(); |
|
515 | - $shares = []; |
|
516 | - while($data = $cursor->fetch()) { |
|
517 | - $shares[] = $this->createShareObject($data); |
|
518 | - } |
|
519 | - $cursor->closeCursor(); |
|
520 | - |
|
521 | - return $shares; |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * @inheritdoc |
|
526 | - */ |
|
527 | - public function getShareById($id, $recipientId = null) { |
|
528 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
529 | - |
|
530 | - $qb->select('*') |
|
531 | - ->from('share') |
|
532 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
533 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
534 | - |
|
535 | - $cursor = $qb->execute(); |
|
536 | - $data = $cursor->fetch(); |
|
537 | - $cursor->closeCursor(); |
|
538 | - |
|
539 | - if ($data === false) { |
|
540 | - throw new ShareNotFound(); |
|
541 | - } |
|
542 | - |
|
543 | - try { |
|
544 | - $share = $this->createShareObject($data); |
|
545 | - } catch (InvalidShare $e) { |
|
546 | - throw new ShareNotFound(); |
|
547 | - } |
|
548 | - |
|
549 | - return $share; |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * Get shares for a given path |
|
554 | - * |
|
555 | - * @param \OCP\Files\Node $path |
|
556 | - * @return IShare[] |
|
557 | - */ |
|
558 | - public function getSharesByPath(Node $path) { |
|
559 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
560 | - |
|
561 | - $cursor = $qb->select('*') |
|
562 | - ->from('share') |
|
563 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
564 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
565 | - ->execute(); |
|
566 | - |
|
567 | - $shares = []; |
|
568 | - while($data = $cursor->fetch()) { |
|
569 | - $shares[] = $this->createShareObject($data); |
|
570 | - } |
|
571 | - $cursor->closeCursor(); |
|
572 | - |
|
573 | - return $shares; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * @inheritdoc |
|
578 | - */ |
|
579 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
580 | - /** @var IShare[] $shares */ |
|
581 | - $shares = []; |
|
582 | - |
|
583 | - //Get shares directly with this user |
|
584 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
585 | - $qb->select('*') |
|
586 | - ->from('share'); |
|
587 | - |
|
588 | - // Order by id |
|
589 | - $qb->orderBy('id'); |
|
590 | - |
|
591 | - // Set limit and offset |
|
592 | - if ($limit !== -1) { |
|
593 | - $qb->setMaxResults($limit); |
|
594 | - } |
|
595 | - $qb->setFirstResult($offset); |
|
596 | - |
|
597 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
598 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
599 | - |
|
600 | - // Filter by node if provided |
|
601 | - if ($node !== null) { |
|
602 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
603 | - } |
|
604 | - |
|
605 | - $cursor = $qb->execute(); |
|
606 | - |
|
607 | - while($data = $cursor->fetch()) { |
|
608 | - $shares[] = $this->createShareObject($data); |
|
609 | - } |
|
610 | - $cursor->closeCursor(); |
|
611 | - |
|
612 | - |
|
613 | - return $shares; |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Get a share by token |
|
618 | - * |
|
619 | - * @param string $token |
|
620 | - * @return IShare |
|
621 | - * @throws ShareNotFound |
|
622 | - */ |
|
623 | - public function getShareByToken($token) { |
|
624 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
625 | - |
|
626 | - $cursor = $qb->select('*') |
|
627 | - ->from('share') |
|
628 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
629 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
630 | - ->execute(); |
|
631 | - |
|
632 | - $data = $cursor->fetch(); |
|
633 | - |
|
634 | - if ($data === false) { |
|
635 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
636 | - } |
|
637 | - |
|
638 | - try { |
|
639 | - $share = $this->createShareObject($data); |
|
640 | - } catch (InvalidShare $e) { |
|
641 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
642 | - } |
|
643 | - |
|
644 | - return $share; |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * remove share from table |
|
649 | - * |
|
650 | - * @param string $shareId |
|
651 | - */ |
|
652 | - protected function removeShareFromTable($shareId) { |
|
653 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
654 | - $qb->delete('share') |
|
655 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
656 | - $qb->execute(); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Create a share object from an database row |
|
661 | - * |
|
662 | - * @param array $data |
|
663 | - * @return IShare |
|
664 | - * @throws InvalidShare |
|
665 | - * @throws ShareNotFound |
|
666 | - */ |
|
667 | - protected function createShareObject($data) { |
|
668 | - |
|
669 | - $share = new Share($this->rootFolder, $this->userManager); |
|
670 | - $share->setId((int)$data['id']) |
|
671 | - ->setShareType((int)$data['share_type']) |
|
672 | - ->setPermissions((int)$data['permissions']) |
|
673 | - ->setTarget($data['file_target']) |
|
674 | - ->setMailSend((bool)$data['mail_send']) |
|
675 | - ->setToken($data['token']); |
|
676 | - |
|
677 | - $shareTime = new \DateTime(); |
|
678 | - $shareTime->setTimestamp((int)$data['stime']); |
|
679 | - $share->setShareTime($shareTime); |
|
680 | - $share->setSharedWith($data['share_with']); |
|
681 | - $share->setPassword($data['password']); |
|
682 | - |
|
683 | - if ($data['uid_initiator'] !== null) { |
|
684 | - $share->setShareOwner($data['uid_owner']); |
|
685 | - $share->setSharedBy($data['uid_initiator']); |
|
686 | - } else { |
|
687 | - //OLD SHARE |
|
688 | - $share->setSharedBy($data['uid_owner']); |
|
689 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
690 | - |
|
691 | - $owner = $path->getOwner(); |
|
692 | - $share->setShareOwner($owner->getUID()); |
|
693 | - } |
|
694 | - |
|
695 | - if ($data['expiration'] !== null) { |
|
696 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
697 | - if ($expiration !== false) { |
|
698 | - $share->setExpirationDate($expiration); |
|
699 | - } |
|
700 | - } |
|
701 | - |
|
702 | - $share->setNodeId((int)$data['file_source']); |
|
703 | - $share->setNodeType($data['item_type']); |
|
704 | - |
|
705 | - $share->setProviderId($this->identifier()); |
|
706 | - |
|
707 | - return $share; |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Get the node with file $id for $user |
|
712 | - * |
|
713 | - * @param string $userId |
|
714 | - * @param int $id |
|
715 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
716 | - * @throws InvalidShare |
|
717 | - */ |
|
718 | - private function getNode($userId, $id) { |
|
719 | - try { |
|
720 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
721 | - } catch (NotFoundException $e) { |
|
722 | - throw new InvalidShare(); |
|
723 | - } |
|
724 | - |
|
725 | - $nodes = $userFolder->getById($id); |
|
726 | - |
|
727 | - if (empty($nodes)) { |
|
728 | - throw new InvalidShare(); |
|
729 | - } |
|
730 | - |
|
731 | - return $nodes[0]; |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * A user is deleted from the system |
|
736 | - * So clean up the relevant shares. |
|
737 | - * |
|
738 | - * @param string $uid |
|
739 | - * @param int $shareType |
|
740 | - */ |
|
741 | - public function userDeleted($uid, $shareType) { |
|
742 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
743 | - |
|
744 | - $qb->delete('share') |
|
745 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
746 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
747 | - ->execute(); |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * This provider does not support group shares |
|
752 | - * |
|
753 | - * @param string $gid |
|
754 | - */ |
|
755 | - public function groupDeleted($gid) { |
|
756 | - return; |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * This provider does not support group shares |
|
761 | - * |
|
762 | - * @param string $uid |
|
763 | - * @param string $gid |
|
764 | - */ |
|
765 | - public function userDeletedFromGroup($uid, $gid) { |
|
766 | - return; |
|
767 | - } |
|
768 | - |
|
769 | - /** |
|
770 | - * get database row of a give share |
|
771 | - * |
|
772 | - * @param $id |
|
773 | - * @return array |
|
774 | - * @throws ShareNotFound |
|
775 | - */ |
|
776 | - protected function getRawShare($id) { |
|
777 | - |
|
778 | - // Now fetch the inserted share and create a complete share object |
|
779 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
780 | - $qb->select('*') |
|
781 | - ->from('share') |
|
782 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
783 | - |
|
784 | - $cursor = $qb->execute(); |
|
785 | - $data = $cursor->fetch(); |
|
786 | - $cursor->closeCursor(); |
|
787 | - |
|
788 | - if ($data === false) { |
|
789 | - throw new ShareNotFound; |
|
790 | - } |
|
791 | - |
|
792 | - return $data; |
|
793 | - } |
|
794 | - |
|
795 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
796 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
797 | - $qb->select('*') |
|
798 | - ->from('share', 's') |
|
799 | - ->andWhere($qb->expr()->orX( |
|
800 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
801 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
802 | - )) |
|
803 | - ->andWhere( |
|
804 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
805 | - ); |
|
806 | - |
|
807 | - /** |
|
808 | - * Reshares for this user are shares where they are the owner. |
|
809 | - */ |
|
810 | - if ($reshares === false) { |
|
811 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
812 | - } else { |
|
813 | - $qb->andWhere( |
|
814 | - $qb->expr()->orX( |
|
815 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
816 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
817 | - ) |
|
818 | - ); |
|
819 | - } |
|
820 | - |
|
821 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
822 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
823 | - |
|
824 | - $qb->orderBy('id'); |
|
825 | - |
|
826 | - $cursor = $qb->execute(); |
|
827 | - $shares = []; |
|
828 | - while ($data = $cursor->fetch()) { |
|
829 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
830 | - } |
|
831 | - $cursor->closeCursor(); |
|
832 | - |
|
833 | - return $shares; |
|
834 | - } |
|
428 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
429 | + $qb->update('share') |
|
430 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
431 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
432 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
433 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
434 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
435 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
436 | + ->execute(); |
|
437 | + |
|
438 | + return $share; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * @inheritdoc |
|
443 | + */ |
|
444 | + public function move(IShare $share, $recipient) { |
|
445 | + /** |
|
446 | + * nothing to do here, mail shares are only outgoing shares |
|
447 | + */ |
|
448 | + return $share; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Delete a share (owner unShares the file) |
|
453 | + * |
|
454 | + * @param IShare $share |
|
455 | + */ |
|
456 | + public function delete(IShare $share) { |
|
457 | + $this->removeShareFromTable($share->getId()); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * @inheritdoc |
|
462 | + */ |
|
463 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
464 | + // nothing to do here, mail shares are only outgoing shares |
|
465 | + return; |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * @inheritdoc |
|
470 | + */ |
|
471 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
472 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
473 | + $qb->select('*') |
|
474 | + ->from('share'); |
|
475 | + |
|
476 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
477 | + |
|
478 | + /** |
|
479 | + * Reshares for this user are shares where they are the owner. |
|
480 | + */ |
|
481 | + if ($reshares === false) { |
|
482 | + //Special case for old shares created via the web UI |
|
483 | + $or1 = $qb->expr()->andX( |
|
484 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
485 | + $qb->expr()->isNull('uid_initiator') |
|
486 | + ); |
|
487 | + |
|
488 | + $qb->andWhere( |
|
489 | + $qb->expr()->orX( |
|
490 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
491 | + $or1 |
|
492 | + ) |
|
493 | + ); |
|
494 | + } else { |
|
495 | + $qb->andWhere( |
|
496 | + $qb->expr()->orX( |
|
497 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
498 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
499 | + ) |
|
500 | + ); |
|
501 | + } |
|
502 | + |
|
503 | + if ($node !== null) { |
|
504 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
505 | + } |
|
506 | + |
|
507 | + if ($limit !== -1) { |
|
508 | + $qb->setMaxResults($limit); |
|
509 | + } |
|
510 | + |
|
511 | + $qb->setFirstResult($offset); |
|
512 | + $qb->orderBy('id'); |
|
513 | + |
|
514 | + $cursor = $qb->execute(); |
|
515 | + $shares = []; |
|
516 | + while($data = $cursor->fetch()) { |
|
517 | + $shares[] = $this->createShareObject($data); |
|
518 | + } |
|
519 | + $cursor->closeCursor(); |
|
520 | + |
|
521 | + return $shares; |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * @inheritdoc |
|
526 | + */ |
|
527 | + public function getShareById($id, $recipientId = null) { |
|
528 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
529 | + |
|
530 | + $qb->select('*') |
|
531 | + ->from('share') |
|
532 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
533 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
534 | + |
|
535 | + $cursor = $qb->execute(); |
|
536 | + $data = $cursor->fetch(); |
|
537 | + $cursor->closeCursor(); |
|
538 | + |
|
539 | + if ($data === false) { |
|
540 | + throw new ShareNotFound(); |
|
541 | + } |
|
542 | + |
|
543 | + try { |
|
544 | + $share = $this->createShareObject($data); |
|
545 | + } catch (InvalidShare $e) { |
|
546 | + throw new ShareNotFound(); |
|
547 | + } |
|
548 | + |
|
549 | + return $share; |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * Get shares for a given path |
|
554 | + * |
|
555 | + * @param \OCP\Files\Node $path |
|
556 | + * @return IShare[] |
|
557 | + */ |
|
558 | + public function getSharesByPath(Node $path) { |
|
559 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
560 | + |
|
561 | + $cursor = $qb->select('*') |
|
562 | + ->from('share') |
|
563 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
564 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
565 | + ->execute(); |
|
566 | + |
|
567 | + $shares = []; |
|
568 | + while($data = $cursor->fetch()) { |
|
569 | + $shares[] = $this->createShareObject($data); |
|
570 | + } |
|
571 | + $cursor->closeCursor(); |
|
572 | + |
|
573 | + return $shares; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * @inheritdoc |
|
578 | + */ |
|
579 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
580 | + /** @var IShare[] $shares */ |
|
581 | + $shares = []; |
|
582 | + |
|
583 | + //Get shares directly with this user |
|
584 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
585 | + $qb->select('*') |
|
586 | + ->from('share'); |
|
587 | + |
|
588 | + // Order by id |
|
589 | + $qb->orderBy('id'); |
|
590 | + |
|
591 | + // Set limit and offset |
|
592 | + if ($limit !== -1) { |
|
593 | + $qb->setMaxResults($limit); |
|
594 | + } |
|
595 | + $qb->setFirstResult($offset); |
|
596 | + |
|
597 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
598 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
599 | + |
|
600 | + // Filter by node if provided |
|
601 | + if ($node !== null) { |
|
602 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
603 | + } |
|
604 | + |
|
605 | + $cursor = $qb->execute(); |
|
606 | + |
|
607 | + while($data = $cursor->fetch()) { |
|
608 | + $shares[] = $this->createShareObject($data); |
|
609 | + } |
|
610 | + $cursor->closeCursor(); |
|
611 | + |
|
612 | + |
|
613 | + return $shares; |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Get a share by token |
|
618 | + * |
|
619 | + * @param string $token |
|
620 | + * @return IShare |
|
621 | + * @throws ShareNotFound |
|
622 | + */ |
|
623 | + public function getShareByToken($token) { |
|
624 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
625 | + |
|
626 | + $cursor = $qb->select('*') |
|
627 | + ->from('share') |
|
628 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
629 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
630 | + ->execute(); |
|
631 | + |
|
632 | + $data = $cursor->fetch(); |
|
633 | + |
|
634 | + if ($data === false) { |
|
635 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
636 | + } |
|
637 | + |
|
638 | + try { |
|
639 | + $share = $this->createShareObject($data); |
|
640 | + } catch (InvalidShare $e) { |
|
641 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
642 | + } |
|
643 | + |
|
644 | + return $share; |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * remove share from table |
|
649 | + * |
|
650 | + * @param string $shareId |
|
651 | + */ |
|
652 | + protected function removeShareFromTable($shareId) { |
|
653 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
654 | + $qb->delete('share') |
|
655 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
656 | + $qb->execute(); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Create a share object from an database row |
|
661 | + * |
|
662 | + * @param array $data |
|
663 | + * @return IShare |
|
664 | + * @throws InvalidShare |
|
665 | + * @throws ShareNotFound |
|
666 | + */ |
|
667 | + protected function createShareObject($data) { |
|
668 | + |
|
669 | + $share = new Share($this->rootFolder, $this->userManager); |
|
670 | + $share->setId((int)$data['id']) |
|
671 | + ->setShareType((int)$data['share_type']) |
|
672 | + ->setPermissions((int)$data['permissions']) |
|
673 | + ->setTarget($data['file_target']) |
|
674 | + ->setMailSend((bool)$data['mail_send']) |
|
675 | + ->setToken($data['token']); |
|
676 | + |
|
677 | + $shareTime = new \DateTime(); |
|
678 | + $shareTime->setTimestamp((int)$data['stime']); |
|
679 | + $share->setShareTime($shareTime); |
|
680 | + $share->setSharedWith($data['share_with']); |
|
681 | + $share->setPassword($data['password']); |
|
682 | + |
|
683 | + if ($data['uid_initiator'] !== null) { |
|
684 | + $share->setShareOwner($data['uid_owner']); |
|
685 | + $share->setSharedBy($data['uid_initiator']); |
|
686 | + } else { |
|
687 | + //OLD SHARE |
|
688 | + $share->setSharedBy($data['uid_owner']); |
|
689 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
690 | + |
|
691 | + $owner = $path->getOwner(); |
|
692 | + $share->setShareOwner($owner->getUID()); |
|
693 | + } |
|
694 | + |
|
695 | + if ($data['expiration'] !== null) { |
|
696 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
697 | + if ($expiration !== false) { |
|
698 | + $share->setExpirationDate($expiration); |
|
699 | + } |
|
700 | + } |
|
701 | + |
|
702 | + $share->setNodeId((int)$data['file_source']); |
|
703 | + $share->setNodeType($data['item_type']); |
|
704 | + |
|
705 | + $share->setProviderId($this->identifier()); |
|
706 | + |
|
707 | + return $share; |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Get the node with file $id for $user |
|
712 | + * |
|
713 | + * @param string $userId |
|
714 | + * @param int $id |
|
715 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
716 | + * @throws InvalidShare |
|
717 | + */ |
|
718 | + private function getNode($userId, $id) { |
|
719 | + try { |
|
720 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
721 | + } catch (NotFoundException $e) { |
|
722 | + throw new InvalidShare(); |
|
723 | + } |
|
724 | + |
|
725 | + $nodes = $userFolder->getById($id); |
|
726 | + |
|
727 | + if (empty($nodes)) { |
|
728 | + throw new InvalidShare(); |
|
729 | + } |
|
730 | + |
|
731 | + return $nodes[0]; |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * A user is deleted from the system |
|
736 | + * So clean up the relevant shares. |
|
737 | + * |
|
738 | + * @param string $uid |
|
739 | + * @param int $shareType |
|
740 | + */ |
|
741 | + public function userDeleted($uid, $shareType) { |
|
742 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
743 | + |
|
744 | + $qb->delete('share') |
|
745 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
746 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
747 | + ->execute(); |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * This provider does not support group shares |
|
752 | + * |
|
753 | + * @param string $gid |
|
754 | + */ |
|
755 | + public function groupDeleted($gid) { |
|
756 | + return; |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * This provider does not support group shares |
|
761 | + * |
|
762 | + * @param string $uid |
|
763 | + * @param string $gid |
|
764 | + */ |
|
765 | + public function userDeletedFromGroup($uid, $gid) { |
|
766 | + return; |
|
767 | + } |
|
768 | + |
|
769 | + /** |
|
770 | + * get database row of a give share |
|
771 | + * |
|
772 | + * @param $id |
|
773 | + * @return array |
|
774 | + * @throws ShareNotFound |
|
775 | + */ |
|
776 | + protected function getRawShare($id) { |
|
777 | + |
|
778 | + // Now fetch the inserted share and create a complete share object |
|
779 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
780 | + $qb->select('*') |
|
781 | + ->from('share') |
|
782 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
783 | + |
|
784 | + $cursor = $qb->execute(); |
|
785 | + $data = $cursor->fetch(); |
|
786 | + $cursor->closeCursor(); |
|
787 | + |
|
788 | + if ($data === false) { |
|
789 | + throw new ShareNotFound; |
|
790 | + } |
|
791 | + |
|
792 | + return $data; |
|
793 | + } |
|
794 | + |
|
795 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
796 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
797 | + $qb->select('*') |
|
798 | + ->from('share', 's') |
|
799 | + ->andWhere($qb->expr()->orX( |
|
800 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
801 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
802 | + )) |
|
803 | + ->andWhere( |
|
804 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
805 | + ); |
|
806 | + |
|
807 | + /** |
|
808 | + * Reshares for this user are shares where they are the owner. |
|
809 | + */ |
|
810 | + if ($reshares === false) { |
|
811 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
812 | + } else { |
|
813 | + $qb->andWhere( |
|
814 | + $qb->expr()->orX( |
|
815 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
816 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
817 | + ) |
|
818 | + ); |
|
819 | + } |
|
820 | + |
|
821 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
822 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
823 | + |
|
824 | + $qb->orderBy('id'); |
|
825 | + |
|
826 | + $cursor = $qb->execute(); |
|
827 | + $shares = []; |
|
828 | + while ($data = $cursor->fetch()) { |
|
829 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
830 | + } |
|
831 | + $cursor->closeCursor(); |
|
832 | + |
|
833 | + return $shares; |
|
834 | + } |
|
835 | 835 | |
836 | 836 | } |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | $share->getShareOwner(), |
235 | 235 | $share->getSharedBy(), $share->getSharedWith()); |
236 | 236 | } catch (HintException $hintException) { |
237 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
237 | + $this->logger->error('Failed to send share by mail: '.$hintException->getMessage()); |
|
238 | 238 | $this->removeShareFromTable($shareId); |
239 | 239 | throw $hintException; |
240 | 240 | } catch (\Exception $e) { |
241 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
241 | + $this->logger->error('Failed to send share by mail: '.$e->getMessage()); |
|
242 | 242 | $this->removeShareFromTable($shareId); |
243 | 243 | throw new HintException('Failed to send share by mail', |
244 | 244 | $this->l->t('Failed to send share by E-mail')); |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
255 | 255 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
256 | 256 | if ($owner === $initiator) { |
257 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
257 | + $subject = (string) $this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
258 | 258 | } else { |
259 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
259 | + $subject = (string) $this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | $message = $this->mailer->createMessage(); |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | if ($owner === $initiator) { |
270 | 270 | $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
271 | 271 | } else { |
272 | - $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
272 | + $text = $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
273 | 273 | } |
274 | 274 | |
275 | - $text .= ' ' . $this->l->t('Click the button below to open it.'); |
|
275 | + $text .= ' '.$this->l->t('Click the button below to open it.'); |
|
276 | 276 | |
277 | 277 | $emailTemplate->addBodyText($text); |
278 | 278 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | |
306 | 306 | $initiatorUser = $this->userManager->get($initiator); |
307 | 307 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
308 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
308 | + $subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
309 | 309 | |
310 | 310 | $message = $this->mailer->createMessage(); |
311 | 311 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | */ |
339 | 339 | protected function generateToken() { |
340 | 340 | $token = $this->secureRandom->generate( |
341 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
341 | + 15, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
342 | 342 | return $token; |
343 | 343 | } |
344 | 344 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | ->orderBy('id'); |
360 | 360 | |
361 | 361 | $cursor = $qb->execute(); |
362 | - while($data = $cursor->fetch()) { |
|
362 | + while ($data = $cursor->fetch()) { |
|
363 | 363 | $children[] = $this->createShareObject($data); |
364 | 364 | } |
365 | 365 | $cursor->closeCursor(); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $qb->execute(); |
403 | 403 | $id = $qb->getLastInsertId(); |
404 | 404 | |
405 | - return (int)$id; |
|
405 | + return (int) $id; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | // a real password was given |
420 | 420 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
421 | 421 | |
422 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
422 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
423 | 423 | $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
424 | 424 | } |
425 | 425 | /* |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | |
514 | 514 | $cursor = $qb->execute(); |
515 | 515 | $shares = []; |
516 | - while($data = $cursor->fetch()) { |
|
516 | + while ($data = $cursor->fetch()) { |
|
517 | 517 | $shares[] = $this->createShareObject($data); |
518 | 518 | } |
519 | 519 | $cursor->closeCursor(); |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | ->execute(); |
566 | 566 | |
567 | 567 | $shares = []; |
568 | - while($data = $cursor->fetch()) { |
|
568 | + while ($data = $cursor->fetch()) { |
|
569 | 569 | $shares[] = $this->createShareObject($data); |
570 | 570 | } |
571 | 571 | $cursor->closeCursor(); |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | |
605 | 605 | $cursor = $qb->execute(); |
606 | 606 | |
607 | - while($data = $cursor->fetch()) { |
|
607 | + while ($data = $cursor->fetch()) { |
|
608 | 608 | $shares[] = $this->createShareObject($data); |
609 | 609 | } |
610 | 610 | $cursor->closeCursor(); |
@@ -667,15 +667,15 @@ discard block |
||
667 | 667 | protected function createShareObject($data) { |
668 | 668 | |
669 | 669 | $share = new Share($this->rootFolder, $this->userManager); |
670 | - $share->setId((int)$data['id']) |
|
671 | - ->setShareType((int)$data['share_type']) |
|
672 | - ->setPermissions((int)$data['permissions']) |
|
670 | + $share->setId((int) $data['id']) |
|
671 | + ->setShareType((int) $data['share_type']) |
|
672 | + ->setPermissions((int) $data['permissions']) |
|
673 | 673 | ->setTarget($data['file_target']) |
674 | - ->setMailSend((bool)$data['mail_send']) |
|
674 | + ->setMailSend((bool) $data['mail_send']) |
|
675 | 675 | ->setToken($data['token']); |
676 | 676 | |
677 | 677 | $shareTime = new \DateTime(); |
678 | - $shareTime->setTimestamp((int)$data['stime']); |
|
678 | + $shareTime->setTimestamp((int) $data['stime']); |
|
679 | 679 | $share->setShareTime($shareTime); |
680 | 680 | $share->setSharedWith($data['share_with']); |
681 | 681 | $share->setPassword($data['password']); |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | } else { |
687 | 687 | //OLD SHARE |
688 | 688 | $share->setSharedBy($data['uid_owner']); |
689 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
689 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
690 | 690 | |
691 | 691 | $owner = $path->getOwner(); |
692 | 692 | $share->setShareOwner($owner->getUID()); |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | } |
700 | 700 | } |
701 | 701 | |
702 | - $share->setNodeId((int)$data['file_source']); |
|
702 | + $share->setNodeId((int) $data['file_source']); |
|
703 | 703 | $share->setNodeType($data['item_type']); |
704 | 704 | |
705 | 705 | $share->setProviderId($this->identifier()); |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | ); |
819 | 819 | } |
820 | 820 | |
821 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
821 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
822 | 822 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
823 | 823 | |
824 | 824 | $qb->orderBy('id'); |
@@ -39,25 +39,25 @@ discard block |
||
39 | 39 | * @package OC\Mail |
40 | 40 | */ |
41 | 41 | class EMailTemplate implements IEMailTemplate { |
42 | - /** @var Defaults */ |
|
43 | - protected $themingDefaults; |
|
44 | - /** @var IURLGenerator */ |
|
45 | - protected $urlGenerator; |
|
46 | - /** @var IL10N */ |
|
47 | - protected $l10n; |
|
48 | - |
|
49 | - /** @var string */ |
|
50 | - protected $htmlBody = ''; |
|
51 | - /** @var string */ |
|
52 | - protected $plainBody = ''; |
|
53 | - /** @var bool indicated if the footer is added */ |
|
54 | - protected $headerAdded = false; |
|
55 | - /** @var bool indicated if the body is already opened */ |
|
56 | - protected $bodyOpened = false; |
|
57 | - /** @var bool indicated if the footer is added */ |
|
58 | - protected $footerAdded = false; |
|
59 | - |
|
60 | - protected $head = <<<EOF |
|
42 | + /** @var Defaults */ |
|
43 | + protected $themingDefaults; |
|
44 | + /** @var IURLGenerator */ |
|
45 | + protected $urlGenerator; |
|
46 | + /** @var IL10N */ |
|
47 | + protected $l10n; |
|
48 | + |
|
49 | + /** @var string */ |
|
50 | + protected $htmlBody = ''; |
|
51 | + /** @var string */ |
|
52 | + protected $plainBody = ''; |
|
53 | + /** @var bool indicated if the footer is added */ |
|
54 | + protected $headerAdded = false; |
|
55 | + /** @var bool indicated if the body is already opened */ |
|
56 | + protected $bodyOpened = false; |
|
57 | + /** @var bool indicated if the footer is added */ |
|
58 | + protected $footerAdded = false; |
|
59 | + |
|
60 | + protected $head = <<<EOF |
|
61 | 61 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
62 | 62 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important"> |
63 | 63 | <head> |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | <center data-parsed="" style="min-width:580px;width:100%"> |
76 | 76 | EOF; |
77 | 77 | |
78 | - protected $tail = <<<EOF |
|
78 | + protected $tail = <<<EOF |
|
79 | 79 | </center> |
80 | 80 | </td> |
81 | 81 | </tr> |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | </html> |
87 | 87 | EOF; |
88 | 88 | |
89 | - protected $header = <<<EOF |
|
89 | + protected $header = <<<EOF |
|
90 | 90 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
91 | 91 | <tr style="padding:0;text-align:left;vertical-align:top"> |
92 | 92 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | </table> |
120 | 120 | EOF; |
121 | 121 | |
122 | - protected $heading = <<<EOF |
|
122 | + protected $heading = <<<EOF |
|
123 | 123 | <table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px"> |
124 | 124 | <tbody> |
125 | 125 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | </table> |
139 | 139 | EOF; |
140 | 140 | |
141 | - protected $bodyBegin = <<<EOF |
|
141 | + protected $bodyBegin = <<<EOF |
|
142 | 142 | <table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%"> |
143 | 143 | <tr style="padding:0;text-align:left;vertical-align:top"> |
144 | 144 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | </table> |
156 | 156 | EOF; |
157 | 157 | |
158 | - protected $bodyText = <<<EOF |
|
158 | + protected $bodyText = <<<EOF |
|
159 | 159 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
160 | 160 | <tbody> |
161 | 161 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | </table> |
175 | 175 | EOF; |
176 | 176 | |
177 | - protected $buttonGroup = <<<EOF |
|
177 | + protected $buttonGroup = <<<EOF |
|
178 | 178 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
179 | 179 | <tbody> |
180 | 180 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | </table> |
228 | 228 | EOF; |
229 | 229 | |
230 | - protected $button = <<<EOF |
|
230 | + protected $button = <<<EOF |
|
231 | 231 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
232 | 232 | <tbody> |
233 | 233 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | </table> |
268 | 268 | EOF; |
269 | 269 | |
270 | - protected $bodyEnd = <<<EOF |
|
270 | + protected $bodyEnd = <<<EOF |
|
271 | 271 | |
272 | 272 | </td> |
273 | 273 | </tr> |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | </table> |
279 | 279 | EOF; |
280 | 280 | |
281 | - protected $footer = <<<EOF |
|
281 | + protected $footer = <<<EOF |
|
282 | 282 | <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
283 | 283 | <tbody> |
284 | 284 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -304,193 +304,193 @@ discard block |
||
304 | 304 | </table> |
305 | 305 | EOF; |
306 | 306 | |
307 | - /** |
|
308 | - * @param Defaults $themingDefaults |
|
309 | - * @param IURLGenerator $urlGenerator |
|
310 | - * @param IL10N $l10n |
|
311 | - */ |
|
312 | - public function __construct(Defaults $themingDefaults, |
|
313 | - IURLGenerator $urlGenerator, |
|
314 | - IL10N $l10n) { |
|
315 | - $this->themingDefaults = $themingDefaults; |
|
316 | - $this->urlGenerator = $urlGenerator; |
|
317 | - $this->l10n = $l10n; |
|
318 | - $this->htmlBody .= $this->head; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Adds a header to the email |
|
323 | - */ |
|
324 | - public function addHeader() { |
|
325 | - if ($this->headerAdded) { |
|
326 | - return; |
|
327 | - } |
|
328 | - $this->headerAdded = true; |
|
329 | - |
|
330 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()); |
|
331 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Adds a heading to the email |
|
336 | - * |
|
337 | - * @param string $title |
|
338 | - * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used |
|
339 | - */ |
|
340 | - public function addHeading($title, $plainTitle = '') { |
|
341 | - if ($this->footerAdded) { |
|
342 | - return; |
|
343 | - } |
|
344 | - if ($plainTitle === '') { |
|
345 | - $plainTitle = $title; |
|
346 | - } |
|
347 | - |
|
348 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
349 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Adds a paragraph to the body of the email |
|
354 | - * |
|
355 | - * @param string $text |
|
356 | - * @param string $plainText Text that is used in the plain text email - if empty the $text is used |
|
357 | - */ |
|
358 | - public function addBodyText($text, $plainText = '') { |
|
359 | - if ($this->footerAdded) { |
|
360 | - return; |
|
361 | - } |
|
362 | - if ($plainText === '') { |
|
363 | - $plainText = $text; |
|
364 | - } |
|
365 | - |
|
366 | - if (!$this->bodyOpened) { |
|
367 | - $this->htmlBody .= $this->bodyBegin; |
|
368 | - $this->bodyOpened = true; |
|
369 | - } |
|
370 | - |
|
371 | - $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
|
372 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Adds a button group of two buttons to the body of the email |
|
377 | - * |
|
378 | - * @param string $textLeft Text of left button |
|
379 | - * @param string $urlLeft URL of left button |
|
380 | - * @param string $textRight Text of right button |
|
381 | - * @param string $urlRight URL of right button |
|
382 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
383 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
384 | - */ |
|
385 | - public function addBodyButtonGroup($textLeft, |
|
386 | - $urlLeft, |
|
387 | - $textRight, |
|
388 | - $urlRight, |
|
389 | - $plainTextLeft = '', |
|
390 | - $plainTextRight = '') { |
|
391 | - if ($this->footerAdded) { |
|
392 | - return; |
|
393 | - } |
|
394 | - if ($plainTextLeft === '') { |
|
395 | - $plainTextLeft = $textLeft; |
|
396 | - } |
|
397 | - |
|
398 | - if ($plainTextRight === '') { |
|
399 | - $plainTextRight = $textRight; |
|
400 | - } |
|
401 | - |
|
402 | - if (!$this->bodyOpened) { |
|
403 | - $this->htmlBody .= $this->bodyBegin; |
|
404 | - $this->bodyOpened = true; |
|
405 | - } |
|
406 | - |
|
407 | - $color = $this->themingDefaults->getColorPrimary(); |
|
408 | - |
|
409 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
|
410 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
411 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Adds a button to the body of the email |
|
417 | - * |
|
418 | - * @param string $text Text of button |
|
419 | - * @param string $url URL of button |
|
420 | - * |
|
421 | - * @since 12.0.0 |
|
422 | - */ |
|
423 | - public function addBodyButton($text, $url) { |
|
424 | - if ($this->footerAdded) { |
|
425 | - return; |
|
426 | - } |
|
427 | - |
|
428 | - if (!$this->bodyOpened) { |
|
429 | - $this->htmlBody .= $this->bodyBegin; |
|
430 | - $this->bodyOpened = true; |
|
431 | - } |
|
432 | - |
|
433 | - $color = $this->themingDefaults->getColorPrimary(); |
|
434 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
|
435 | - $this->plainBody .= $text . ': ' . $url . PHP_EOL; |
|
436 | - |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
441 | - * |
|
442 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
443 | - */ |
|
444 | - public function addFooter($text = '') { |
|
445 | - if($text === '') { |
|
446 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
447 | - } |
|
448 | - |
|
449 | - if ($this->footerAdded) { |
|
450 | - return; |
|
451 | - } |
|
452 | - $this->footerAdded = true; |
|
453 | - |
|
454 | - if ($this->bodyOpened) { |
|
455 | - $this->htmlBody .= $this->bodyEnd; |
|
456 | - $this->bodyOpened = false; |
|
457 | - } |
|
458 | - |
|
459 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
460 | - $this->htmlBody .= $this->tail; |
|
461 | - $this->plainBody .= '--' . PHP_EOL; |
|
462 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Returns the rendered HTML email as string |
|
467 | - * |
|
468 | - * @return string |
|
469 | - */ |
|
470 | - public function renderHTML() { |
|
471 | - if (!$this->footerAdded) { |
|
472 | - $this->footerAdded = true; |
|
473 | - if ($this->bodyOpened) { |
|
474 | - $this->htmlBody .= $this->bodyEnd; |
|
475 | - } |
|
476 | - $this->htmlBody .= $this->tail; |
|
477 | - } |
|
478 | - return $this->htmlBody; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Returns the rendered plain text email as string |
|
483 | - * |
|
484 | - * @return string |
|
485 | - */ |
|
486 | - public function renderText() { |
|
487 | - if (!$this->footerAdded) { |
|
488 | - $this->footerAdded = true; |
|
489 | - if ($this->bodyOpened) { |
|
490 | - $this->htmlBody .= $this->bodyEnd; |
|
491 | - } |
|
492 | - $this->htmlBody .= $this->tail; |
|
493 | - } |
|
494 | - return $this->plainBody; |
|
495 | - } |
|
307 | + /** |
|
308 | + * @param Defaults $themingDefaults |
|
309 | + * @param IURLGenerator $urlGenerator |
|
310 | + * @param IL10N $l10n |
|
311 | + */ |
|
312 | + public function __construct(Defaults $themingDefaults, |
|
313 | + IURLGenerator $urlGenerator, |
|
314 | + IL10N $l10n) { |
|
315 | + $this->themingDefaults = $themingDefaults; |
|
316 | + $this->urlGenerator = $urlGenerator; |
|
317 | + $this->l10n = $l10n; |
|
318 | + $this->htmlBody .= $this->head; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Adds a header to the email |
|
323 | + */ |
|
324 | + public function addHeader() { |
|
325 | + if ($this->headerAdded) { |
|
326 | + return; |
|
327 | + } |
|
328 | + $this->headerAdded = true; |
|
329 | + |
|
330 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()); |
|
331 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Adds a heading to the email |
|
336 | + * |
|
337 | + * @param string $title |
|
338 | + * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used |
|
339 | + */ |
|
340 | + public function addHeading($title, $plainTitle = '') { |
|
341 | + if ($this->footerAdded) { |
|
342 | + return; |
|
343 | + } |
|
344 | + if ($plainTitle === '') { |
|
345 | + $plainTitle = $title; |
|
346 | + } |
|
347 | + |
|
348 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
349 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Adds a paragraph to the body of the email |
|
354 | + * |
|
355 | + * @param string $text |
|
356 | + * @param string $plainText Text that is used in the plain text email - if empty the $text is used |
|
357 | + */ |
|
358 | + public function addBodyText($text, $plainText = '') { |
|
359 | + if ($this->footerAdded) { |
|
360 | + return; |
|
361 | + } |
|
362 | + if ($plainText === '') { |
|
363 | + $plainText = $text; |
|
364 | + } |
|
365 | + |
|
366 | + if (!$this->bodyOpened) { |
|
367 | + $this->htmlBody .= $this->bodyBegin; |
|
368 | + $this->bodyOpened = true; |
|
369 | + } |
|
370 | + |
|
371 | + $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
|
372 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Adds a button group of two buttons to the body of the email |
|
377 | + * |
|
378 | + * @param string $textLeft Text of left button |
|
379 | + * @param string $urlLeft URL of left button |
|
380 | + * @param string $textRight Text of right button |
|
381 | + * @param string $urlRight URL of right button |
|
382 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
383 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
384 | + */ |
|
385 | + public function addBodyButtonGroup($textLeft, |
|
386 | + $urlLeft, |
|
387 | + $textRight, |
|
388 | + $urlRight, |
|
389 | + $plainTextLeft = '', |
|
390 | + $plainTextRight = '') { |
|
391 | + if ($this->footerAdded) { |
|
392 | + return; |
|
393 | + } |
|
394 | + if ($plainTextLeft === '') { |
|
395 | + $plainTextLeft = $textLeft; |
|
396 | + } |
|
397 | + |
|
398 | + if ($plainTextRight === '') { |
|
399 | + $plainTextRight = $textRight; |
|
400 | + } |
|
401 | + |
|
402 | + if (!$this->bodyOpened) { |
|
403 | + $this->htmlBody .= $this->bodyBegin; |
|
404 | + $this->bodyOpened = true; |
|
405 | + } |
|
406 | + |
|
407 | + $color = $this->themingDefaults->getColorPrimary(); |
|
408 | + |
|
409 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
|
410 | + $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
411 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Adds a button to the body of the email |
|
417 | + * |
|
418 | + * @param string $text Text of button |
|
419 | + * @param string $url URL of button |
|
420 | + * |
|
421 | + * @since 12.0.0 |
|
422 | + */ |
|
423 | + public function addBodyButton($text, $url) { |
|
424 | + if ($this->footerAdded) { |
|
425 | + return; |
|
426 | + } |
|
427 | + |
|
428 | + if (!$this->bodyOpened) { |
|
429 | + $this->htmlBody .= $this->bodyBegin; |
|
430 | + $this->bodyOpened = true; |
|
431 | + } |
|
432 | + |
|
433 | + $color = $this->themingDefaults->getColorPrimary(); |
|
434 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
|
435 | + $this->plainBody .= $text . ': ' . $url . PHP_EOL; |
|
436 | + |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
441 | + * |
|
442 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
443 | + */ |
|
444 | + public function addFooter($text = '') { |
|
445 | + if($text === '') { |
|
446 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
447 | + } |
|
448 | + |
|
449 | + if ($this->footerAdded) { |
|
450 | + return; |
|
451 | + } |
|
452 | + $this->footerAdded = true; |
|
453 | + |
|
454 | + if ($this->bodyOpened) { |
|
455 | + $this->htmlBody .= $this->bodyEnd; |
|
456 | + $this->bodyOpened = false; |
|
457 | + } |
|
458 | + |
|
459 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
460 | + $this->htmlBody .= $this->tail; |
|
461 | + $this->plainBody .= '--' . PHP_EOL; |
|
462 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Returns the rendered HTML email as string |
|
467 | + * |
|
468 | + * @return string |
|
469 | + */ |
|
470 | + public function renderHTML() { |
|
471 | + if (!$this->footerAdded) { |
|
472 | + $this->footerAdded = true; |
|
473 | + if ($this->bodyOpened) { |
|
474 | + $this->htmlBody .= $this->bodyEnd; |
|
475 | + } |
|
476 | + $this->htmlBody .= $this->tail; |
|
477 | + } |
|
478 | + return $this->htmlBody; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Returns the rendered plain text email as string |
|
483 | + * |
|
484 | + * @return string |
|
485 | + */ |
|
486 | + public function renderText() { |
|
487 | + if (!$this->footerAdded) { |
|
488 | + $this->footerAdded = true; |
|
489 | + if ($this->bodyOpened) { |
|
490 | + $this->htmlBody .= $this->bodyEnd; |
|
491 | + } |
|
492 | + $this->htmlBody .= $this->tail; |
|
493 | + } |
|
494 | + return $this->plainBody; |
|
495 | + } |
|
496 | 496 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | } |
347 | 347 | |
348 | 348 | $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
349 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
349 | + $this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL; |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
372 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
372 | + $this->plainBody .= $plainText.PHP_EOL.PHP_EOL; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | $color = $this->themingDefaults->getColorPrimary(); |
408 | 408 | |
409 | 409 | $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
410 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
411 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
410 | + $this->plainBody .= $plainTextLeft.': '.$urlLeft.PHP_EOL; |
|
411 | + $this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL; |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | |
433 | 433 | $color = $this->themingDefaults->getColorPrimary(); |
434 | 434 | $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
435 | - $this->plainBody .= $text . ': ' . $url . PHP_EOL; |
|
435 | + $this->plainBody .= $text.': '.$url.PHP_EOL; |
|
436 | 436 | |
437 | 437 | } |
438 | 438 | |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
443 | 443 | */ |
444 | 444 | public function addFooter($text = '') { |
445 | - if($text === '') { |
|
446 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
445 | + if ($text === '') { |
|
446 | + $text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan().'<br>'.$this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | if ($this->footerAdded) { |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | |
459 | 459 | $this->htmlBody .= vsprintf($this->footer, [$text]); |
460 | 460 | $this->htmlBody .= $this->tail; |
461 | - $this->plainBody .= '--' . PHP_EOL; |
|
461 | + $this->plainBody .= '--'.PHP_EOL; |
|
462 | 462 | $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
463 | 463 | } |
464 | 464 |
@@ -51,81 +51,81 @@ |
||
51 | 51 | * @since 12.0.0 |
52 | 52 | */ |
53 | 53 | interface IEMailTemplate { |
54 | - /** |
|
55 | - * Adds a header to the email |
|
56 | - * |
|
57 | - * @since 12.0.0 |
|
58 | - */ |
|
59 | - public function addHeader(); |
|
54 | + /** |
|
55 | + * Adds a header to the email |
|
56 | + * |
|
57 | + * @since 12.0.0 |
|
58 | + */ |
|
59 | + public function addHeader(); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Adds a heading to the email |
|
63 | - * |
|
64 | - * @param string $title |
|
65 | - * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used |
|
66 | - * |
|
67 | - * @since 12.0.0 |
|
68 | - */ |
|
69 | - public function addHeading($title, $plainTitle = ''); |
|
61 | + /** |
|
62 | + * Adds a heading to the email |
|
63 | + * |
|
64 | + * @param string $title |
|
65 | + * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used |
|
66 | + * |
|
67 | + * @since 12.0.0 |
|
68 | + */ |
|
69 | + public function addHeading($title, $plainTitle = ''); |
|
70 | 70 | |
71 | - /** |
|
72 | - * Adds a paragraph to the body of the email |
|
73 | - * |
|
74 | - * @param string $text |
|
75 | - * @param string $plainText Text that is used in the plain text email - if empty the $text is used |
|
76 | - * |
|
77 | - * @since 12.0.0 |
|
78 | - */ |
|
79 | - public function addBodyText($text, $plainText = ''); |
|
71 | + /** |
|
72 | + * Adds a paragraph to the body of the email |
|
73 | + * |
|
74 | + * @param string $text |
|
75 | + * @param string $plainText Text that is used in the plain text email - if empty the $text is used |
|
76 | + * |
|
77 | + * @since 12.0.0 |
|
78 | + */ |
|
79 | + public function addBodyText($text, $plainText = ''); |
|
80 | 80 | |
81 | - /** |
|
82 | - * Adds a button group of two buttons to the body of the email |
|
83 | - * |
|
84 | - * @param string $textLeft Text of left button |
|
85 | - * @param string $urlLeft URL of left button |
|
86 | - * @param string $textRight Text of right button |
|
87 | - * @param string $urlRight URL of right button |
|
88 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
89 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
90 | - * |
|
91 | - * @since 12.0.0 |
|
92 | - */ |
|
93 | - public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
|
81 | + /** |
|
82 | + * Adds a button group of two buttons to the body of the email |
|
83 | + * |
|
84 | + * @param string $textLeft Text of left button |
|
85 | + * @param string $urlLeft URL of left button |
|
86 | + * @param string $textRight Text of right button |
|
87 | + * @param string $urlRight URL of right button |
|
88 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
89 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
90 | + * |
|
91 | + * @since 12.0.0 |
|
92 | + */ |
|
93 | + public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
|
94 | 94 | |
95 | - /** |
|
96 | - * Adds a button to the body of the email |
|
97 | - * |
|
98 | - * @param string $text Text of button |
|
99 | - * @param string $url URL of button |
|
100 | - * |
|
101 | - * @since 12.0.0 |
|
102 | - */ |
|
103 | - public function addBodyButton($text, $url); |
|
95 | + /** |
|
96 | + * Adds a button to the body of the email |
|
97 | + * |
|
98 | + * @param string $text Text of button |
|
99 | + * @param string $url URL of button |
|
100 | + * |
|
101 | + * @since 12.0.0 |
|
102 | + */ |
|
103 | + public function addBodyButton($text, $url); |
|
104 | 104 | |
105 | - /** |
|
106 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
107 | - * |
|
108 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
109 | - * |
|
110 | - * @since 12.0.0 |
|
111 | - */ |
|
112 | - public function addFooter($text = ''); |
|
105 | + /** |
|
106 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
107 | + * |
|
108 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
109 | + * |
|
110 | + * @since 12.0.0 |
|
111 | + */ |
|
112 | + public function addFooter($text = ''); |
|
113 | 113 | |
114 | - /** |
|
115 | - * Returns the rendered HTML email as string |
|
116 | - * |
|
117 | - * @return string |
|
118 | - * |
|
119 | - * @since 12.0.0 |
|
120 | - */ |
|
121 | - public function renderHTML(); |
|
114 | + /** |
|
115 | + * Returns the rendered HTML email as string |
|
116 | + * |
|
117 | + * @return string |
|
118 | + * |
|
119 | + * @since 12.0.0 |
|
120 | + */ |
|
121 | + public function renderHTML(); |
|
122 | 122 | |
123 | - /** |
|
124 | - * Returns the rendered plain text email as string |
|
125 | - * |
|
126 | - * @return string |
|
127 | - * |
|
128 | - * @since 12.0.0 |
|
129 | - */ |
|
130 | - public function renderText(); |
|
123 | + /** |
|
124 | + * Returns the rendered plain text email as string |
|
125 | + * |
|
126 | + * @return string |
|
127 | + * |
|
128 | + * @since 12.0.0 |
|
129 | + */ |
|
130 | + public function renderText(); |
|
131 | 131 | } |