[Owncloud] files_sharing - sharing emails as templates

Martin Werthmöller mw+owncloud at lw-systems.de
Tue Aug 14 15:39:08 UTC 2012


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

-- 
LWsystems - IT-Service and Consulting
mw at lw-systems.de * http://www.lw-systems.de



More information about the Owncloud mailing list