some clean-up

This commit is contained in:
Bjoern Schiessle 2013-08-30 16:21:52 +02:00
parent 10cf1b3a4e
commit 36574241f8

View file

@ -97,66 +97,47 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
$noMail = array(); $noMail = array();
$recipientList = array(); $recipientList = array();
if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { if($shareType === \OCP\Share::SHARE_TYPE_USER) {
$users = \OC_Group::usersInGroup($recipient); $recipientList[] = $recipient;
foreach ($users as $user) { } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$email = OC_Preferences::getValue($user, 'settings', 'email', ''); $recipientList = \OC_Group::usersInGroup($recipient);
if ($email !== '' || $recipient === \OCP\User::getUser()) {
$recipientList[] = array(
'email' => $email,
'displayName' => \OCP\User::getDisplayName($user),
'uid' => $user,
);
} else {
$noMail[] = \OCP\User::getDisplayName($user);
}
}
} else { // shared to a single user
$email = OC_Preferences::getValue($recipient, 'settings', 'email', '');
if ($email !== '') {
$recipientList[] = array(
'email' => $email,
'displayName' => \OCP\User::getDisplayName($recipient),
'uid' => $recipient,
);
} else {
$noMail[] = \OCP\User::getDisplayName($recipient);
}
} }
// send mail to all recipients with an email address // send mail to all recipients with an email address
foreach ($recipientList as $recipient) { foreach ($recipientList as $recipient) {
//get correct target folder name //get correct target folder name
$email = OC_Preferences::getValue($recipient, 'settings', 'email', '');
$users = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient['uid']); if ($email !== '') {
$targetName = $users[0]['file_target']; $displayName = \OCP\User::getDisplayName($recipient);
$items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient);
$filename = $items[0]['file_target'];
//$share = $shareManager->getShares($itemType, array('shareWith' => $recipient['uid'], 'isShareWithUser' => true, 'itemSource' => $itemSource)); if ($itemType === 'folder') {
//$targetName = $share[0]->getItemTarget(); $foldername = "/Shared/" . $filename;
if ($itemType === 'folder') { } else {
$foldername = "/Shared/" . $targetName; // if it is a file we can just link to the Shared folder,
$filename = $targetName; // that's the place where the user will find the file
$foldername = "/Shared";
}
$url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername));
$text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url);
try {
OCP\Util::sendMail(
$email,
$displayName,
$subject,
$text,
$from,
\OCP\User::getDisplayName()
);
} catch (Exception $exception) {
$noMail[] = \OCP\User::getDisplayName($recipient['displayName']);
}
} else { } else {
// if it is a file we can just link to the Shared folder, $noMail[] = \OCP\User::getDisplayName($recipient);
// that's the place where the user will find the file
$foldername = "/Shared";
$filename = $targetName;
}
$url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername));
$text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url);
try {
OCP\Util::sendMail(
$recipient['email'],
$recipient['displayName'],
$subject,
$text,
$from,
\OCP\User::getDisplayName()
);
} catch (Exception $exception) {
$noMail[] = \OCP\User::getDisplayName($recipient['displayName']);
} }
} }