[Owncloud] files_sharing - sharing emails as templates
Michael Gapczynski
mtgap at owncloud.com
Tue Aug 14 16:56:13 UTC 2012
Hi Martin,
This could be a nice feature for admins to configure. The template could be
overridden by a custom theme. That ajax email file will be removed when the
share_api branch is merged into master. You can wait after that to put in a
merge request with the template.
Michael
On Tuesday, August 14, 2012 05:39:08 PM Martin Werthmöller wrote:
> Hi list,
>
> the email content sent by the files_sharing app is hardcoded at
> "apps/files_sharing/email.php". I suggest, it should be possible to
> add the ability to create a template for the sharing email.
>
> I've hacked a little proof of concept (see below). Here, the
> template will be included directly from the template/ directory.
> Changes at the template will be overwritten.
>
> Where should I put the template and how can I access this?
>
> Are there any method calls / variables in OC-Classes that addresses
> directories for custom extensions?
>
>
> ** Example files
>
> * apps/files_sharing/email.php
>
> --- SNIP ---
> <?php
> OCP\JSON::checkLoggedIn();
> OCP\JSON::callCheck();
> OCP\JSON::checkAppEnabled('files_sharing');
> $user = OCP\USER::getUser();
> // TODO translations
> $type = (strpos($_POST['file'], '.') === false) ? 'folder' : 'file';
> $tmpl = new OCP\Template('files_sharing', 'email');
> $tmpl->assign('USERNAME', $user);
> $tmpl->assign('SHAREOBJECT', $_POST['file']);
> $tmpl->assign('DOWNLADLINK', $_POST['link']);
> $tmpl->assign('OBJECTTYPE', $type);
> $template = $tmpl->fetchPage();
> $lines = preg_split('/\r?\n/',$template,2);
> $subject = preg_replace('/^Subject: /','',$lines[0]);
> $text = ltrim($lines[1]);
> $fromaddress = OCP\Config::getUserValue($user, 'settings', 'email',
> 'sharing-noreply@'.OCP\Util::getServerHost());
> try {
> OCP\Util::sendMail($_POST['toaddress'], $_POST['toaddress'],
> $subject, $text, $fromaddress, $user);
> OCP\JSON::success();
> } catch (Exception $exception) {
> OCP\JSON::error(array('data' => array('message' =>
> $exception->getMessage())));
> }
> --- /SNIP ---
>
> * apps/files_sharing/templates/email.php
>
> --- SNIP ---
> Subject: <?php echo $_['USERNAME'] ?> shared a <?php echo
> $_['OBJECTTYPE'] ?> with you
> <?php echo $_['USERNAME'] ?> shared the <?php echo $_['OBJECTTYPE'] ?>
> <?php echo $_['SHAREOBJECT'] ?> with you. It is available for download
> here:
> <?php echo $_['DOWNLADLINK'] ?>
> --- /SNIP ---
>
>
> Best regards,
> Martin Werthmoeller
More information about the Owncloud
mailing list