From 77adaee6457c3e17d0f0b32c74da4cdbfce60164 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 13:53:49 +0200 Subject: enable user to inform recipients about a shared file by mail --- lib/defaults.php | 31 +++++++++++++++++-- lib/public/defaults.php | 19 ++++++++++++ lib/public/share.php | 81 ++++++++++++++++++++++++++++++++++++++++++++----- lib/util.php | 16 +++++----- 4 files changed, 130 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/defaults.php b/lib/defaults.php index 10813a3e8d8..26f417ae2ae 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -13,6 +13,7 @@ if (file_exists(OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults. class OC_Defaults { private $theme; + private $l; private $defaultEntity; private $defaultName; @@ -24,7 +25,7 @@ class OC_Defaults { private $defaultLogoClaim; function __construct() { - $l = OC_L10N::get('core'); + $this->l = OC_L10N::get('core'); $this->defaultEntity = "ownCloud"; /* e.g. company name, used for footers and copyright notices */ $this->defaultName = "ownCloud"; /* short name, used when referring to the software */ @@ -32,7 +33,7 @@ class OC_Defaults { $this->defaultBaseUrl = "http://owncloud.org"; $this->defaultSyncClientUrl = " http://owncloud.org/sync-clients/"; $this->defaultDocBaseUrl = "http://doc.owncloud.org"; - $this->defaultSlogan = $l->t("web services under your control"); + $this->defaultSlogan = $this->l->t("web services under your control"); $this->defaultLogoClaim = ""; if (class_exists("OC_Theme")) { @@ -47,6 +48,32 @@ class OC_Defaults { return false; } + /** + * + * @param string $itemType typically "file" or "folder" + */ + public function getShareNotificationSubject($itemType) { + if ($this->themeExist('getShareNotificationSubject')) { + return $this->theme->getShareNotificationSubject($itemType); + } else { + return $this->l->t("A %s was shared with you", array($itemType)); + } + } + + /** + * @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 + */ + public function getShareNotificationText($sender, $itemName, $itemType, $link) { + if ($this->themeExist('getShareNotificationText')) { + return $this->theme->getShareNotificationText($sender, $itemName, $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)); + } + } + public function getBaseUrl() { if ($this->themeExist('getBaseUrl')) { return $this->theme->getBaseUrl(); diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 147f23e341f..9c8c3c0bdab 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -34,6 +34,25 @@ class Defaults { $this->defaults = new \OC_Defaults(); } + /** + * @brief subject for notification mails if a new file was shared + * @param string $itemType typically "file" or "folder" + */ + public function getShareNotificationSubject($itemType = "file") { + return $this->defaults->getShareNotificationSubject($itemType); + } + + /** + * @brief mail body for notification mails if a new file was shared + * @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 + */ + public function getShareNotificationText($sender, $itemName, $itemType, $link) { + return $this->defaults->getShareNotificationText($sender, $itemName, $itemType, $link); + } + /** * @breif get base URL for the organisation behind your ownCloud instance * @return string diff --git a/lib/public/share.php b/lib/public/share.php index b38208bc67f..eac6fab2b6a 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -106,22 +106,22 @@ class Share { } return false; } - + /** * @brief Prepare a path to be passed to DB as file_target * @return string Prepared path */ public static function prepFileTarget( $path ) { - + // Paths in DB are stored with leading slashes, so add one if necessary if ( substr( $path, 0, 1 ) !== '/' ) { - + $path = '/' . $path; - + } - + return $path; - + } /** @@ -251,7 +251,57 @@ class Share { return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, 1, $includeCollections); } - + + /** + * @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 + */ + public static function getItemSharedWithUser($itemType, $itemSource, $user) { + + $shares = array(); + + // first check if there is a db entry for the specific user + $query = \OC_DB::prepare( + 'SELECT `file_target`, `permissions`, `expiration` + FROM + `*PREFIX*share` + WHERE + `item_source` = ? AND `item_type` = ? AND `share_with` = ?' + ); + + $result = $query->execute(array($itemSource, $itemType, $user)); + + while ($row = $result->fetchRow()) { + $shares[] = $row; + } + + //if didn't found a result than let's look for a group share. + if(empty($shares)) { + $groups = \OC_Group::getUserGroups($user); + + $query = \OC_DB::prepare( + 'SELECT `file_target`, `permissions`, `expiration` + FROM + `*PREFIX*share` + WHERE + `item_source` = ? AND `item_type` = ? AND `share_with` in (?)' + ); + + $result = $query->execute(array($itemSource, $itemType, implode(',', $groups))); + + while ($row = $result->fetchRow()) { + $shares[] = $row; + } + } + + return $shares; + + } + + /** * @brief Get the item of item type shared with the current user by source * @param string Item type @@ -633,6 +683,23 @@ class Share { } return false; } + /** + * @brief sent status if users got informed by mail about share + * @param string $itemType + * @param string $itemSource + * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK + * @param bool $status + */ + public static function setSendMailStatus($itemType, $itemSource, $shareType, $status) { + $status = $status ? 1 : 0; + + $query = \OC_DB::prepare( + 'UPDATE `*PREFIX*share` + SET `mail_send` = ? + WHERE `item_type` = ? AND `item_source` = ? AND `share_type` = ?'); + + $query->execute(array($status, $itemType, $itemSource, $shareType)); + } /** * @brief Set the permissions of an item for a specific user or group diff --git a/lib/util.php b/lib/util.php index e03667b0794..ef77ba8a916 100755 --- a/lib/util.php +++ b/lib/util.php @@ -98,7 +98,7 @@ class OC_Util { public static function getVersion() { // hint: We only can count up. Reset minor/patchlevel when // updating major/minor version number. - return array(5, 80, 05); + return array(5, 80, 06); } /** @@ -352,10 +352,10 @@ class OC_Util { $encryptedFiles = true; } } - + return $encryptedFiles; } - + /** * Check for correct file permissions of data directory * @return array arrays with error messages and hints @@ -581,16 +581,16 @@ class OC_Util { } return $value; } - + /** * @brief Public function to encode url parameters * * This function is used to encode path to file before output. * Encoding is done according to RFC 3986 with one exception: - * Character '/' is preserved as is. + * Character '/' is preserved as is. * * @param string $component part of URI to encode - * @return string + * @return string */ public static function encodePath($component) { $encoded = rawurlencode($component); @@ -734,7 +734,7 @@ class OC_Util { } } - + /** * Check if the connection to the internet is disabled on purpose */ @@ -887,7 +887,7 @@ class OC_Util { $theme = OC_Config::getValue("theme", ''); if($theme === '') { - + if(is_dir(OC::$SERVERROOT . '/themes/default')) { $theme = 'default'; } -- cgit v1.2.3 From 10cf1b3a4e03dfa908d9dfc7cae85e9bd418e5bf Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 15:39:43 +0200 Subject: return mailSend status in getItems() --- core/js/share.js | 5 +++-- lib/public/share.php | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/core/js/share.js b/core/js/share.js index c806d83f10c..7d7f580c9bb 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -114,6 +114,7 @@ OC.Share={ data = false; } }}); + return data; }, share:function(itemType, itemSource, shareType, shareWith, permissions, callback) { @@ -219,7 +220,7 @@ OC.Share={ if (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.mail_send, share.permissions, possiblePermissions, share.mail_send, false); + OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, false); } } if (share.expiration != null) { @@ -344,7 +345,7 @@ OC.Share={ mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); if (mailNotificationEnabled === 'yes') { checked = ''; - if (mailSend === true) { + if (mailSend === '1') { checked = 'checked'; } html += ''+t('core', 'notify user by email')+''; 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 = '*'; -- cgit v1.2.3 From 4bbefdf608fdf930fa6fd1f783d6f58267752394 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 30 Aug 2013 17:20:10 +0200 Subject: 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(-) (limited to 'lib') 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); } /** -- cgit v1.2.3 From 983da0d78fe13814fb771eb90dd2f10a89e0bcc6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:01:10 +0200 Subject: fix db queries --- lib/public/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') 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 = '*'; -- cgit v1.2.3 From 931e90634e905816e5ec8db3d10f9446c1b1eacc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Sep 2013 17:03:35 +0200 Subject: fix db queries --- lib/public/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') 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) { -- cgit v1.2.3 From fd7469db9e1cd1fd85e3a8a18aac87c7040ec8e7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 3 Sep 2013 13:37:06 +0200 Subject: coding-style fixes --- core/ajax/share.php | 16 ++++++++++++++-- core/js/share.js | 2 +- lib/defaults.php | 9 +++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) (limited to 'lib') 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)); } } } -- cgit v1.2.3 From 0637dad0b39f1f90dc1c22afc2985642432e8096 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Sep 2013 18:52:20 +0200 Subject: some small fixes --- lib/public/share.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib') 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); + } + + } /** -- cgit v1.2.3 From ca47fc5f18178c88f8a4eff3de35f02b580bc6b1 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Sep 2013 19:37:24 +0200 Subject: fix PHPDoc --- lib/public/share.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') 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) { -- cgit v1.2.3 From 883d1c0df32a942d3bb07f242e8ffcd871418f60 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 11:51:28 +0200 Subject: 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(-) (limited to 'lib') 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) { + $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) { - 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 .= "\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(); } /** -- cgit v1.2.3 From 3cd0caa6435992c270adc3d2387b03f0aebfe98c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 12:15:30 +0200 Subject: set default value for expire parameter --- lib/public/defaults.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') 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); } -- cgit v1.2.3 From 5a9e473a7964a068599de59cbbd7fe1dae6493ef Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 12:15:46 +0200 Subject: use OC_DB::executeAudited --- lib/public/share.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib') 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. -- cgit v1.2.3 From acd3c11e47212e3b9d59a914cea408637582bb06 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 25 Sep 2013 12:18:29 +0200 Subject: use OC_DB::executeAudited --- lib/public/share.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib') 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; } } -- cgit v1.2.3 From 029abc9c43d1d396d8cd4301542c89e1023fa553 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 30 Sep 2013 10:03:12 +0200 Subject: 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(-) (limited to 'lib') 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 -- cgit v1.2.3