diff --git a/apps/files_sharing/ajax/getmailtemplate.php b/apps/files_sharing/ajax/getmailtemplate.php
new file mode 100644
index 0000000000..8caf0ebcec
--- /dev/null
+++ b/apps/files_sharing/ajax/getmailtemplate.php
@@ -0,0 +1,21 @@
+renderContent();
+ } catch (\OCP\Files\NotPermittedException $ex) {
+ \OC_Response::setStatus(403); // forbidden
+ }
+ exit();
+}
+\OC_Response::setStatus(404); // not found
diff --git a/apps/files_sharing/ajax/resetmailtemplate.php b/apps/files_sharing/ajax/resetmailtemplate.php
new file mode 100644
index 0000000000..4050235bc5
--- /dev/null
+++ b/apps/files_sharing/ajax/resetmailtemplate.php
@@ -0,0 +1,24 @@
+reset();
+ \OC_Response::setStatus(200); // ok
+ } catch (\OCP\Files\NotPermittedException $ex) {
+ \OC_Response::setStatus(403); // forbidden
+ }
+ exit();
+}
+\OC_Response::setStatus(404); // not found
diff --git a/apps/files_sharing/ajax/setmailtemplate.php b/apps/files_sharing/ajax/setmailtemplate.php
new file mode 100644
index 0000000000..d8bb587627
--- /dev/null
+++ b/apps/files_sharing/ajax/setmailtemplate.php
@@ -0,0 +1,24 @@
+setContent($_POST['content']);
+ \OC_Response::setStatus(200); // ok
+ } catch (\OCP\Files\NotPermittedException $ex) {
+ \OC_Response::setStatus(403); // forbidden
+ }
+ exit();
+}
+\OC_Response::setStatus(404); // not found
diff --git a/apps/files_sharing/ajax/settings.php b/apps/files_sharing/ajax/settings.php
new file mode 100644
index 0000000000..da244f8de4
--- /dev/null
+++ b/apps/files_sharing/ajax/settings.php
@@ -0,0 +1,5 @@
+add(
diff --git a/apps/files_sharing/css/settings-admin.css b/apps/files_sharing/css/settings-admin.css
new file mode 100644
index 0000000000..c807fc83c7
--- /dev/null
+++ b/apps/files_sharing/css/settings-admin.css
@@ -0,0 +1,33 @@
+#mailTemplateSettings .actions div {
+ display: inline-block;
+}
+
+#mailTemplateSettings div label {
+ display: block
+}
+
+#mailTemplateSettings textarea {
+ box-sizing: border-box;
+ width: 100%;
+ height: 100px;
+}
+
+#mailTemplateSettings .templateEditor + .actions {
+ height:28px;
+}
+
+
+#mailTemplateSettings .actions .reset {
+ margin: 0;
+}
+
+#mailTemplateSettings .actions .save {
+ float: right;
+ margin: 0;
+}
+
+#mailTemplateSettings #mts-msg {
+ float: right;
+ margin: 1px 5px;
+ padding:3px;
+}
diff --git a/apps/files_sharing/js/settings-admin.js b/apps/files_sharing/js/settings-admin.js
new file mode 100644
index 0000000000..25950b9f4f
--- /dev/null
+++ b/apps/files_sharing/js/settings-admin.js
@@ -0,0 +1,75 @@
+$(document).ready(function() {
+
+ var loadTemplate = function (theme, template) {
+ $.get(
+ OC.filePath( 'files_sharing', 'ajax', 'getmailtemplate.php' )
+ , { theme: theme, template: template }
+ ).done(function( result ) {
+ $( '#mailTemplateSettings textarea' ).val(result);
+ }).fail(function( result ) {
+ alert(result);
+ });
+
+ }
+
+ // load default template
+ var theme = $( '#mts-theme' ).val();
+ var template = $( '#mts-template' ).val();
+ loadTemplate(theme, template);
+
+ $( '#mts-template' ).change(
+ function() {
+ var theme = $( '#mts-theme' ).val();
+ var template = $( this ).val();
+ loadTemplate(theme, template);
+ }
+ );
+ $( '#mts-theme' ).change(
+ function() {
+ var theme = $( this ).val();
+ var template = $( '#mts-template' ).val();
+ loadTemplate(theme, template);
+ }
+ );
+ $( '#mailTemplateSettings .actions' ).on('click', '.save',
+ function() {
+ var theme = $( '#mts-theme' ).val();
+ var template = $( '#mts-template' ).val();
+ var content = $( '#mailTemplateSettings textarea' ).val();
+ OC.msg.startSaving('#mts-msg');
+ $.post(
+ OC.filePath( 'files_sharing', 'ajax', 'setmailtemplate.php' )
+ , { theme: theme, template: template, content: content }
+ ).done(function( result ) {
+ var data = { status:'success', data:{message:t('files_sharing', 'Saved')} };
+ OC.msg.finishedSaving('#mts-msg', data);
+ }).fail(function( result ) {
+ var data = { status:'error', data:{message:t('files_sharing', 'Error')} };
+ OC.msg.finishedSaving('#mts-msg', data);
+ });
+ }
+ );
+ $( '#mailTemplateSettings .actions' ).on('click', '.reset',
+ function() {
+ var theme = $( '#mts-theme' ).val();
+ var template = $( '#mts-template' ).val();
+ var content = $( '#mailTemplateSettings textarea' ).val();
+ OC.msg.startSaving('#mts-msg');
+ $.post(
+ OC.filePath( 'files_sharing', 'ajax', 'resetmailtemplate.php' )
+ , { theme: theme, template: template }
+ ).done(function( result ) {
+ var data = { status:'success', data:{message:t('files_sharing', 'Reset')} };
+ OC.msg.finishedSaving('#mts-msg', data);
+
+ // load default template
+ var theme = $( '#mts-theme' ).val();
+ var template = $( '#mts-template' ).val();
+ loadTemplate(theme, template);
+ }).fail(function( result ) {
+ var data = { status:'error', data:{message:t('files_sharing', 'Error')} };
+ OC.msg.finishedSaving('#mts-msg', data);
+ });
+ }
+ );
+});
diff --git a/apps/files_sharing/lib/mailtemplate.php b/apps/files_sharing/lib/mailtemplate.php
new file mode 100644
index 0000000000..0ea8b6ea34
--- /dev/null
+++ b/apps/files_sharing/lib/mailtemplate.php
@@ -0,0 +1,106 @@
+theme = $theme;
+ $this->path = $path;
+
+ //determine valid theme names
+ $this->editableThemes = self::getEditableThemes();
+ //for now hardcode the valid mail template paths
+ $this->editableTemplates = self::getEditableTemplates();
+ }
+
+ public function renderContent() {
+ if($this->isEditable()) {
+ list($app, $filename) = explode("/templates/", $this->path, 2);
+ $name = substr($filename, 0, -4);
+ list($path, $template) = $this->findTemplate($this->theme, $app, $name, '');
+ \OC_Response::sendFile($template);
+ } else {
+ throw new NotPermittedException('Template not editable.');
+ }
+ }
+
+ public function isEditable() {
+ if ($this->editableThemes[$this->theme]
+ && $this->editableTemplates[$this->path]
+ ) {
+ return true;
+ }
+ return false;
+ }
+ public function setContent($data) {
+ if($this->isEditable()) {
+ //save default templates in default folder to overwrite core template
+ $absolutePath = \OC::$SERVERROOT.'/themes/'.$this->theme.'/'.$this->path;
+ $parent = dirname($absolutePath);
+ if ( ! is_dir($parent) ) {
+ if ( ! mkdir(dirname($absolutePath), 0777, true) ){
+ throw new NotPermittedException('Could not create directory.');
+ }
+ }
+ if ( $this->theme !== 'default' && is_file($absolutePath) ) {
+ if ( ! copy($absolutePath, $absolutePath.'.bak') ){
+ throw new NotPermittedException('Could not create directory.');
+ }
+ }
+ //overwrite theme templates? versioning?
+ return file_put_contents($absolutePath, $data);
+ }
+ throw new NotPermittedException('Template not editable.');
+ }
+ public function reset(){
+ if($this->isEditable()) {
+ $absolutePath = \OC::$SERVERROOT.'/themes/'.$this->theme.'/'.$this->path;
+ if ($this->theme === 'default') {
+ //templates can simply be deleted in the themes folder
+ if (unlink($absolutePath)) {
+ return true;
+ }
+ } else {
+ //if a bak file exists overwrite the template with it
+ if (is_file($absolutePath.'.bak')) {
+ if (rename($absolutePath.'.bak', $absolutePath)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ throw new NotPermittedException('Template not editable.');
+ }
+ public static function getEditableThemes() {
+ $themes = array(
+ 'default' => true
+ );
+ if ($handle = opendir(\OC::$SERVERROOT.'/themes')) {
+ while (false !== ($entry = readdir($handle))) {
+ if ($entry != '.' && $entry != '..') {
+ if (is_dir(\OC::$SERVERROOT.'/themes/'.$entry)) {
+ $themes[$entry] = true;
+ }
+ }
+ }
+ closedir($handle);
+ }
+ return $themes;
+ }
+ public static function getEditableTemplates() {
+ return array(
+ 'core/templates/mail.php' => true,
+ 'core/templates/altmail.php' => true,
+ 'core/lostpassword/templates/email.php' => true,
+ );
+ }
+}
\ No newline at end of file
diff --git a/apps/files_sharing/settings-admin.php b/apps/files_sharing/settings-admin.php
new file mode 100644
index 0000000000..cbc500c218
--- /dev/null
+++ b/apps/files_sharing/settings-admin.php
@@ -0,0 +1,53 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+\OC_Util::checkAdminUser();
+
+if (\OC_Util::getTheme()) {
+ $mailTemplatePath = \OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/core/templates/mail.php';
+}
+
+if (!isset($mailTemplatePath) || !file_exists($mailTemplatePath) ) {
+ $mailTemplatePath = \OC::$SERVERROOT . '/core/templates/mail.php';
+}
+
+if (file_exists($mailTemplatePath)) {
+ $mailTemplate = file_get_contents($mailTemplatePath);
+} else {
+ //log no mail template found
+}
+
+
+\OCP\Util::addStyle('files_sharing', 'settings-admin');
+\OCP\Util::addScript('files_sharing', 'settings-admin');
+//\OCP\Util::addScript('settings', 'personal');
+
+$themes = array('default');
+
+if ($handle = opendir(\OC::$SERVERROOT.'/themes')) {
+ while (false !== ($entry = readdir($handle))) {
+ if ($entry != '.' && $entry != '..') {
+ if (is_dir(\OC::$SERVERROOT.'/themes/'.$entry)) {
+ $themes[] = $entry;
+ }
+ }
+ }
+ closedir($handle);
+}
+
+$editableTemplates = \OCA\Files_Sharing\MailTemplate::getEditableTemplates();
+
+$tmpl = new OCP\Template('files_sharing', 'settings-admin');
+$tmpl->assign('themes', $themes);
+$tmpl->assign('editableTemplates', $editableTemplates);
+
+
+//\OCP\Util::addscript('files_settings', 'settings');
+//\OCP\Util::addscript('core', 'multiselect');
+
+return $tmpl->fetchPage();
diff --git a/apps/files_sharing/templates/settings-admin.php b/apps/files_sharing/templates/settings-admin.php
new file mode 100644
index 0000000000..44864c2471
--- /dev/null
+++ b/apps/files_sharing/templates/settings-admin.php
@@ -0,0 +1,39 @@
+
+
t('Mail templates'));?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/templates/mail.html b/core/templates/mail.html
new file mode 100644
index 0000000000..3382dbf81d
--- /dev/null
+++ b/core/templates/mail.html
@@ -0,0 +1,38 @@
+
+
+
+
+ |
+
+
+ |
+
+ |
+
+ |
+
+t('Hey there,
just letting you know that %s shared %s with you. View it!
', array($_['user_displayname'], $_['filename'], $_['link'])));
+if ( isset($_['expiration']) ) {
+ p($l->t("The share will expire on %s.", array($_['expiration'])));
+ print_unescaped('
');
+}
+p($l->t('Cheers!'));
+?>
+ |
+
+ |
+
+ |
+--
+{{theme.name}} -
+{{theme.slogan}}
+ {{theme.baseurl}}
+ |
+
+
+ |
+
+
+ |
+