mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
use template for txt and html mails to send notification mails
This commit is contained in:
parent
ca47fc5f18
commit
883d1c0df3
5 changed files with 133 additions and 51 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
print_unescaped($l->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));
|
||||
?>
|
||||
|
||||
--
|
||||
<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
|
||||
<?php print_unescaped("\n".$theme->getBaseUrl());
|
||||
<?php print_unescaped($theme->getMailFooterAlt());
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
<td bgcolor="#f8f8f8" width="20px"> </td>
|
||||
<td bgcolor="#f8f8f8" style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
|
||||
<?php
|
||||
print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared »%s« with you.<br><a href="%s">View it!</a><br><br>Cheers!', array($_['user_displayname'], $_['filename'], $_['link'])));
|
||||
$expiration = isset($_['expiration']) ? $_['expiration'] : null;
|
||||
print_unescaped($theme->getShareNotificationTextHtml($_['user_displayname'], $_['filename'], $_['link'], $expiration));
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -20,9 +21,8 @@ print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared »
|
|||
<tr>
|
||||
<td bgcolor="#f8f8f8" width="20px"> </td>
|
||||
<td bgcolor="#f8f8f8" style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
|
||||
<?php p($theme->getName()); ?> -
|
||||
<?php p($theme->getSlogan()); ?>
|
||||
<br><a href="<?php print_unescaped($theme->getBaseUrl()); ?>"><?php print_unescaped($theme->getBaseUrl());?></a></td>
|
||||
<?php print_unescaped($theme->getMailFooterHtml()); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#f8f8f8" colspan="2"> </td>
|
||||
|
|
|
|||
|
|
@ -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,<br><br>just letting you know that %s shared »%s« with you.'.
|
||||
'<br><a href="%s">View it!</a>', 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 .= '<br><br>';
|
||||
$message .= $this->l->t("The share will expire at %s.", array($expiration));
|
||||
}
|
||||
|
||||
$message .= '<br><br>';
|
||||
$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() .
|
||||
'<br>' .
|
||||
'<a href="'. $this->getBaseUrl() .'">'.$this->getBaseUrl().'</a>';
|
||||
|
||||
return $footer;
|
||||
}
|
||||
}
|
||||
|
||||
public function getMailFooterAlt() {
|
||||
if ($this->themeExist('getMailFooterAlt')) {
|
||||
return $this->theme->getMailFooterAlt();
|
||||
} else {
|
||||
$footer = $this->getName() . ' - ' . $this->getSlogan() .
|
||||
"\n" . $this->getBaseUrl();
|
||||
|
||||
return $footer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue