From 77adaee6457c3e17d0f0b32c74da4cdbfce60164 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 13:53:49 +0200 Subject: [PATCH 01/25] enable user to inform recipients about a shared file by mail --- apps/files/index.php | 3 +- apps/files/templates/index.php | 1 + core/ajax/share.php | 106 +++++++++++++++++++++++++++++++-- core/css/share.css | 4 +- core/js/share.js | 39 ++++++++++-- db_structure.xml | 8 +++ lib/defaults.php | 31 +++++++++- lib/public/defaults.php | 19 ++++++ lib/public/share.php | 81 ++++++++++++++++++++++--- lib/util.php | 16 ++--- settings/admin.php | 5 +- settings/templates/admin.php | 10 +++- 12 files changed, 292 insertions(+), 31 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index e4d8e353858..7f5f9ec4741 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -131,7 +131,7 @@ if ($needUpgrade) { if ($trashEnabled) { $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user); } - + OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); OCP\Util::addscript('files', 'keyboardshortcuts'); @@ -151,5 +151,6 @@ if ($needUpgrade) { $tmpl->assign('isPublic', false); $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles()); + $tmpl->assign("mailNotificationEnabled", \OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'yes')); $tmpl->printPage(); } diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 360874103f8..e3fcecbe47a 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -120,3 +120,4 @@ + diff --git a/core/ajax/share.php b/core/ajax/share.php index d3c6a8456a6..3f6a9953266 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -23,6 +23,8 @@ OC_JSON::checkLoggedIn(); OCP\JSON::callCheck(); OC_App::loadApps(); +$defaults = new \OCP\Defaults(); + if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) { switch ($_POST['action']) { case 'share': @@ -33,7 +35,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if ($shareType === OCP\Share::SHARE_TYPE_LINK && $shareWith == '') { $shareWith = null; } - + $token = OCP\Share::shareItem( $_POST['itemType'], $_POST['itemSource'], @@ -41,7 +43,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $shareWith, $_POST['permissions'] ); - + if (is_string($token)) { OC_JSON::success(array('data' => array('token' => $token))); } else { @@ -81,6 +83,102 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo ($return) ? OC_JSON::success() : OC_JSON::error(); } break; + case 'informRecipients': + + $l = OC_L10N::get('core'); + + $shareType = (int) $_POST['shareType']; + $itemType = $_POST['itemType']; + $itemSource = $_POST['itemSource']; + $recipient = $_POST['recipient']; + $from = \OCP\Util::getDefaultEmailAddress('sharing-noreply'); + $subject = $defaults->getShareNotificationSubject($itemType); + + $noMail = array(); + $recipientList = array(); + + if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $users = \OC_Group::usersInGroup($recipient); + foreach ($users as $user) { + $email = OC_Preferences::getValue($user, 'settings', 'email', ''); + 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 + foreach ($recipientList as $recipient) { + //get correct target folder name + + $users = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient['uid']); + $targetName = $users[0]['file_target']; + + //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient['uid'], 'isShareWithUser' => true, 'itemSource' => $itemSource)); + //$targetName = $share[0]->getItemTarget(); + if ($itemType === 'folder') { + $foldername = "/Shared/" . $targetName; + $filename = $targetName; + } else { + // if it is a file we can just link to the Shared folder, + // 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']); + } + } + + \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, true); + + if (empty($noMail)) { + OCP\JSON::success(); + } else { + OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $noMail))))); + } + break; + case 'informRecipientsDisabled': + $itemSource = $_POST['itemSource']; + $itemType = $_POST['itemType']; + $recipient = $_POST['recipient']; + //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient, 'isShareWithUser' => true, 'itemSource' => $itemSource)); + //$share[0]->setMailSend(false); + //$shareManager->update($share[0]); + //write status to db + OCP\JSON::success(); + break; + case 'email': // read post variables $user = OCP\USER::getUser(); @@ -213,10 +311,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } } $count = 0; - + // enable l10n support $l = OC_L10N::get('core'); - + foreach ($groups as $group) { if ($count < 15) { if (stripos($group, $_GET['search']) !== false diff --git a/core/css/share.css b/core/css/share.css index 2d6849b4bb1..b6c5a0c1390 100644 --- a/core/css/share.css +++ b/core/css/share.css @@ -11,7 +11,7 @@ margin-right:7em; position:absolute; right:0; - width:19em; + width:25em; z-index:500; padding:1em; } @@ -24,7 +24,7 @@ #shareWithList li { padding-top:.1em; } - + #shareWithList li:first-child { white-space:normal; } diff --git a/core/js/share.js b/core/js/share.js index 27c16f38b92..c806d83f10c 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -217,9 +217,9 @@ OC.Share={ OC.Share.showLink(share.token, share.share_with, itemSource); } else { if (share.collection) { - OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.collection); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection); } else { - OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, false); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.mail_send, share.permissions, possiblePermissions, share.mail_send, false); } } if (share.expiration != null) { @@ -299,7 +299,7 @@ OC.Share={ } }); }, - addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, collection) { + addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, collection) { if (!OC.Share.itemShares[shareType]) { OC.Share.itemShares[shareType] = []; } @@ -341,6 +341,14 @@ OC.Share={ }else{ html += escapeHTML(shareWithDisplayName); } + mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); + if (mailNotificationEnabled === 'yes') { + checked = ''; + if (mailSend === true) { + checked = 'checked'; + } + html += ''+t('core', 'notify user by email')+''; + } if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) { if (editChecked == '') { html += ''; diff --git a/lib/public/share.php b/lib/public/share.php index eac6fab2b6a..c2dd0096ab9 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1030,19 +1030,19 @@ class Share { if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' - .' `share_type`, `file_source`, `path`, `expiration`, `storage`'; + .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`'; } } else { if (isset($uidOwner)) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`'; + .' `expiration`, `token`, `storage`, `storage`, `mail_send`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`'; + .' `stime`, `file_source`, `expiration`, `token`, `storage`, `mail_send`'; } } else { if ($fileDependent) { @@ -1053,11 +1053,11 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `storage`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `storage`, `mail_send`'; } } else { $select = '*'; From 36574241f821f0cbef2f52032b8187b99c5fce94 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 16:21:52 +0200 Subject: [PATCH 03/25] some clean-up --- core/ajax/share.php | 85 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 3f6a9953266..9727f7d02e3 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -97,66 +97,47 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $noMail = array(); $recipientList = array(); - if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { - $users = \OC_Group::usersInGroup($recipient); - foreach ($users as $user) { - $email = OC_Preferences::getValue($user, 'settings', 'email', ''); - 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); - } + if($shareType === \OCP\Share::SHARE_TYPE_USER) { + $recipientList[] = $recipient; + } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $recipientList = \OC_Group::usersInGroup($recipient); } // send mail to all recipients with an email address foreach ($recipientList as $recipient) { //get correct target folder name + $email = OC_Preferences::getValue($recipient, 'settings', 'email', ''); - $users = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient['uid']); - $targetName = $users[0]['file_target']; + if ($email !== '') { + $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)); - //$targetName = $share[0]->getItemTarget(); - if ($itemType === 'folder') { - $foldername = "/Shared/" . $targetName; - $filename = $targetName; + if ($itemType === 'folder') { + $foldername = "/Shared/" . $filename; + } else { + // if it is a file we can just link to the Shared folder, + // 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 { - // if it is a file we can just link to the Shared folder, - // 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']); + $noMail[] = \OCP\User::getDisplayName($recipient); } } From 65ddefc89d6730f3c32727bddae2895232c66a62 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 16:29:22 +0200 Subject: [PATCH 04/25] set sendMail status back to false --- core/ajax/share.php | 8 +++----- core/js/share.js | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 9727f7d02e3..76a67f54720 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -134,7 +134,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo \OCP\User::getDisplayName() ); } catch (Exception $exception) { - $noMail[] = \OCP\User::getDisplayName($recipient['displayName']); + $noMail[] = \OCP\User::getDisplayName($recipient); } } else { $noMail[] = \OCP\User::getDisplayName($recipient); @@ -151,12 +151,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; case 'informRecipientsDisabled': $itemSource = $_POST['itemSource']; + $shareType = $_POST['shareType']; $itemType = $_POST['itemType']; $recipient = $_POST['recipient']; - //$share = $shareManager->getShares($itemType, array('shareWith' => $recipient, 'isShareWithUser' => true, 'itemSource' => $itemSource)); - //$share[0]->setMailSend(false); - //$shareManager->update($share[0]); - //write status to db + \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, false); OCP\JSON::success(); break; diff --git a/core/js/share.js b/core/js/share.js index 7d7f580c9bb..e253f77ef27 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -695,9 +695,7 @@ $(document).ready(function() { } }); - $(document).on('click', '#dropdown input[name=mailNotification]', function(event) { - event.preventDefault(); - event.stopPropagation(); + $(document).on('click', '#dropdown input[name=mailNotification]', function() { var li = $(this).parent(); var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); From e7959f4fd23ff3354db7b876db2c3e595044bc4c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 16:52:06 +0200 Subject: [PATCH 05/25] don't send mail to the user who shared the file --- core/ajax/share.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/ajax/share.php b/core/ajax/share.php index 76a67f54720..0cf4b246f98 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -103,6 +103,9 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $recipientList = \OC_Group::usersInGroup($recipient); } + // don't send a mail to the user who shared the file + array_diff($recipientList, [\OCP\User::getUser()]); + // send mail to all recipients with an email address foreach ($recipientList as $recipient) { //get correct target folder name From 4bbefdf608fdf930fa6fd1f783d6f58267752394 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 17:20:10 +0200 Subject: [PATCH 06/25] add expiration date if it is already set --- core/ajax/share.php | 8 ++++++-- lib/defaults.php | 11 ++++++++--- lib/public/defaults.php | 5 +++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 0cf4b246f98..8b5191e6550 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -114,7 +114,11 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if ($email !== '') { $displayName = \OCP\User::getDisplayName($recipient); $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient); - $filename = $items[0]['file_target']; + $filename = trim($items[0]['file_target'], '/'); + $expiration = null; + if (isset($items[0]['expiration'])) { + $expiration = $items[0]['expiration']; + } if ($itemType === 'folder') { $foldername = "/Shared/" . $filename; @@ -125,7 +129,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); - $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url); + $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url, $expiration); try { OCP\Util::sendMail( diff --git a/lib/defaults.php b/lib/defaults.php index 26f417ae2ae..0685fbb16c0 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -65,12 +65,17 @@ class OC_Defaults { * @param string $itemName name of the file/folder * @param string $itemType typically "file" or "folder" * @param string $link link directly to the file/folder in your ownCloud + * @param string $expiration expiration date */ - public function getShareNotificationText($sender, $itemName, $itemType, $link) { + public function getShareNotificationText($sender, $itemName, $itemType, $link, $expiration=null) { if ($this->themeExist('getShareNotificationText')) { - return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link); + return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); } else { - return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link)); + if ($expiration) { + return $this->l->t("%s shared a %s called %s with you. The share will expire at %s. You can find the %s here: %s", array($sender, $itemType, $itemName, $expiration, $itemType, $link)); + } else { + return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link)); + } } } diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 9c8c3c0bdab..573831e8eae 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -48,9 +48,10 @@ class Defaults { * @param string $itemName name of the file/folder * @param string $itemType typically "file" or "folder" * @param string $link link directly to the file/folder in your ownCloud + * @param string $expiration expiration date */ - public function getShareNotificationText($sender, $itemName, $itemType, $link) { - return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link); + public function getShareNotificationText($sender, $itemName, $itemType, $link, $expiration) { + return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); } /** From 983da0d78fe13814fb771eb90dd2f10a89e0bcc6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:01:10 +0200 Subject: [PATCH 07/25] fix db queries --- lib/public/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index c2dd0096ab9..cb55c5c9756 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1053,11 +1053,11 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `storage`, `mail_send`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `storage`, `mail_send`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`'; } } else { $select = '*'; From 931e90634e905816e5ec8db3d10f9446c1b1eacc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:03:35 +0200 Subject: [PATCH 08/25] fix db queries --- lib/public/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index cb55c5c9756..4461a1d421f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1039,10 +1039,10 @@ class Share { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`, `storage`, `mail_send`'; + .' `expiration`, `token`, `storage`, `mail_send`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`, `storage`, `mail_send`'; + .' `stime`, `file_source`, `expiration`, `token`, `mail_send`'; } } else { if ($fileDependent) { From 7ce54f7b3a86c4cc1301cb6d96f3029c7047a95b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:09:26 +0200 Subject: [PATCH 09/25] revert submodule reference changes --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 21b466b72cd..dc87ea63028 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 21b466b72cdd4c823c011669593ecef1defb1f3c +Subproject commit dc87ea630287f27502eba825fbb19fcc33c34c86 From 3ce4bf5ec70ed4cfd0e6d619e2f7ae0a1bfdb06c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:14:11 +0200 Subject: [PATCH 10/25] use css class hidden to hide setting elements --- settings/templates/admin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 22cf946803e..72e93e78dac 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -128,7 +128,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -137,7 +137,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -146,7 +146,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -154,7 +154,7 @@ if (!$_['internetconnectionworking']) { - > + > />
@@ -164,7 +164,7 @@ if (!$_['internetconnectionworking']) { - > + > />
From fd7469db9e1cd1fd85e3a8a18aac87c7040ec8e7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 3 Sep 2013 13:37:06 +0200 Subject: [PATCH 11/25] coding-style fixes --- core/ajax/share.php | 16 ++++++++++++++-- core/js/share.js | 2 +- lib/defaults.php | 9 +++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 1e954ac4f9d..8f5432a0fcb 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -129,7 +129,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); - $text = $defaults->getShareNotificationText(\OCP\User::getDisplayName(), $filename, $itemType, $url, $expiration); + $text = $defaults->getShareNotificationText( + \OCP\User::getDisplayName(), + $filename, + $itemType, + $url, + $expiration + ); try { OCP\Util::sendMail( @@ -153,7 +159,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if (empty($noMail)) { OCP\JSON::success(); } else { - OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $noMail))))); + OCP\JSON::error(array( + 'data' => array( + 'message' => $l->t("Couldn't send mail to following users: %s ", + implode(', ', $noMail) + ) + ) + )); } break; case 'informRecipientsDisabled': diff --git a/core/js/share.js b/core/js/share.js index e253f77ef27..763713e7cf2 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -493,7 +493,7 @@ $(document).ready(function() { $('input:[type=checkbox]', this).hide(); $('label', this).hide(); } - } else { + } else { $('a.unshare', this).hide(); } }); diff --git a/lib/defaults.php b/lib/defaults.php index 0685fbb16c0..efb6c2c7b32 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -72,9 +72,14 @@ class OC_Defaults { return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); } else { if ($expiration) { - return $this->l->t("%s shared a %s called %s with you. The share will expire at %s. You can find the %s here: %s", array($sender, $itemType, $itemName, $expiration, $itemType, $link)); + return $this->l->t("%s shared a %s called %s with you. " . + "The share will expire at %s. ". + "You can find the %s here: %s", + array($sender, $itemType, $itemName, $expiration, $itemType, $link)); } else { - return $this->l->t("%s shared a %s called %s with you. You can find the %s here: %s", array($sender, $itemType, $itemName, $itemType, $link)); + return $this->l->t("%s shared a %s called %s with you. ". + "You can find the %s here: %s", + array($sender, $itemType, $itemName, $itemType, $link)); } } } From 74f1359b8b5f2948412375e9b3415fbc4b93791b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Sep 2013 12:50:03 +0200 Subject: [PATCH 12/25] revert broken 3rdparty reference --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index dc87ea63028..98fdc3a4e2f 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit dc87ea630287f27502eba825fbb19fcc33c34c86 +Subproject commit 98fdc3a4e2f56f7d231470418222162dbf95f46a From 6d0987bdb439e11a2027d3823c4499341180ba09 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Sep 2013 18:32:57 +0200 Subject: [PATCH 13/25] some small js fixes --- core/js/share.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index cf078d42ffc..b366665ed3f 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -344,9 +344,9 @@ OC.Share={ }else{ html += escapeHTML(shareWithDisplayName); } - mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); + var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); if (mailNotificationEnabled === 'yes') { - checked = ''; + var checked = ''; if (mailSend === '1') { checked = 'checked'; } @@ -712,14 +712,15 @@ $(document).ready(function() { var li = $(this).parent(); var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); + var action = ''; if (this.checked) { action = 'informRecipients'; } else { action = 'informRecipientsDisabled'; } - shareType = $(li).data('share-type'); - shareWith = $(li).data('share-with'); + var shareType = $(li).data('share-type'); + var shareWith = $(li).data('share-with'); $.post(OC.filePath('core', 'ajax', 'share.php'), {action: action, recipient: shareWith, shareType: shareType, itemSource: itemSource, itemType: itemType}, function(result) { if (result.status !== 'success') { From 0637dad0b39f1f90dc1c22afc2985642432e8096 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Sep 2013 18:52:20 +0200 Subject: [PATCH 14/25] some small fixes --- lib/public/share.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index 0dfbbef0a73..03ad5853e28 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -246,9 +246,9 @@ class Share { /** * @brief Get the item of item type shared with the current user - * @param string Item type - * @param string Item target - * @param int Format (optional) Format type must be defined by the backend + * @param string $itemType + * @param string $ItemTarget + * @param int $format (optional) Format type must be defined by the backend * @return Return depends on format */ public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE, @@ -279,8 +279,10 @@ class Share { $result = $query->execute(array($itemSource, $itemType, $user)); - while ($row = $result->fetchRow()) { - $shares[] = $row; + if($result) { + while ($row = $result->fetchRow()) { + $shares[] = $row; + } } //if didn't found a result than let's look for a group share. @@ -297,8 +299,10 @@ class Share { $result = $query->execute(array($itemSource, $itemType, implode(',', $groups))); - while ($row = $result->fetchRow()) { - $shares[] = $row; + if($result) { + while ($row = $result->fetchRow()) { + $shares[] = $row; + } } } @@ -706,7 +710,13 @@ class Share { SET `mail_send` = ? WHERE `item_type` = ? AND `item_source` = ? AND `share_type` = ?'); - $query->execute(array($status, $itemType, $itemSource, $shareType)); + $result = $query->execute(array($status, $itemType, $itemSource, $shareType)); + + if($result === false) { + \OC_Log::write('OCP\Share', 'Couldn\'t set send mail status', \OC_Log::ERROR); + } + + } /** From ca47fc5f18178c88f8a4eff3de35f02b580bc6b1 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Sep 2013 19:37:24 +0200 Subject: [PATCH 15/25] fix PHPDoc --- lib/public/share.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index 03ad5853e28..bdfaed2d5cd 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -259,10 +259,10 @@ class Share { /** * @brief Get the item of item type shared with a given user by source - * @param string Item type - * @param string Item source - * @param string User user to whom the item was shared - * @return Return list of items with file_target, permissions and expiration + * @param string $ItemType + * @param string $ItemSource + * @param string $user User user to whom the item was shared + * @return array Return list of items with file_target, permissions and expiration */ public static function getItemSharedWithUser($itemType, $itemSource, $user) { From 883d1c0df32a942d3bb07f242e8ffcd871418f60 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 11:51:28 +0200 Subject: [PATCH 16/25] use template for txt and html mails to send notification mails --- core/ajax/share.php | 41 ++++++++++-------- core/templates/altmail.php | 6 +-- core/templates/mail.php | 8 ++-- lib/defaults.php | 88 ++++++++++++++++++++++++++++++-------- lib/public/defaults.php | 41 ++++++++++++++---- 5 files changed, 133 insertions(+), 51 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 8f5432a0fcb..293e140d1d5 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -91,8 +91,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $itemType = $_POST['itemType']; $itemSource = $_POST['itemSource']; $recipient = $_POST['recipient']; + $ownerDisplayName = \OCP\User::getDisplayName(); $from = \OCP\Util::getDefaultEmailAddress('sharing-noreply'); - $subject = $defaults->getShareNotificationSubject($itemType); $noMail = array(); $recipientList = array(); @@ -115,6 +115,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $displayName = \OCP\User::getDisplayName($recipient); $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient); $filename = trim($items[0]['file_target'], '/'); + $subject = $defaults->getShareNotificationSubject($ownerDisplayName, $filename); $expiration = null; if (isset($items[0]['expiration'])) { $expiration = $items[0]['expiration']; @@ -128,29 +129,31 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $foldername = "/Shared"; } - $url = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); - $text = $defaults->getShareNotificationText( - \OCP\User::getDisplayName(), - $filename, - $itemType, - $url, - $expiration - ); + $link = \OCP\Util::linkToAbsolute('files', 'index.php', array("dir" => $foldername)); + $content = new OC_Template("core", "mail", ""); + $content->assign('link', $link); + $content->assign('user_displayname', $ownerDisplayName); + $content->assign('filename', $filename); + $content->assign('expiration', $expiration); + $text = $content->fetchPage(); + + $content = new OC_Template("core", "altmail", ""); + $content->assign('link', $link); + $content->assign('user_displayname', $ownerDisplayName); + $content->assign('filename', $filename); + $content->assign('expiration', $expiration); + $alttext = $content->fetchPage(); + + $default_from = OCP\Util::getDefaultEmailAddress('sharing-noreply'); + $from = OCP\Config::getUserValue(\OCP\User::getUser(), 'settings', 'email', $default_from); + + // send it out now try { - OCP\Util::sendMail( - $email, - $displayName, - $subject, - $text, - $from, - \OCP\User::getDisplayName() - ); + OCP\Util::sendMail($email, $displayName, $subject, $text, $from, $ownerDisplayName, 1, $alttext); } catch (Exception $exception) { $noMail[] = \OCP\User::getDisplayName($recipient); } - } else { - $noMail[] = \OCP\User::getDisplayName($recipient); } } diff --git a/core/templates/altmail.php b/core/templates/altmail.php index 2551473c6f0..f7159a021a8 100644 --- a/core/templates/altmail.php +++ b/core/templates/altmail.php @@ -1,7 +1,7 @@ t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\nCheers!", array($_['user_displayname'], $_['filename'], $_['link']))); +$expiration = isset($_['expiration']) ? $_['expiration'] : null; +print_unescaped($theme->getShareNotificationTextAlt($_['user_displayname'], $_['filename'], $_['link'], $expiration)); ?> -- -getName() . ' - ' . $theme->getSlogan()); ?> -getBaseUrl()); +getMailFooterAlt()); diff --git a/core/templates/mail.php b/core/templates/mail.php index de72b136b13..5570e4caabe 100644 --- a/core/templates/mail.php +++ b/core/templates/mail.php @@ -12,7 +12,8 @@   t('Hey there,

just letting you know that %s shared »%s« with you.
View it!

Cheers!', array($_['user_displayname'], $_['filename'], $_['link']))); +$expiration = isset($_['expiration']) ? $_['expiration'] : null; +print_unescaped($theme->getShareNotificationTextHtml($_['user_displayname'], $_['filename'], $_['link'], $expiration)); ?> @@ -20,9 +21,8 @@ print_unescaped($l->t('Hey there,

just letting you know that %s shared »   --
-getName()); ?> - -getSlogan()); ?> -
getBaseUrl());?> +getMailFooterHtml()); ?> +   diff --git a/lib/defaults.php b/lib/defaults.php index efb6c2c7b32..eb531d1e052 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -49,38 +49,92 @@ class OC_Defaults { } /** - * - * @param string $itemType typically "file" or "folder" + * @brief subject for share notification mail + * @param string $user user who shared the item + * @pram string $itemName name of the item */ - public function getShareNotificationSubject($itemType) { + public function getShareNotificationSubject($user, $itemName) { if ($this->themeExist('getShareNotificationSubject')) { - return $this->theme->getShareNotificationSubject($itemType); + return $this->theme->getShareNotificationSubject($user, $itemName); } else { - return $this->l->t("A %s was shared with you", array($itemType)); + return $this->l->t("%s shared »%s« with you", array($user, $itemName)); } } /** + * @brief mail body for share notification mail (text only) * @param string $sender owner of the file/folder * @param string $itemName name of the file/folder - * @param string $itemType typically "file" or "folder" * @param string $link link directly to the file/folder in your ownCloud * @param string $expiration expiration date */ - public function getShareNotificationText($sender, $itemName, $itemType, $link, $expiration=null) { - if ($this->themeExist('getShareNotificationText')) { - return $this->theme->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); + public function getShareNotificationTextHtml($sender, $itemName, $link, $expiration=null) { + if ($this->themeExist('getShareNotificationTextHtml')) { + return $this->theme->getShareNotificationTextHtml($sender, $itemName, $link, $expiration); } else { + + $message = $this->l->t('Hey there,

just letting you know that %s shared »%s« with you.'. + '
View it!', array($sender, $itemName, $link)); + if ($expiration) { - return $this->l->t("%s shared a %s called %s with you. " . - "The share will expire at %s. ". - "You can find the %s here: %s", - array($sender, $itemType, $itemName, $expiration, $itemType, $link)); - } else { - return $this->l->t("%s shared a %s called %s with you. ". - "You can find the %s here: %s", - array($sender, $itemType, $itemName, $itemType, $link)); + $message .= '

'; + $message .= $this->l->t("The share will expire at %s.", array($expiration)); } + + $message .= '

'; + $message .= $this->l->t('Cheers!'); + + return $message; + } + } + + /** + * @brief mail body for share notification mail (text only) + * @param string $sender owner of the file/folder + * @param string $itemName name of the file/folder + * @param string $link link directly to the file/folder in your ownCloud + * @param string $expiration expiration date + */ + public function getShareNotificationTextAlt($sender, $itemName, $link, $expiration=null) { + if ($this->themeExist('getShareNotificationTextAlt')) { + return $this->theme->getShareNotificationTextAlt($sender, $itemName, $link, $expiration); + } else { + + $message = $this->l->t("Hey there,\n\njust letting you know that %s shared %s with you.\n". + "View it: %s", array($sender, $itemName, $link)); + + if ($expiration) { + $message .= "\n\n"; + $message .= $this->l->t("The share will expire at %s.", array($expiration)); + } + + $message .= "\n\n"; + $message .= $this->l->t('Cheers!'); + + return $message; + } + } + + public function getMailFooterHtml() { + if ($this->themeExist('getMailFooterHtml')) { + return $this->theme->getMailFooterHtml(); + } else { + $footer = $this->getName() . ' - ' . $this->getSlogan() . + '
' . + ''.$this->getBaseUrl().''; + + return $footer; + } + } + + public function getMailFooterAlt() { + if ($this->themeExist('getMailFooterAlt')) { + return $this->theme->getMailFooterAlt(); + } else { + $footer = $this->getName() . ' - ' . $this->getSlogan() . + "\n" . $this->getBaseUrl(); + + return $footer; } } diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 573831e8eae..10bd07bab54 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -35,23 +35,48 @@ class Defaults { } /** - * @brief subject for notification mails if a new file was shared - * @param string $itemType typically "file" or "folder" + * @brief subject for share notification mail + * @param string $user user who shared the item + * @pram string $itemName name of the item */ - public function getShareNotificationSubject($itemType = "file") { - return $this->defaults->getShareNotificationSubject($itemType); + public function getShareNotificationSubject($user, $itemName) { + return $this->defaults->getShareNotificationSubject($user, $itemName); } /** - * @brief mail body for notification mails if a new file was shared + * @brief mail body for share notification mail (text only) * @param string $sender owner of the file/folder * @param string $itemName name of the file/folder - * @param string $itemType typically "file" or "folder" * @param string $link link directly to the file/folder in your ownCloud * @param string $expiration expiration date */ - public function getShareNotificationText($sender, $itemName, $itemType, $link, $expiration) { - return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link, $expiration); + public function getShareNotificationTextAlt($sender, $itemName, $link, $expiration) { + return $this->defaults->getShareNotificationTextAlt($sender, $itemName, $link, $expiration); + } + + /** + * @brief mail body for share notification mail (HTML mail) + * @param string $sender owner of the file/folder + * @param string $itemName name of the file/folder + * @param string $link link directly to the file/folder in your ownCloud + * @param string $expiration expiration date + */ + public function getShareNotificationTextHtml($sender, $itemName, $link, $expiration) { + return $this->defaults->getShareNotificationTextHtml($sender, $itemName, $link, $expiration); + } + + /** + * @brief return footer for mails (HTML mail) + */ + public function getMailFooterHtml() { + return $this->defaults->getMailFooterHtml(); + } + + /** + * @brief return footer for mails (text only) + */ + public function getMailFooterAlt() { + return $this->defaults->getMailFooterAlt(); } /** From 3cd0caa6435992c270adc3d2387b03f0aebfe98c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 12:15:30 +0200 Subject: [PATCH 17/25] set default value for expire parameter --- lib/public/defaults.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 10bd07bab54..a508c504c94 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -50,7 +50,7 @@ class Defaults { * @param string $link link directly to the file/folder in your ownCloud * @param string $expiration expiration date */ - public function getShareNotificationTextAlt($sender, $itemName, $link, $expiration) { + public function getShareNotificationTextAlt($sender, $itemName, $link, $expiration=null) { return $this->defaults->getShareNotificationTextAlt($sender, $itemName, $link, $expiration); } @@ -61,7 +61,7 @@ class Defaults { * @param string $link link directly to the file/folder in your ownCloud * @param string $expiration expiration date */ - public function getShareNotificationTextHtml($sender, $itemName, $link, $expiration) { + public function getShareNotificationTextHtml($sender, $itemName, $link, $expiration=null) { return $this->defaults->getShareNotificationTextHtml($sender, $itemName, $link, $expiration); } From 5a9e473a7964a068599de59cbbd7fe1dae6493ef Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 12:15:46 +0200 Subject: [PATCH 18/25] use OC_DB::executeAudited --- lib/public/share.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index bdfaed2d5cd..c0f339744cc 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -277,12 +277,10 @@ class Share { `item_source` = ? AND `item_type` = ? AND `share_with` = ?' ); - $result = $query->execute(array($itemSource, $itemType, $user)); + $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, $user)); - if($result) { - while ($row = $result->fetchRow()) { - $shares[] = $row; - } + while ($row = $result->fetchRow()) { + $shares[] = $row; } //if didn't found a result than let's look for a group share. From acd3c11e47212e3b9d59a914cea408637582bb06 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 12:18:29 +0200 Subject: [PATCH 19/25] use OC_DB::executeAudited --- lib/public/share.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index c0f339744cc..be61d046f0b 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -295,12 +295,10 @@ class Share { `item_source` = ? AND `item_type` = ? AND `share_with` in (?)' ); - $result = $query->execute(array($itemSource, $itemType, implode(',', $groups))); + $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups))); - if($result) { - while ($row = $result->fetchRow()) { - $shares[] = $row; - } + while ($row = $result->fetchRow()) { + $shares[] = $row; } } From b9a1f6334482ae181609e262c11c378e1d0f6109 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 30 Sep 2013 10:02:26 +0200 Subject: [PATCH 20/25] go back to old template but add expire date as optional content --- core/templates/altmail.php | 10 +++++++--- core/templates/mail.php | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core/templates/altmail.php b/core/templates/altmail.php index f7159a021a8..5df43b50776 100644 --- a/core/templates/altmail.php +++ b/core/templates/altmail.php @@ -1,7 +1,11 @@ getShareNotificationTextAlt($_['user_displayname'], $_['filename'], $_['link'], $expiration)); +print_unescaped($l->t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\n", array($_['user_displayname'], $_['filename'], $_['link']))); +if ( isset($_['expiration']) ) { + print_unescaped($l->t("The share will expire at %s.\n\n", array($_['expiration']))); +} +p($l->t("Cheers!")); ?> -- -getMailFooterAlt()); +getName() . ' - ' . $theme->getSlogan()); ?> +getBaseUrl()); diff --git a/core/templates/mail.php b/core/templates/mail.php index 5570e4caabe..1464d2be2f4 100644 --- a/core/templates/mail.php +++ b/core/templates/mail.php @@ -12,8 +12,11 @@   getShareNotificationTextHtml($_['user_displayname'], $_['filename'], $_['link'], $expiration)); +print_unescaped($l->t('Hey there,

just letting you know that %s shared »%s« with you.
View it!

', array($_['user_displayname'], $_['filename'], $_['link']))); +if ( isset($_['expiration']) ) { + print_unescaped($l->t("The share will expire at %s.

", array($_['expiration']))); +} +p($l->t('Cheers!')); ?> @@ -21,7 +24,9 @@ print_unescaped($theme->getShareNotificationTextHtml($_['user_displayname'], $_[   --
-getMailFooterHtml()); ?> +getName()); ?> - +getSlogan()); ?> +
getBaseUrl());?> From 029abc9c43d1d396d8cd4301542c89e1023fa553 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 30 Sep 2013 10:03:12 +0200 Subject: [PATCH 21/25] mail is already themable via the template, no need to provide additional string in OC_Defaults --- lib/defaults.php | 90 ----------------------------------------- lib/public/defaults.php | 45 --------------------- 2 files changed, 135 deletions(-) diff --git a/lib/defaults.php b/lib/defaults.php index eb531d1e052..4951c6f50ae 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -48,96 +48,6 @@ class OC_Defaults { return false; } - /** - * @brief subject for share notification mail - * @param string $user user who shared the item - * @pram string $itemName name of the item - */ - public function getShareNotificationSubject($user, $itemName) { - if ($this->themeExist('getShareNotificationSubject')) { - return $this->theme->getShareNotificationSubject($user, $itemName); - } else { - return $this->l->t("%s shared »%s« with you", array($user, $itemName)); - } - } - - /** - * @brief mail body for share notification mail (text only) - * @param string $sender owner of the file/folder - * @param string $itemName name of the file/folder - * @param string $link link directly to the file/folder in your ownCloud - * @param string $expiration expiration date - */ - public function getShareNotificationTextHtml($sender, $itemName, $link, $expiration=null) { - if ($this->themeExist('getShareNotificationTextHtml')) { - return $this->theme->getShareNotificationTextHtml($sender, $itemName, $link, $expiration); - } else { - - $message = $this->l->t('Hey there,

just letting you know that %s shared »%s« with you.'. - '
View it!', array($sender, $itemName, $link)); - - if ($expiration) { - $message .= '

'; - $message .= $this->l->t("The share will expire at %s.", array($expiration)); - } - - $message .= '

'; - $message .= $this->l->t('Cheers!'); - - return $message; - } - } - - /** - * @brief mail body for share notification mail (text only) - * @param string $sender owner of the file/folder - * @param string $itemName name of the file/folder - * @param string $link link directly to the file/folder in your ownCloud - * @param string $expiration expiration date - */ - public function getShareNotificationTextAlt($sender, $itemName, $link, $expiration=null) { - if ($this->themeExist('getShareNotificationTextAlt')) { - return $this->theme->getShareNotificationTextAlt($sender, $itemName, $link, $expiration); - } else { - - $message = $this->l->t("Hey there,\n\njust letting you know that %s shared %s with you.\n". - "View it: %s", array($sender, $itemName, $link)); - - if ($expiration) { - $message .= "\n\n"; - $message .= $this->l->t("The share will expire at %s.", array($expiration)); - } - - $message .= "\n\n"; - $message .= $this->l->t('Cheers!'); - - return $message; - } - } - - public function getMailFooterHtml() { - if ($this->themeExist('getMailFooterHtml')) { - return $this->theme->getMailFooterHtml(); - } else { - $footer = $this->getName() . ' - ' . $this->getSlogan() . - '
' . - ''.$this->getBaseUrl().''; - - return $footer; - } - } - - public function getMailFooterAlt() { - if ($this->themeExist('getMailFooterAlt')) { - return $this->theme->getMailFooterAlt(); - } else { - $footer = $this->getName() . ' - ' . $this->getSlogan() . - "\n" . $this->getBaseUrl(); - - return $footer; - } - } - public function getBaseUrl() { if ($this->themeExist('getBaseUrl')) { return $this->theme->getBaseUrl(); diff --git a/lib/public/defaults.php b/lib/public/defaults.php index a508c504c94..147f23e341f 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -34,51 +34,6 @@ class Defaults { $this->defaults = new \OC_Defaults(); } - /** - * @brief subject for share notification mail - * @param string $user user who shared the item - * @pram string $itemName name of the item - */ - public function getShareNotificationSubject($user, $itemName) { - return $this->defaults->getShareNotificationSubject($user, $itemName); - } - - /** - * @brief mail body for share notification mail (text only) - * @param string $sender owner of the file/folder - * @param string $itemName name of the file/folder - * @param string $link link directly to the file/folder in your ownCloud - * @param string $expiration expiration date - */ - public function getShareNotificationTextAlt($sender, $itemName, $link, $expiration=null) { - return $this->defaults->getShareNotificationTextAlt($sender, $itemName, $link, $expiration); - } - - /** - * @brief mail body for share notification mail (HTML mail) - * @param string $sender owner of the file/folder - * @param string $itemName name of the file/folder - * @param string $link link directly to the file/folder in your ownCloud - * @param string $expiration expiration date - */ - public function getShareNotificationTextHtml($sender, $itemName, $link, $expiration=null) { - return $this->defaults->getShareNotificationTextHtml($sender, $itemName, $link, $expiration); - } - - /** - * @brief return footer for mails (HTML mail) - */ - public function getMailFooterHtml() { - return $this->defaults->getMailFooterHtml(); - } - - /** - * @brief return footer for mails (text only) - */ - public function getMailFooterAlt() { - return $this->defaults->getMailFooterAlt(); - } - /** * @breif get base URL for the organisation behind your ownCloud instance * @return string From 17aa49a890195f8482e527f2b8c102238d94bc7c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 30 Sep 2013 13:33:02 +0200 Subject: [PATCH 22/25] fix mail subject; don't show time for expire date --- core/ajax/share.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 293e140d1d5..9b282b2b94a 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -115,10 +115,11 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $displayName = \OCP\User::getDisplayName($recipient); $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient); $filename = trim($items[0]['file_target'], '/'); - $subject = $defaults->getShareNotificationSubject($ownerDisplayName, $filename); + $subject = (string)$l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); $expiration = null; if (isset($items[0]['expiration'])) { - $expiration = $items[0]['expiration']; + $date = new DateTime($items[0]['expiration']); + $expiration = $date->format('Y-m-d'); } if ($itemType === 'folder') { From 084f76fd14125023d5b7277c558eb86a20ea07d3 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 30 Sep 2013 13:33:49 +0200 Subject: [PATCH 23/25] grammar fixes --- core/templates/altmail.php | 2 +- core/templates/mail.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/templates/altmail.php b/core/templates/altmail.php index 5df43b50776..00b67bee456 100644 --- a/core/templates/altmail.php +++ b/core/templates/altmail.php @@ -1,7 +1,7 @@ t("Hey there,\n\njust letting you know that %s shared %s with you.\nView it: %s\n\n", array($_['user_displayname'], $_['filename'], $_['link']))); if ( isset($_['expiration']) ) { - print_unescaped($l->t("The share will expire at %s.\n\n", array($_['expiration']))); + print_unescaped($l->t("The share will expire on %s.\n\n", array($_['expiration']))); } p($l->t("Cheers!")); ?> diff --git a/core/templates/mail.php b/core/templates/mail.php index 1464d2be2f4..40092f5491f 100644 --- a/core/templates/mail.php +++ b/core/templates/mail.php @@ -14,7 +14,7 @@ t('Hey there,

just letting you know that %s shared »%s« with you.
View it!

', array($_['user_displayname'], $_['filename'], $_['link']))); if ( isset($_['expiration']) ) { - print_unescaped($l->t("The share will expire at %s.

", array($_['expiration']))); + print_unescaped($l->t("The share will expire on %s.

", array($_['expiration']))); } p($l->t('Cheers!')); ?> From d09b1553d0356adb894854884c672e3696a74f4e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 3 Oct 2013 11:30:55 +0200 Subject: [PATCH 24/25] Fixed syntax error in array --- core/ajax/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 9b282b2b94a..f55a79a9034 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -104,7 +104,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } // don't send a mail to the user who shared the file - array_diff($recipientList, [\OCP\User::getUser()]); + array_diff($recipientList, array(\OCP\User::getUser())); // send mail to all recipients with an email address foreach ($recipientList as $recipient) { From 304803d102fed4f9a7acf404f76fcf49d82f5a43 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 4 Oct 2013 12:23:40 +0200 Subject: [PATCH 25/25] fix array_diff call --- core/ajax/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 9b282b2b94a..ed9cbfd109a 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -104,7 +104,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } // don't send a mail to the user who shared the file - array_diff($recipientList, [\OCP\User::getUser()]); + $recipientList = array_diff($recipientList, [\OCP\User::getUser()]); // send mail to all recipients with an email address foreach ($recipientList as $recipient) {