@@ -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,788 +50,788 @@ |
||
| 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]), false); |
|
| 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 | - $emailTemplate->addBodyText( |
|
| 276 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
| 277 | - $text |
|
| 278 | - ); |
|
| 279 | - |
|
| 280 | - $emailTemplate->addBodyButton( |
|
| 281 | - $this->l->t('Open »%s«', [$filename]), |
|
| 282 | - $link |
|
| 283 | - ); |
|
| 284 | - $emailTemplate->addFooter(); |
|
| 285 | - |
|
| 286 | - $message->setTo([$shareWith]); |
|
| 287 | - $message->setSubject($subject); |
|
| 288 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
| 289 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
| 290 | - $this->mailer->send($message); |
|
| 291 | - |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * send password to recipient of a mail share |
|
| 296 | - * |
|
| 297 | - * @param string $filename |
|
| 298 | - * @param string $initiator |
|
| 299 | - * @param string $shareWith |
|
| 300 | - */ |
|
| 301 | - protected function sendPassword($filename, $initiator, $shareWith, $password) { |
|
| 302 | - |
|
| 303 | - if ($this->settingsManager->sendPasswordByMail() === false) { |
|
| 304 | - return; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $initiatorUser = $this->userManager->get($initiator); |
|
| 308 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 309 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
| 310 | - |
|
| 311 | - $message = $this->mailer->createMessage(); |
|
| 312 | - |
|
| 313 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
| 314 | - |
|
| 315 | - $emailTemplate->addHeader(); |
|
| 316 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); |
|
| 317 | - |
|
| 318 | - $emailTemplate->addBodyText($this->l->t( |
|
| 319 | - '%s shared »%s« with you. You should have already received a separate mail with a link to access it.', |
|
| 320 | - [$initiatorDisplayName, $filename] |
|
| 321 | - )); |
|
| 322 | - $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
| 323 | - |
|
| 324 | - $emailTemplate->addFooter(); |
|
| 325 | - |
|
| 326 | - $message->setTo([$shareWith]); |
|
| 327 | - $message->setSubject($subject); |
|
| 328 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
| 329 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
| 330 | - $this->mailer->send($message); |
|
| 331 | - |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * generate share token |
|
| 337 | - * |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - protected function generateToken() { |
|
| 341 | - $token = $this->secureRandom->generate( |
|
| 342 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 343 | - return $token; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Get all children of this share |
|
| 348 | - * |
|
| 349 | - * @param IShare $parent |
|
| 350 | - * @return IShare[] |
|
| 351 | - */ |
|
| 352 | - public function getChildren(IShare $parent) { |
|
| 353 | - $children = []; |
|
| 354 | - |
|
| 355 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 356 | - $qb->select('*') |
|
| 357 | - ->from('share') |
|
| 358 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 359 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 360 | - ->orderBy('id'); |
|
| 361 | - |
|
| 362 | - $cursor = $qb->execute(); |
|
| 363 | - while($data = $cursor->fetch()) { |
|
| 364 | - $children[] = $this->createShareObject($data); |
|
| 365 | - } |
|
| 366 | - $cursor->closeCursor(); |
|
| 367 | - |
|
| 368 | - return $children; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * add share to the database and return the ID |
|
| 373 | - * |
|
| 374 | - * @param int $itemSource |
|
| 375 | - * @param string $itemType |
|
| 376 | - * @param string $shareWith |
|
| 377 | - * @param string $sharedBy |
|
| 378 | - * @param string $uidOwner |
|
| 379 | - * @param int $permissions |
|
| 380 | - * @param string $token |
|
| 381 | - * @return int |
|
| 382 | - */ |
|
| 383 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 384 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 385 | - $qb->insert('share') |
|
| 386 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 387 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 388 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 389 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 390 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 391 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 392 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 393 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 394 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
| 395 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 396 | - |
|
| 397 | - /* |
|
| 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]), false); |
|
| 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 | + $emailTemplate->addBodyText( |
|
| 276 | + $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
| 277 | + $text |
|
| 278 | + ); |
|
| 279 | + |
|
| 280 | + $emailTemplate->addBodyButton( |
|
| 281 | + $this->l->t('Open »%s«', [$filename]), |
|
| 282 | + $link |
|
| 283 | + ); |
|
| 284 | + $emailTemplate->addFooter(); |
|
| 285 | + |
|
| 286 | + $message->setTo([$shareWith]); |
|
| 287 | + $message->setSubject($subject); |
|
| 288 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
| 289 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
| 290 | + $this->mailer->send($message); |
|
| 291 | + |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * send password to recipient of a mail share |
|
| 296 | + * |
|
| 297 | + * @param string $filename |
|
| 298 | + * @param string $initiator |
|
| 299 | + * @param string $shareWith |
|
| 300 | + */ |
|
| 301 | + protected function sendPassword($filename, $initiator, $shareWith, $password) { |
|
| 302 | + |
|
| 303 | + if ($this->settingsManager->sendPasswordByMail() === false) { |
|
| 304 | + return; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $initiatorUser = $this->userManager->get($initiator); |
|
| 308 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
| 309 | + $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
| 310 | + |
|
| 311 | + $message = $this->mailer->createMessage(); |
|
| 312 | + |
|
| 313 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
| 314 | + |
|
| 315 | + $emailTemplate->addHeader(); |
|
| 316 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); |
|
| 317 | + |
|
| 318 | + $emailTemplate->addBodyText($this->l->t( |
|
| 319 | + '%s shared »%s« with you. You should have already received a separate mail with a link to access it.', |
|
| 320 | + [$initiatorDisplayName, $filename] |
|
| 321 | + )); |
|
| 322 | + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
| 323 | + |
|
| 324 | + $emailTemplate->addFooter(); |
|
| 325 | + |
|
| 326 | + $message->setTo([$shareWith]); |
|
| 327 | + $message->setSubject($subject); |
|
| 328 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
| 329 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
| 330 | + $this->mailer->send($message); |
|
| 331 | + |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * generate share token |
|
| 337 | + * |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + protected function generateToken() { |
|
| 341 | + $token = $this->secureRandom->generate( |
|
| 342 | + 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 343 | + return $token; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Get all children of this share |
|
| 348 | + * |
|
| 349 | + * @param IShare $parent |
|
| 350 | + * @return IShare[] |
|
| 351 | + */ |
|
| 352 | + public function getChildren(IShare $parent) { |
|
| 353 | + $children = []; |
|
| 354 | + |
|
| 355 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 356 | + $qb->select('*') |
|
| 357 | + ->from('share') |
|
| 358 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 359 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 360 | + ->orderBy('id'); |
|
| 361 | + |
|
| 362 | + $cursor = $qb->execute(); |
|
| 363 | + while($data = $cursor->fetch()) { |
|
| 364 | + $children[] = $this->createShareObject($data); |
|
| 365 | + } |
|
| 366 | + $cursor->closeCursor(); |
|
| 367 | + |
|
| 368 | + return $children; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * add share to the database and return the ID |
|
| 373 | + * |
|
| 374 | + * @param int $itemSource |
|
| 375 | + * @param string $itemType |
|
| 376 | + * @param string $shareWith |
|
| 377 | + * @param string $sharedBy |
|
| 378 | + * @param string $uidOwner |
|
| 379 | + * @param int $permissions |
|
| 380 | + * @param string $token |
|
| 381 | + * @return int |
|
| 382 | + */ |
|
| 383 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 384 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 385 | + $qb->insert('share') |
|
| 386 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 387 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 388 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 389 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 390 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 391 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 392 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 393 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 394 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
| 395 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 396 | + |
|
| 397 | + /* |
|
| 398 | 398 | * Added to fix https://github.com/owncloud/core/issues/22215 |
| 399 | 399 | * Can be removed once we get rid of ajax/share.php |
| 400 | 400 | */ |
| 401 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 401 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 402 | 402 | |
| 403 | - $qb->execute(); |
|
| 404 | - $id = $qb->getLastInsertId(); |
|
| 403 | + $qb->execute(); |
|
| 404 | + $id = $qb->getLastInsertId(); |
|
| 405 | 405 | |
| 406 | - return (int)$id; |
|
| 407 | - } |
|
| 406 | + return (int)$id; |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - /** |
|
| 410 | - * Update a share |
|
| 411 | - * |
|
| 412 | - * @param IShare $share |
|
| 413 | - * @param string|null $plainTextPassword |
|
| 414 | - * @return IShare The share object |
|
| 415 | - */ |
|
| 416 | - public function update(IShare $share, $plainTextPassword = null) { |
|
| 409 | + /** |
|
| 410 | + * Update a share |
|
| 411 | + * |
|
| 412 | + * @param IShare $share |
|
| 413 | + * @param string|null $plainTextPassword |
|
| 414 | + * @return IShare The share object |
|
| 415 | + */ |
|
| 416 | + public function update(IShare $share, $plainTextPassword = null) { |
|
| 417 | 417 | |
| 418 | - $originalShare = $this->getShareById($share->getId()); |
|
| 418 | + $originalShare = $this->getShareById($share->getId()); |
|
| 419 | 419 | |
| 420 | - // a real password was given |
|
| 421 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
| 420 | + // a real password was given |
|
| 421 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
| 422 | 422 | |
| 423 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 424 | - $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
|
| 425 | - } |
|
| 426 | - /* |
|
| 423 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 424 | + $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
|
| 425 | + } |
|
| 426 | + /* |
|
| 427 | 427 | * We allow updating the permissions and password of mail shares |
| 428 | 428 | */ |
| 429 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 430 | - $qb->update('share') |
|
| 431 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 432 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 433 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 434 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 435 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
| 436 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
| 437 | - ->execute(); |
|
| 438 | - |
|
| 439 | - return $share; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @inheritdoc |
|
| 444 | - */ |
|
| 445 | - public function move(IShare $share, $recipient) { |
|
| 446 | - /** |
|
| 447 | - * nothing to do here, mail shares are only outgoing shares |
|
| 448 | - */ |
|
| 449 | - return $share; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Delete a share (owner unShares the file) |
|
| 454 | - * |
|
| 455 | - * @param IShare $share |
|
| 456 | - */ |
|
| 457 | - public function delete(IShare $share) { |
|
| 458 | - $this->removeShareFromTable($share->getId()); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * @inheritdoc |
|
| 463 | - */ |
|
| 464 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
| 465 | - // nothing to do here, mail shares are only outgoing shares |
|
| 466 | - return; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * @inheritdoc |
|
| 471 | - */ |
|
| 472 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 473 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 474 | - $qb->select('*') |
|
| 475 | - ->from('share'); |
|
| 476 | - |
|
| 477 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Reshares for this user are shares where they are the owner. |
|
| 481 | - */ |
|
| 482 | - if ($reshares === false) { |
|
| 483 | - //Special case for old shares created via the web UI |
|
| 484 | - $or1 = $qb->expr()->andX( |
|
| 485 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 486 | - $qb->expr()->isNull('uid_initiator') |
|
| 487 | - ); |
|
| 488 | - |
|
| 489 | - $qb->andWhere( |
|
| 490 | - $qb->expr()->orX( |
|
| 491 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 492 | - $or1 |
|
| 493 | - ) |
|
| 494 | - ); |
|
| 495 | - } else { |
|
| 496 | - $qb->andWhere( |
|
| 497 | - $qb->expr()->orX( |
|
| 498 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 499 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 500 | - ) |
|
| 501 | - ); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - if ($node !== null) { |
|
| 505 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - if ($limit !== -1) { |
|
| 509 | - $qb->setMaxResults($limit); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - $qb->setFirstResult($offset); |
|
| 513 | - $qb->orderBy('id'); |
|
| 514 | - |
|
| 515 | - $cursor = $qb->execute(); |
|
| 516 | - $shares = []; |
|
| 517 | - while($data = $cursor->fetch()) { |
|
| 518 | - $shares[] = $this->createShareObject($data); |
|
| 519 | - } |
|
| 520 | - $cursor->closeCursor(); |
|
| 521 | - |
|
| 522 | - return $shares; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @inheritdoc |
|
| 527 | - */ |
|
| 528 | - public function getShareById($id, $recipientId = null) { |
|
| 529 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 530 | - |
|
| 531 | - $qb->select('*') |
|
| 532 | - ->from('share') |
|
| 533 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 534 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 535 | - |
|
| 536 | - $cursor = $qb->execute(); |
|
| 537 | - $data = $cursor->fetch(); |
|
| 538 | - $cursor->closeCursor(); |
|
| 539 | - |
|
| 540 | - if ($data === false) { |
|
| 541 | - throw new ShareNotFound(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - try { |
|
| 545 | - $share = $this->createShareObject($data); |
|
| 546 | - } catch (InvalidShare $e) { |
|
| 547 | - throw new ShareNotFound(); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return $share; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Get shares for a given path |
|
| 555 | - * |
|
| 556 | - * @param \OCP\Files\Node $path |
|
| 557 | - * @return IShare[] |
|
| 558 | - */ |
|
| 559 | - public function getSharesByPath(Node $path) { |
|
| 560 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 561 | - |
|
| 562 | - $cursor = $qb->select('*') |
|
| 563 | - ->from('share') |
|
| 564 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 565 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 566 | - ->execute(); |
|
| 567 | - |
|
| 568 | - $shares = []; |
|
| 569 | - while($data = $cursor->fetch()) { |
|
| 570 | - $shares[] = $this->createShareObject($data); |
|
| 571 | - } |
|
| 572 | - $cursor->closeCursor(); |
|
| 573 | - |
|
| 574 | - return $shares; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @inheritdoc |
|
| 579 | - */ |
|
| 580 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 581 | - /** @var IShare[] $shares */ |
|
| 582 | - $shares = []; |
|
| 583 | - |
|
| 584 | - //Get shares directly with this user |
|
| 585 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 586 | - $qb->select('*') |
|
| 587 | - ->from('share'); |
|
| 588 | - |
|
| 589 | - // Order by id |
|
| 590 | - $qb->orderBy('id'); |
|
| 591 | - |
|
| 592 | - // Set limit and offset |
|
| 593 | - if ($limit !== -1) { |
|
| 594 | - $qb->setMaxResults($limit); |
|
| 595 | - } |
|
| 596 | - $qb->setFirstResult($offset); |
|
| 597 | - |
|
| 598 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 599 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 600 | - |
|
| 601 | - // Filter by node if provided |
|
| 602 | - if ($node !== null) { |
|
| 603 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - $cursor = $qb->execute(); |
|
| 607 | - |
|
| 608 | - while($data = $cursor->fetch()) { |
|
| 609 | - $shares[] = $this->createShareObject($data); |
|
| 610 | - } |
|
| 611 | - $cursor->closeCursor(); |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - return $shares; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Get a share by token |
|
| 619 | - * |
|
| 620 | - * @param string $token |
|
| 621 | - * @return IShare |
|
| 622 | - * @throws ShareNotFound |
|
| 623 | - */ |
|
| 624 | - public function getShareByToken($token) { |
|
| 625 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 626 | - |
|
| 627 | - $cursor = $qb->select('*') |
|
| 628 | - ->from('share') |
|
| 629 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 630 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 631 | - ->execute(); |
|
| 632 | - |
|
| 633 | - $data = $cursor->fetch(); |
|
| 634 | - |
|
| 635 | - if ($data === false) { |
|
| 636 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - try { |
|
| 640 | - $share = $this->createShareObject($data); |
|
| 641 | - } catch (InvalidShare $e) { |
|
| 642 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - return $share; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * remove share from table |
|
| 650 | - * |
|
| 651 | - * @param string $shareId |
|
| 652 | - */ |
|
| 653 | - protected function removeShareFromTable($shareId) { |
|
| 654 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 655 | - $qb->delete('share') |
|
| 656 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 657 | - $qb->execute(); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Create a share object from an database row |
|
| 662 | - * |
|
| 663 | - * @param array $data |
|
| 664 | - * @return IShare |
|
| 665 | - * @throws InvalidShare |
|
| 666 | - * @throws ShareNotFound |
|
| 667 | - */ |
|
| 668 | - protected function createShareObject($data) { |
|
| 669 | - |
|
| 670 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 671 | - $share->setId((int)$data['id']) |
|
| 672 | - ->setShareType((int)$data['share_type']) |
|
| 673 | - ->setPermissions((int)$data['permissions']) |
|
| 674 | - ->setTarget($data['file_target']) |
|
| 675 | - ->setMailSend((bool)$data['mail_send']) |
|
| 676 | - ->setToken($data['token']); |
|
| 677 | - |
|
| 678 | - $shareTime = new \DateTime(); |
|
| 679 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 680 | - $share->setShareTime($shareTime); |
|
| 681 | - $share->setSharedWith($data['share_with']); |
|
| 682 | - $share->setPassword($data['password']); |
|
| 683 | - |
|
| 684 | - if ($data['uid_initiator'] !== null) { |
|
| 685 | - $share->setShareOwner($data['uid_owner']); |
|
| 686 | - $share->setSharedBy($data['uid_initiator']); |
|
| 687 | - } else { |
|
| 688 | - //OLD SHARE |
|
| 689 | - $share->setSharedBy($data['uid_owner']); |
|
| 690 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 691 | - |
|
| 692 | - $owner = $path->getOwner(); |
|
| 693 | - $share->setShareOwner($owner->getUID()); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - if ($data['expiration'] !== null) { |
|
| 697 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
| 698 | - if ($expiration !== false) { |
|
| 699 | - $share->setExpirationDate($expiration); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - $share->setNodeId((int)$data['file_source']); |
|
| 704 | - $share->setNodeType($data['item_type']); |
|
| 705 | - |
|
| 706 | - $share->setProviderId($this->identifier()); |
|
| 707 | - |
|
| 708 | - return $share; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Get the node with file $id for $user |
|
| 713 | - * |
|
| 714 | - * @param string $userId |
|
| 715 | - * @param int $id |
|
| 716 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 717 | - * @throws InvalidShare |
|
| 718 | - */ |
|
| 719 | - private function getNode($userId, $id) { |
|
| 720 | - try { |
|
| 721 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 722 | - } catch (NotFoundException $e) { |
|
| 723 | - throw new InvalidShare(); |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - $nodes = $userFolder->getById($id); |
|
| 727 | - |
|
| 728 | - if (empty($nodes)) { |
|
| 729 | - throw new InvalidShare(); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - return $nodes[0]; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * A user is deleted from the system |
|
| 737 | - * So clean up the relevant shares. |
|
| 738 | - * |
|
| 739 | - * @param string $uid |
|
| 740 | - * @param int $shareType |
|
| 741 | - */ |
|
| 742 | - public function userDeleted($uid, $shareType) { |
|
| 743 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 744 | - |
|
| 745 | - $qb->delete('share') |
|
| 746 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 747 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 748 | - ->execute(); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * This provider does not support group shares |
|
| 753 | - * |
|
| 754 | - * @param string $gid |
|
| 755 | - */ |
|
| 756 | - public function groupDeleted($gid) { |
|
| 757 | - return; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * This provider does not support group shares |
|
| 762 | - * |
|
| 763 | - * @param string $uid |
|
| 764 | - * @param string $gid |
|
| 765 | - */ |
|
| 766 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 767 | - return; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * get database row of a give share |
|
| 772 | - * |
|
| 773 | - * @param $id |
|
| 774 | - * @return array |
|
| 775 | - * @throws ShareNotFound |
|
| 776 | - */ |
|
| 777 | - protected function getRawShare($id) { |
|
| 778 | - |
|
| 779 | - // Now fetch the inserted share and create a complete share object |
|
| 780 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 781 | - $qb->select('*') |
|
| 782 | - ->from('share') |
|
| 783 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 784 | - |
|
| 785 | - $cursor = $qb->execute(); |
|
| 786 | - $data = $cursor->fetch(); |
|
| 787 | - $cursor->closeCursor(); |
|
| 788 | - |
|
| 789 | - if ($data === false) { |
|
| 790 | - throw new ShareNotFound; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - return $data; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 797 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 798 | - $qb->select('*') |
|
| 799 | - ->from('share', 's') |
|
| 800 | - ->andWhere($qb->expr()->orX( |
|
| 801 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 802 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 803 | - )) |
|
| 804 | - ->andWhere( |
|
| 805 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 806 | - ); |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * Reshares for this user are shares where they are the owner. |
|
| 810 | - */ |
|
| 811 | - if ($reshares === false) { |
|
| 812 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 813 | - } else { |
|
| 814 | - $qb->andWhere( |
|
| 815 | - $qb->expr()->orX( |
|
| 816 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 817 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 818 | - ) |
|
| 819 | - ); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 823 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 824 | - |
|
| 825 | - $qb->orderBy('id'); |
|
| 826 | - |
|
| 827 | - $cursor = $qb->execute(); |
|
| 828 | - $shares = []; |
|
| 829 | - while ($data = $cursor->fetch()) { |
|
| 830 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 831 | - } |
|
| 832 | - $cursor->closeCursor(); |
|
| 833 | - |
|
| 834 | - return $shares; |
|
| 835 | - } |
|
| 429 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 430 | + $qb->update('share') |
|
| 431 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 432 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 433 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 434 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 435 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
| 436 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
| 437 | + ->execute(); |
|
| 438 | + |
|
| 439 | + return $share; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @inheritdoc |
|
| 444 | + */ |
|
| 445 | + public function move(IShare $share, $recipient) { |
|
| 446 | + /** |
|
| 447 | + * nothing to do here, mail shares are only outgoing shares |
|
| 448 | + */ |
|
| 449 | + return $share; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Delete a share (owner unShares the file) |
|
| 454 | + * |
|
| 455 | + * @param IShare $share |
|
| 456 | + */ |
|
| 457 | + public function delete(IShare $share) { |
|
| 458 | + $this->removeShareFromTable($share->getId()); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @inheritdoc |
|
| 463 | + */ |
|
| 464 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
| 465 | + // nothing to do here, mail shares are only outgoing shares |
|
| 466 | + return; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * @inheritdoc |
|
| 471 | + */ |
|
| 472 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 473 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 474 | + $qb->select('*') |
|
| 475 | + ->from('share'); |
|
| 476 | + |
|
| 477 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Reshares for this user are shares where they are the owner. |
|
| 481 | + */ |
|
| 482 | + if ($reshares === false) { |
|
| 483 | + //Special case for old shares created via the web UI |
|
| 484 | + $or1 = $qb->expr()->andX( |
|
| 485 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 486 | + $qb->expr()->isNull('uid_initiator') |
|
| 487 | + ); |
|
| 488 | + |
|
| 489 | + $qb->andWhere( |
|
| 490 | + $qb->expr()->orX( |
|
| 491 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 492 | + $or1 |
|
| 493 | + ) |
|
| 494 | + ); |
|
| 495 | + } else { |
|
| 496 | + $qb->andWhere( |
|
| 497 | + $qb->expr()->orX( |
|
| 498 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 499 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 500 | + ) |
|
| 501 | + ); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + if ($node !== null) { |
|
| 505 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + if ($limit !== -1) { |
|
| 509 | + $qb->setMaxResults($limit); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $qb->setFirstResult($offset); |
|
| 513 | + $qb->orderBy('id'); |
|
| 514 | + |
|
| 515 | + $cursor = $qb->execute(); |
|
| 516 | + $shares = []; |
|
| 517 | + while($data = $cursor->fetch()) { |
|
| 518 | + $shares[] = $this->createShareObject($data); |
|
| 519 | + } |
|
| 520 | + $cursor->closeCursor(); |
|
| 521 | + |
|
| 522 | + return $shares; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @inheritdoc |
|
| 527 | + */ |
|
| 528 | + public function getShareById($id, $recipientId = null) { |
|
| 529 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 530 | + |
|
| 531 | + $qb->select('*') |
|
| 532 | + ->from('share') |
|
| 533 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 534 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 535 | + |
|
| 536 | + $cursor = $qb->execute(); |
|
| 537 | + $data = $cursor->fetch(); |
|
| 538 | + $cursor->closeCursor(); |
|
| 539 | + |
|
| 540 | + if ($data === false) { |
|
| 541 | + throw new ShareNotFound(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + try { |
|
| 545 | + $share = $this->createShareObject($data); |
|
| 546 | + } catch (InvalidShare $e) { |
|
| 547 | + throw new ShareNotFound(); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return $share; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Get shares for a given path |
|
| 555 | + * |
|
| 556 | + * @param \OCP\Files\Node $path |
|
| 557 | + * @return IShare[] |
|
| 558 | + */ |
|
| 559 | + public function getSharesByPath(Node $path) { |
|
| 560 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 561 | + |
|
| 562 | + $cursor = $qb->select('*') |
|
| 563 | + ->from('share') |
|
| 564 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 565 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 566 | + ->execute(); |
|
| 567 | + |
|
| 568 | + $shares = []; |
|
| 569 | + while($data = $cursor->fetch()) { |
|
| 570 | + $shares[] = $this->createShareObject($data); |
|
| 571 | + } |
|
| 572 | + $cursor->closeCursor(); |
|
| 573 | + |
|
| 574 | + return $shares; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @inheritdoc |
|
| 579 | + */ |
|
| 580 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 581 | + /** @var IShare[] $shares */ |
|
| 582 | + $shares = []; |
|
| 583 | + |
|
| 584 | + //Get shares directly with this user |
|
| 585 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 586 | + $qb->select('*') |
|
| 587 | + ->from('share'); |
|
| 588 | + |
|
| 589 | + // Order by id |
|
| 590 | + $qb->orderBy('id'); |
|
| 591 | + |
|
| 592 | + // Set limit and offset |
|
| 593 | + if ($limit !== -1) { |
|
| 594 | + $qb->setMaxResults($limit); |
|
| 595 | + } |
|
| 596 | + $qb->setFirstResult($offset); |
|
| 597 | + |
|
| 598 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
| 599 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 600 | + |
|
| 601 | + // Filter by node if provided |
|
| 602 | + if ($node !== null) { |
|
| 603 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + $cursor = $qb->execute(); |
|
| 607 | + |
|
| 608 | + while($data = $cursor->fetch()) { |
|
| 609 | + $shares[] = $this->createShareObject($data); |
|
| 610 | + } |
|
| 611 | + $cursor->closeCursor(); |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + return $shares; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Get a share by token |
|
| 619 | + * |
|
| 620 | + * @param string $token |
|
| 621 | + * @return IShare |
|
| 622 | + * @throws ShareNotFound |
|
| 623 | + */ |
|
| 624 | + public function getShareByToken($token) { |
|
| 625 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 626 | + |
|
| 627 | + $cursor = $qb->select('*') |
|
| 628 | + ->from('share') |
|
| 629 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 630 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 631 | + ->execute(); |
|
| 632 | + |
|
| 633 | + $data = $cursor->fetch(); |
|
| 634 | + |
|
| 635 | + if ($data === false) { |
|
| 636 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + try { |
|
| 640 | + $share = $this->createShareObject($data); |
|
| 641 | + } catch (InvalidShare $e) { |
|
| 642 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + return $share; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * remove share from table |
|
| 650 | + * |
|
| 651 | + * @param string $shareId |
|
| 652 | + */ |
|
| 653 | + protected function removeShareFromTable($shareId) { |
|
| 654 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 655 | + $qb->delete('share') |
|
| 656 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 657 | + $qb->execute(); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Create a share object from an database row |
|
| 662 | + * |
|
| 663 | + * @param array $data |
|
| 664 | + * @return IShare |
|
| 665 | + * @throws InvalidShare |
|
| 666 | + * @throws ShareNotFound |
|
| 667 | + */ |
|
| 668 | + protected function createShareObject($data) { |
|
| 669 | + |
|
| 670 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 671 | + $share->setId((int)$data['id']) |
|
| 672 | + ->setShareType((int)$data['share_type']) |
|
| 673 | + ->setPermissions((int)$data['permissions']) |
|
| 674 | + ->setTarget($data['file_target']) |
|
| 675 | + ->setMailSend((bool)$data['mail_send']) |
|
| 676 | + ->setToken($data['token']); |
|
| 677 | + |
|
| 678 | + $shareTime = new \DateTime(); |
|
| 679 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 680 | + $share->setShareTime($shareTime); |
|
| 681 | + $share->setSharedWith($data['share_with']); |
|
| 682 | + $share->setPassword($data['password']); |
|
| 683 | + |
|
| 684 | + if ($data['uid_initiator'] !== null) { |
|
| 685 | + $share->setShareOwner($data['uid_owner']); |
|
| 686 | + $share->setSharedBy($data['uid_initiator']); |
|
| 687 | + } else { |
|
| 688 | + //OLD SHARE |
|
| 689 | + $share->setSharedBy($data['uid_owner']); |
|
| 690 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 691 | + |
|
| 692 | + $owner = $path->getOwner(); |
|
| 693 | + $share->setShareOwner($owner->getUID()); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + if ($data['expiration'] !== null) { |
|
| 697 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
| 698 | + if ($expiration !== false) { |
|
| 699 | + $share->setExpirationDate($expiration); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + $share->setNodeId((int)$data['file_source']); |
|
| 704 | + $share->setNodeType($data['item_type']); |
|
| 705 | + |
|
| 706 | + $share->setProviderId($this->identifier()); |
|
| 707 | + |
|
| 708 | + return $share; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Get the node with file $id for $user |
|
| 713 | + * |
|
| 714 | + * @param string $userId |
|
| 715 | + * @param int $id |
|
| 716 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 717 | + * @throws InvalidShare |
|
| 718 | + */ |
|
| 719 | + private function getNode($userId, $id) { |
|
| 720 | + try { |
|
| 721 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 722 | + } catch (NotFoundException $e) { |
|
| 723 | + throw new InvalidShare(); |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + $nodes = $userFolder->getById($id); |
|
| 727 | + |
|
| 728 | + if (empty($nodes)) { |
|
| 729 | + throw new InvalidShare(); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + return $nodes[0]; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * A user is deleted from the system |
|
| 737 | + * So clean up the relevant shares. |
|
| 738 | + * |
|
| 739 | + * @param string $uid |
|
| 740 | + * @param int $shareType |
|
| 741 | + */ |
|
| 742 | + public function userDeleted($uid, $shareType) { |
|
| 743 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 744 | + |
|
| 745 | + $qb->delete('share') |
|
| 746 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
| 747 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 748 | + ->execute(); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * This provider does not support group shares |
|
| 753 | + * |
|
| 754 | + * @param string $gid |
|
| 755 | + */ |
|
| 756 | + public function groupDeleted($gid) { |
|
| 757 | + return; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * This provider does not support group shares |
|
| 762 | + * |
|
| 763 | + * @param string $uid |
|
| 764 | + * @param string $gid |
|
| 765 | + */ |
|
| 766 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 767 | + return; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * get database row of a give share |
|
| 772 | + * |
|
| 773 | + * @param $id |
|
| 774 | + * @return array |
|
| 775 | + * @throws ShareNotFound |
|
| 776 | + */ |
|
| 777 | + protected function getRawShare($id) { |
|
| 778 | + |
|
| 779 | + // Now fetch the inserted share and create a complete share object |
|
| 780 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 781 | + $qb->select('*') |
|
| 782 | + ->from('share') |
|
| 783 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 784 | + |
|
| 785 | + $cursor = $qb->execute(); |
|
| 786 | + $data = $cursor->fetch(); |
|
| 787 | + $cursor->closeCursor(); |
|
| 788 | + |
|
| 789 | + if ($data === false) { |
|
| 790 | + throw new ShareNotFound; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + return $data; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 797 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 798 | + $qb->select('*') |
|
| 799 | + ->from('share', 's') |
|
| 800 | + ->andWhere($qb->expr()->orX( |
|
| 801 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 802 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 803 | + )) |
|
| 804 | + ->andWhere( |
|
| 805 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
| 806 | + ); |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Reshares for this user are shares where they are the owner. |
|
| 810 | + */ |
|
| 811 | + if ($reshares === false) { |
|
| 812 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 813 | + } else { |
|
| 814 | + $qb->andWhere( |
|
| 815 | + $qb->expr()->orX( |
|
| 816 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 817 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 818 | + ) |
|
| 819 | + ); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 823 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 824 | + |
|
| 825 | + $qb->orderBy('id'); |
|
| 826 | + |
|
| 827 | + $cursor = $qb->execute(); |
|
| 828 | + $shares = []; |
|
| 829 | + while ($data = $cursor->fetch()) { |
|
| 830 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 831 | + } |
|
| 832 | + $cursor->closeCursor(); |
|
| 833 | + |
|
| 834 | + return $shares; |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | 837 | } |
@@ -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,11 +269,11 @@ 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 | 275 | $emailTemplate->addBodyText( |
| 276 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
| 276 | + $text.' '.$this->l->t('Click the button below to open it.'), |
|
| 277 | 277 | $text |
| 278 | 278 | ); |
| 279 | 279 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | $initiatorUser = $this->userManager->get($initiator); |
| 308 | 308 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
| 309 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
| 309 | + $subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
| 310 | 310 | |
| 311 | 311 | $message = $this->mailer->createMessage(); |
| 312 | 312 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | protected function generateToken() { |
| 341 | 341 | $token = $this->secureRandom->generate( |
| 342 | - 15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
| 342 | + 15, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
| 343 | 343 | return $token; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | ->orderBy('id'); |
| 361 | 361 | |
| 362 | 362 | $cursor = $qb->execute(); |
| 363 | - while($data = $cursor->fetch()) { |
|
| 363 | + while ($data = $cursor->fetch()) { |
|
| 364 | 364 | $children[] = $this->createShareObject($data); |
| 365 | 365 | } |
| 366 | 366 | $cursor->closeCursor(); |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | $qb->execute(); |
| 404 | 404 | $id = $qb->getLastInsertId(); |
| 405 | 405 | |
| 406 | - return (int)$id; |
|
| 406 | + return (int) $id; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | // a real password was given |
| 421 | 421 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
| 422 | 422 | |
| 423 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 423 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
| 424 | 424 | $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword); |
| 425 | 425 | } |
| 426 | 426 | /* |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | $cursor = $qb->execute(); |
| 516 | 516 | $shares = []; |
| 517 | - while($data = $cursor->fetch()) { |
|
| 517 | + while ($data = $cursor->fetch()) { |
|
| 518 | 518 | $shares[] = $this->createShareObject($data); |
| 519 | 519 | } |
| 520 | 520 | $cursor->closeCursor(); |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | ->execute(); |
| 567 | 567 | |
| 568 | 568 | $shares = []; |
| 569 | - while($data = $cursor->fetch()) { |
|
| 569 | + while ($data = $cursor->fetch()) { |
|
| 570 | 570 | $shares[] = $this->createShareObject($data); |
| 571 | 571 | } |
| 572 | 572 | $cursor->closeCursor(); |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | |
| 606 | 606 | $cursor = $qb->execute(); |
| 607 | 607 | |
| 608 | - while($data = $cursor->fetch()) { |
|
| 608 | + while ($data = $cursor->fetch()) { |
|
| 609 | 609 | $shares[] = $this->createShareObject($data); |
| 610 | 610 | } |
| 611 | 611 | $cursor->closeCursor(); |
@@ -668,15 +668,15 @@ discard block |
||
| 668 | 668 | protected function createShareObject($data) { |
| 669 | 669 | |
| 670 | 670 | $share = new Share($this->rootFolder, $this->userManager); |
| 671 | - $share->setId((int)$data['id']) |
|
| 672 | - ->setShareType((int)$data['share_type']) |
|
| 673 | - ->setPermissions((int)$data['permissions']) |
|
| 671 | + $share->setId((int) $data['id']) |
|
| 672 | + ->setShareType((int) $data['share_type']) |
|
| 673 | + ->setPermissions((int) $data['permissions']) |
|
| 674 | 674 | ->setTarget($data['file_target']) |
| 675 | - ->setMailSend((bool)$data['mail_send']) |
|
| 675 | + ->setMailSend((bool) $data['mail_send']) |
|
| 676 | 676 | ->setToken($data['token']); |
| 677 | 677 | |
| 678 | 678 | $shareTime = new \DateTime(); |
| 679 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 679 | + $shareTime->setTimestamp((int) $data['stime']); |
|
| 680 | 680 | $share->setShareTime($shareTime); |
| 681 | 681 | $share->setSharedWith($data['share_with']); |
| 682 | 682 | $share->setPassword($data['password']); |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | } else { |
| 688 | 688 | //OLD SHARE |
| 689 | 689 | $share->setSharedBy($data['uid_owner']); |
| 690 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 690 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
| 691 | 691 | |
| 692 | 692 | $owner = $path->getOwner(); |
| 693 | 693 | $share->setShareOwner($owner->getUID()); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | } |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - $share->setNodeId((int)$data['file_source']); |
|
| 703 | + $share->setNodeId((int) $data['file_source']); |
|
| 704 | 704 | $share->setNodeType($data['item_type']); |
| 705 | 705 | |
| 706 | 706 | $share->setProviderId($this->identifier()); |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | ); |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 822 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 823 | 823 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
| 824 | 824 | |
| 825 | 825 | $qb->orderBy('id'); |
@@ -335,7 +335,7 @@ |
||
| 335 | 335 | * Adds a heading to the email |
| 336 | 336 | * |
| 337 | 337 | * @param string $title |
| 338 | - * @param string $plainTitle|bool Title that is used in the plain text email |
|
| 338 | + * @param string $plainTitle Title that is used in the plain text email |
|
| 339 | 339 | * if empty the $title is used, if false none will be used |
| 340 | 340 | */ |
| 341 | 341 | public function addHeading($title, $plainTitle = '') { |
@@ -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,199 +304,199 @@ 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, $this->themingDefaults->getName()]); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Adds a heading to the email |
|
| 336 | - * |
|
| 337 | - * @param string $title |
|
| 338 | - * @param string $plainTitle|bool Title that is used in the plain text email |
|
| 339 | - * if empty the $title is used, if false none will be used |
|
| 340 | - */ |
|
| 341 | - public function addHeading($title, $plainTitle = '') { |
|
| 342 | - if ($this->footerAdded) { |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - if ($plainTitle === '') { |
|
| 346 | - $plainTitle = $title; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 350 | - if ($plainTitle !== false) { |
|
| 351 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Adds a paragraph to the body of the email |
|
| 357 | - * |
|
| 358 | - * @param string $text |
|
| 359 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 360 | - * if empty the $text is used, if false none will be used |
|
| 361 | - */ |
|
| 362 | - public function addBodyText($text, $plainText = '') { |
|
| 363 | - if ($this->footerAdded) { |
|
| 364 | - return; |
|
| 365 | - } |
|
| 366 | - if ($plainText === '') { |
|
| 367 | - $plainText = $text; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - if (!$this->bodyOpened) { |
|
| 371 | - $this->htmlBody .= $this->bodyBegin; |
|
| 372 | - $this->bodyOpened = true; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
|
| 376 | - if ($plainText !== false) { |
|
| 377 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Adds a button group of two buttons to the body of the email |
|
| 383 | - * |
|
| 384 | - * @param string $textLeft Text of left button |
|
| 385 | - * @param string $urlLeft URL of left button |
|
| 386 | - * @param string $textRight Text of right button |
|
| 387 | - * @param string $urlRight URL of right button |
|
| 388 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 389 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 390 | - */ |
|
| 391 | - public function addBodyButtonGroup($textLeft, |
|
| 392 | - $urlLeft, |
|
| 393 | - $textRight, |
|
| 394 | - $urlRight, |
|
| 395 | - $plainTextLeft = '', |
|
| 396 | - $plainTextRight = '') { |
|
| 397 | - if ($this->footerAdded) { |
|
| 398 | - return; |
|
| 399 | - } |
|
| 400 | - if ($plainTextLeft === '') { |
|
| 401 | - $plainTextLeft = $textLeft; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($plainTextRight === '') { |
|
| 405 | - $plainTextRight = $textRight; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - if (!$this->bodyOpened) { |
|
| 409 | - $this->htmlBody .= $this->bodyBegin; |
|
| 410 | - $this->bodyOpened = true; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 414 | - |
|
| 415 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
|
| 416 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 417 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 418 | - |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Adds a button to the body of the email |
|
| 423 | - * |
|
| 424 | - * @param string $text Text of button |
|
| 425 | - * @param string $url URL of button |
|
| 426 | - * |
|
| 427 | - * @since 12.0.0 |
|
| 428 | - */ |
|
| 429 | - public function addBodyButton($text, $url) { |
|
| 430 | - if ($this->footerAdded) { |
|
| 431 | - return; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - if (!$this->bodyOpened) { |
|
| 435 | - $this->htmlBody .= $this->bodyBegin; |
|
| 436 | - $this->bodyOpened = true; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 440 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
|
| 441 | - $this->plainBody .= $text . ': ' . $url . PHP_EOL; |
|
| 442 | - |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 447 | - * |
|
| 448 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
| 449 | - */ |
|
| 450 | - public function addFooter($text = '') { |
|
| 451 | - if($text === '') { |
|
| 452 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - if ($this->footerAdded) { |
|
| 456 | - return; |
|
| 457 | - } |
|
| 458 | - $this->footerAdded = true; |
|
| 459 | - |
|
| 460 | - if ($this->bodyOpened) { |
|
| 461 | - $this->htmlBody .= $this->bodyEnd; |
|
| 462 | - $this->bodyOpened = false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 466 | - $this->htmlBody .= $this->tail; |
|
| 467 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 468 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Returns the rendered HTML email as string |
|
| 473 | - * |
|
| 474 | - * @return string |
|
| 475 | - */ |
|
| 476 | - public function renderHTML() { |
|
| 477 | - if (!$this->footerAdded) { |
|
| 478 | - $this->footerAdded = true; |
|
| 479 | - if ($this->bodyOpened) { |
|
| 480 | - $this->htmlBody .= $this->bodyEnd; |
|
| 481 | - } |
|
| 482 | - $this->htmlBody .= $this->tail; |
|
| 483 | - } |
|
| 484 | - return $this->htmlBody; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Returns the rendered plain text email as string |
|
| 489 | - * |
|
| 490 | - * @return string |
|
| 491 | - */ |
|
| 492 | - public function renderText() { |
|
| 493 | - if (!$this->footerAdded) { |
|
| 494 | - $this->footerAdded = true; |
|
| 495 | - if ($this->bodyOpened) { |
|
| 496 | - $this->htmlBody .= $this->bodyEnd; |
|
| 497 | - } |
|
| 498 | - $this->htmlBody .= $this->tail; |
|
| 499 | - } |
|
| 500 | - return $this->plainBody; |
|
| 501 | - } |
|
| 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, $this->themingDefaults->getName()]); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Adds a heading to the email |
|
| 336 | + * |
|
| 337 | + * @param string $title |
|
| 338 | + * @param string $plainTitle|bool Title that is used in the plain text email |
|
| 339 | + * if empty the $title is used, if false none will be used |
|
| 340 | + */ |
|
| 341 | + public function addHeading($title, $plainTitle = '') { |
|
| 342 | + if ($this->footerAdded) { |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + if ($plainTitle === '') { |
|
| 346 | + $plainTitle = $title; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 350 | + if ($plainTitle !== false) { |
|
| 351 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Adds a paragraph to the body of the email |
|
| 357 | + * |
|
| 358 | + * @param string $text |
|
| 359 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 360 | + * if empty the $text is used, if false none will be used |
|
| 361 | + */ |
|
| 362 | + public function addBodyText($text, $plainText = '') { |
|
| 363 | + if ($this->footerAdded) { |
|
| 364 | + return; |
|
| 365 | + } |
|
| 366 | + if ($plainText === '') { |
|
| 367 | + $plainText = $text; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + if (!$this->bodyOpened) { |
|
| 371 | + $this->htmlBody .= $this->bodyBegin; |
|
| 372 | + $this->bodyOpened = true; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
|
| 376 | + if ($plainText !== false) { |
|
| 377 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Adds a button group of two buttons to the body of the email |
|
| 383 | + * |
|
| 384 | + * @param string $textLeft Text of left button |
|
| 385 | + * @param string $urlLeft URL of left button |
|
| 386 | + * @param string $textRight Text of right button |
|
| 387 | + * @param string $urlRight URL of right button |
|
| 388 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 389 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 390 | + */ |
|
| 391 | + public function addBodyButtonGroup($textLeft, |
|
| 392 | + $urlLeft, |
|
| 393 | + $textRight, |
|
| 394 | + $urlRight, |
|
| 395 | + $plainTextLeft = '', |
|
| 396 | + $plainTextRight = '') { |
|
| 397 | + if ($this->footerAdded) { |
|
| 398 | + return; |
|
| 399 | + } |
|
| 400 | + if ($plainTextLeft === '') { |
|
| 401 | + $plainTextLeft = $textLeft; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($plainTextRight === '') { |
|
| 405 | + $plainTextRight = $textRight; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if (!$this->bodyOpened) { |
|
| 409 | + $this->htmlBody .= $this->bodyBegin; |
|
| 410 | + $this->bodyOpened = true; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 414 | + |
|
| 415 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
|
| 416 | + $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 417 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 418 | + |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Adds a button to the body of the email |
|
| 423 | + * |
|
| 424 | + * @param string $text Text of button |
|
| 425 | + * @param string $url URL of button |
|
| 426 | + * |
|
| 427 | + * @since 12.0.0 |
|
| 428 | + */ |
|
| 429 | + public function addBodyButton($text, $url) { |
|
| 430 | + if ($this->footerAdded) { |
|
| 431 | + return; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + if (!$this->bodyOpened) { |
|
| 435 | + $this->htmlBody .= $this->bodyBegin; |
|
| 436 | + $this->bodyOpened = true; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 440 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
|
| 441 | + $this->plainBody .= $text . ': ' . $url . PHP_EOL; |
|
| 442 | + |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 447 | + * |
|
| 448 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
| 449 | + */ |
|
| 450 | + public function addFooter($text = '') { |
|
| 451 | + if($text === '') { |
|
| 452 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($this->footerAdded) { |
|
| 456 | + return; |
|
| 457 | + } |
|
| 458 | + $this->footerAdded = true; |
|
| 459 | + |
|
| 460 | + if ($this->bodyOpened) { |
|
| 461 | + $this->htmlBody .= $this->bodyEnd; |
|
| 462 | + $this->bodyOpened = false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 466 | + $this->htmlBody .= $this->tail; |
|
| 467 | + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 468 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Returns the rendered HTML email as string |
|
| 473 | + * |
|
| 474 | + * @return string |
|
| 475 | + */ |
|
| 476 | + public function renderHTML() { |
|
| 477 | + if (!$this->footerAdded) { |
|
| 478 | + $this->footerAdded = true; |
|
| 479 | + if ($this->bodyOpened) { |
|
| 480 | + $this->htmlBody .= $this->bodyEnd; |
|
| 481 | + } |
|
| 482 | + $this->htmlBody .= $this->tail; |
|
| 483 | + } |
|
| 484 | + return $this->htmlBody; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Returns the rendered plain text email as string |
|
| 489 | + * |
|
| 490 | + * @return string |
|
| 491 | + */ |
|
| 492 | + public function renderText() { |
|
| 493 | + if (!$this->footerAdded) { |
|
| 494 | + $this->footerAdded = true; |
|
| 495 | + if ($this->bodyOpened) { |
|
| 496 | + $this->htmlBody .= $this->bodyEnd; |
|
| 497 | + } |
|
| 498 | + $this->htmlBody .= $this->tail; |
|
| 499 | + } |
|
| 500 | + return $this->plainBody; |
|
| 501 | + } |
|
| 502 | 502 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
| 350 | 350 | if ($plainTitle !== false) { |
| 351 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 351 | + $this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL; |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
| 376 | 376 | if ($plainText !== false) { |
| 377 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 377 | + $this->plainBody .= $plainText.PHP_EOL.PHP_EOL; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
@@ -413,8 +413,8 @@ discard block |
||
| 413 | 413 | $color = $this->themingDefaults->getColorPrimary(); |
| 414 | 414 | |
| 415 | 415 | $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
| 416 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 417 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 416 | + $this->plainBody .= $plainTextLeft.': '.$urlLeft.PHP_EOL; |
|
| 417 | + $this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL; |
|
| 418 | 418 | |
| 419 | 419 | } |
| 420 | 420 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | $color = $this->themingDefaults->getColorPrimary(); |
| 440 | 440 | $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
| 441 | - $this->plainBody .= $text . ': ' . $url . PHP_EOL; |
|
| 441 | + $this->plainBody .= $text.': '.$url.PHP_EOL; |
|
| 442 | 442 | |
| 443 | 443 | } |
| 444 | 444 | |
@@ -448,8 +448,8 @@ discard block |
||
| 448 | 448 | * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
| 449 | 449 | */ |
| 450 | 450 | public function addFooter($text = '') { |
| 451 | - if($text === '') { |
|
| 452 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
| 451 | + if ($text === '') { |
|
| 452 | + $text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan().'<br>'.$this->l10n->t('This is an automatically generated email, please do not reply.'); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | if ($this->footerAdded) { |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | |
| 465 | 465 | $this->htmlBody .= vsprintf($this->footer, [$text]); |
| 466 | 466 | $this->htmlBody .= $this->tail; |
| 467 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 467 | + $this->plainBody .= PHP_EOL.'-- '.PHP_EOL; |
|
| 468 | 468 | $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
| 469 | 469 | } |
| 470 | 470 | |
@@ -55,6 +55,7 @@ discard block |
||
| 55 | 55 | * Adds a header to the email |
| 56 | 56 | * |
| 57 | 57 | * @since 12.0.0 |
| 58 | + * @return void |
|
| 58 | 59 | */ |
| 59 | 60 | public function addHeader(); |
| 60 | 61 | |
@@ -62,10 +63,11 @@ discard block |
||
| 62 | 63 | * Adds a heading to the email |
| 63 | 64 | * |
| 64 | 65 | * @param string $title |
| 65 | - * @param string $plainTitle|bool Title that is used in the plain text email |
|
| 66 | + * @param string $plainTitle Title that is used in the plain text email |
|
| 66 | 67 | * if empty the $title is used, if false none will be used |
| 67 | 68 | * |
| 68 | 69 | * @since 12.0.0 |
| 70 | + * @return void |
|
| 69 | 71 | */ |
| 70 | 72 | public function addHeading($title, $plainTitle = ''); |
| 71 | 73 | |
@@ -77,6 +79,7 @@ discard block |
||
| 77 | 79 | * if empty the $text is used, if false none will be used |
| 78 | 80 | * |
| 79 | 81 | * @since 12.0.0 |
| 82 | + * @return void |
|
| 80 | 83 | */ |
| 81 | 84 | public function addBodyText($text, $plainText = ''); |
| 82 | 85 | |
@@ -91,6 +94,7 @@ discard block |
||
| 91 | 94 | * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
| 92 | 95 | * |
| 93 | 96 | * @since 12.0.0 |
| 97 | + * @return void |
|
| 94 | 98 | */ |
| 95 | 99 | public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
| 96 | 100 | |
@@ -101,6 +105,7 @@ discard block |
||
| 101 | 105 | * @param string $url URL of button |
| 102 | 106 | * |
| 103 | 107 | * @since 12.0.0 |
| 108 | + * @return void |
|
| 104 | 109 | */ |
| 105 | 110 | public function addBodyButton($text, $url); |
| 106 | 111 | |
@@ -110,6 +115,7 @@ discard block |
||
| 110 | 115 | * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
| 111 | 116 | * |
| 112 | 117 | * @since 12.0.0 |
| 118 | + * @return void |
|
| 113 | 119 | */ |
| 114 | 120 | public function addFooter($text = ''); |
| 115 | 121 | |
@@ -51,83 +51,83 @@ |
||
| 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|bool Title that is used in the plain text email |
|
| 66 | - * if empty the $title is used, if false none will be used |
|
| 67 | - * |
|
| 68 | - * @since 12.0.0 |
|
| 69 | - */ |
|
| 70 | - public function addHeading($title, $plainTitle = ''); |
|
| 61 | + /** |
|
| 62 | + * Adds a heading to the email |
|
| 63 | + * |
|
| 64 | + * @param string $title |
|
| 65 | + * @param string $plainTitle|bool Title that is used in the plain text email |
|
| 66 | + * if empty the $title is used, if false none will be used |
|
| 67 | + * |
|
| 68 | + * @since 12.0.0 |
|
| 69 | + */ |
|
| 70 | + public function addHeading($title, $plainTitle = ''); |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Adds a paragraph to the body of the email |
|
| 74 | - * |
|
| 75 | - * @param string $text |
|
| 76 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 77 | - * if empty the $text is used, if false none will be used |
|
| 78 | - * |
|
| 79 | - * @since 12.0.0 |
|
| 80 | - */ |
|
| 81 | - public function addBodyText($text, $plainText = ''); |
|
| 72 | + /** |
|
| 73 | + * Adds a paragraph to the body of the email |
|
| 74 | + * |
|
| 75 | + * @param string $text |
|
| 76 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 77 | + * if empty the $text is used, if false none will be used |
|
| 78 | + * |
|
| 79 | + * @since 12.0.0 |
|
| 80 | + */ |
|
| 81 | + public function addBodyText($text, $plainText = ''); |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Adds a button group of two buttons to the body of the email |
|
| 85 | - * |
|
| 86 | - * @param string $textLeft Text of left button |
|
| 87 | - * @param string $urlLeft URL of left button |
|
| 88 | - * @param string $textRight Text of right button |
|
| 89 | - * @param string $urlRight URL of right button |
|
| 90 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
| 91 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
| 92 | - * |
|
| 93 | - * @since 12.0.0 |
|
| 94 | - */ |
|
| 95 | - public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
|
| 83 | + /** |
|
| 84 | + * Adds a button group of two buttons to the body of the email |
|
| 85 | + * |
|
| 86 | + * @param string $textLeft Text of left button |
|
| 87 | + * @param string $urlLeft URL of left button |
|
| 88 | + * @param string $textRight Text of right button |
|
| 89 | + * @param string $urlRight URL of right button |
|
| 90 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
| 91 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
| 92 | + * |
|
| 93 | + * @since 12.0.0 |
|
| 94 | + */ |
|
| 95 | + public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Adds a button to the body of the email |
|
| 99 | - * |
|
| 100 | - * @param string $text Text of button |
|
| 101 | - * @param string $url URL of button |
|
| 102 | - * |
|
| 103 | - * @since 12.0.0 |
|
| 104 | - */ |
|
| 105 | - public function addBodyButton($text, $url); |
|
| 97 | + /** |
|
| 98 | + * Adds a button to the body of the email |
|
| 99 | + * |
|
| 100 | + * @param string $text Text of button |
|
| 101 | + * @param string $url URL of button |
|
| 102 | + * |
|
| 103 | + * @since 12.0.0 |
|
| 104 | + */ |
|
| 105 | + public function addBodyButton($text, $url); |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 109 | - * |
|
| 110 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
| 111 | - * |
|
| 112 | - * @since 12.0.0 |
|
| 113 | - */ |
|
| 114 | - public function addFooter($text = ''); |
|
| 107 | + /** |
|
| 108 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 109 | + * |
|
| 110 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used |
|
| 111 | + * |
|
| 112 | + * @since 12.0.0 |
|
| 113 | + */ |
|
| 114 | + public function addFooter($text = ''); |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Returns the rendered HTML email as string |
|
| 118 | - * |
|
| 119 | - * @return string |
|
| 120 | - * |
|
| 121 | - * @since 12.0.0 |
|
| 122 | - */ |
|
| 123 | - public function renderHTML(); |
|
| 116 | + /** |
|
| 117 | + * Returns the rendered HTML email as string |
|
| 118 | + * |
|
| 119 | + * @return string |
|
| 120 | + * |
|
| 121 | + * @since 12.0.0 |
|
| 122 | + */ |
|
| 123 | + public function renderHTML(); |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Returns the rendered plain text email as string |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - * |
|
| 130 | - * @since 12.0.0 |
|
| 131 | - */ |
|
| 132 | - public function renderText(); |
|
| 125 | + /** |
|
| 126 | + * Returns the rendered plain text email as string |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + * |
|
| 130 | + * @since 12.0.0 |
|
| 131 | + */ |
|
| 132 | + public function renderText(); |
|
| 133 | 133 | } |