Blame view
sources/apps/ownpad_lite/ajax/share.php
1.69 KB
|
42e4f8d60
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<?php
/**
* ownCloud - ownpad_lite plugin
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\ownpad_lite;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::callCheck();
$status = true;
$recipients = UrlParam::post(UrlParam::SHARE_WITH);
$source = UrlParam::post(UrlParam::SHARE_WHAT);
if ($source && $recipients) {
$currentUser = \OCP\User::getUser();
$nameFrom = \OCP\User::getDisplayName($currentUser);
$subject = App::$l10n->t('Document was shared');
$message = App::$l10n->t('User %s shared quick document %s with you.', array($nameFrom, $source));
$pattern = '/(.*)\s+<(.*)>$/';
$recipientList = array(
'name' => array(),
'email' => array(),
);
$sendTo = explode(',', $recipients);
foreach($sendTo as $recipient) {
if (preg_match_all($pattern, $recipient, $matches)) {
// We have 'John Doe <email@example.org>'
$recipientList['name'][] = $matches[1][0];
$recipientList['email'][] = $matches[2][0];
} else {
// Name is unknown, we have email@example.org
$recipientList['name'][] = '';
$recipientList['email'][] = $recipient;
}
}
//We only use the first recipient atm. (OC_Mail doesn't support multiple CC)
$nameTo = array_shift($recipientList['name']);
$emailTo = array_shift($recipientList['email']);
try {
$emailFrom = \OCP\Util::getDefaultEmailAddress('noreply');
\OCP\Util::sendMail(
$emailTo, $nameTo, $subject, $message, $emailFrom, $nameFrom
);
} catch (Exception $e) {
$status = false;
}
} else {
$status = false;
}
if ($status) {
\OCP\JSON::success(array());
} else {
\OCP\JSON::error(array());
}
exit();
|