Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ While it is possible to manually change email templates within ownCloud, this ap
</description>
<licence>AGPL</licence>
<author>Jörn Dreyer</author>
<version>0.1</version>
<version>0.2</version>
<namespace>TemplateEditor</namespace>
<dependencies>
<owncloud min-version="10.0" max-version="10.0" />
<owncloud min-version="10.0.3" max-version="10.0.99" />
</dependencies>
<shipped>true</shipped>
<default_enable/>
<settings>
<admin>OCA\TemplateEditor\AdminPanel</admin>
Expand Down
25 changes: 10 additions & 15 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* ownCloud - Template Editor
*
* @author Jörn Dreyer
* @copyright 2014 Jörn Dreyer <[email protected]>
* @author Jörn Dreyer <[email protected]>
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand All @@ -21,15 +21,10 @@
*
*/

$app = new \OCA\TemplateEditor\App\TemplateEditor();

$app->registerRoutes($this, array('routes' => array(

// mailTemplate settings
array('name' => 'admin_settings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'),

array('name' => 'admin_settings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'),

array('name' => 'admin_settings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE')

)));
return [
'routes' => [
['name' => 'adminSettings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'],
['name' => 'adminSettings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'],
['name' => 'adminSettings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE'],
]
];
2 changes: 1 addition & 1 deletion js/settings-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $(document).ready(function() {
$( '#mailTemplateSettings .templateEditor + .actions:hidden').show(400);
$.get(
OC.generateUrl('apps/templateeditor/settings/mailtemplate'),
{ theme: theme, template: template }
{ themeName: theme, template: template }
).done(function( result ) {
$( '#mailTemplateSettings textarea' ).val(result);
}).fail(function( result ) {
Expand Down
66 changes: 66 additions & 0 deletions lib/AdminPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* ownCloud - Template Editor
*
* @author Jörn Dreyer <[email protected]>
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\TemplateEditor;

use OCP\Settings\ISettings;
use OCP\Template;

class AdminPanel implements ISettings {

/**
* @var TemplateEditor
*/
private $templateEditor;

/**
* @param TemplateEditor $templateEditor
*/
public function __construct(TemplateEditor $templateEditor) {
$this->templateEditor = $templateEditor;
}

/**
* @return Template
*/
public function getPanel() {
$template = new Template('templateeditor', 'settings-admin');
$template->assign('themeNames', $this->templateEditor->getAllThemeNames());
$template->assign('editableTemplates', $this->templateEditor->getEditableTemplates());
return $template;
}

/**
* @return string
*/
public function getSectionID() {
return 'general';
}

/**
* @return int
*/
public function getPriority() {
return 5;
}
}
33 changes: 20 additions & 13 deletions app/templateeditor.php → lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* ownCloud - Template Editor
*
* @author Jörn Dreyer
* @copyright 2014 Jörn Dreyer <[email protected]>
* @author Jörn Dreyer <[email protected]>
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand All @@ -21,25 +21,32 @@
*
*/

namespace OCA\TemplateEditor\App;
namespace OCA\TemplateEditor\AppInfo;

use OCP\AppFramework\App;
use OCA\TemplateEditor\Controller\AdminSettingsController;
use OCA\TemplateEditor\TemplateEditor;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;

class TemplateEditor extends App {
class Application extends App {

public function __construct(array $urlParams=array()){
/**
* @param array $urlParams
*/
public function __construct(array $urlParams = []) {
parent::__construct('templateeditor', $urlParams);

$container = $this->getContainer();

/**
* Controllers
*/
$container->registerService('AdminSettingsController', function($c) {
$container->registerService('TemplateEditor', function (IAppContainer $container) {
return new TemplateEditor($container->query('ThemeService'));
});

$container->registerService('AdminSettingsController', function(IAppContainer $container) {
return new AdminSettingsController(
$c->query('AppName'),
$c->query('Request')
$container->query('AppName'),
$container->query('Request'),
$container->query('TemplateEditor')
);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* ownCloud - Template Editor
*
* @author Jörn Dreyer
* @copyright 2014 Jörn Dreyer <[email protected]>
* @author Jörn Dreyer <[email protected]>
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand All @@ -23,30 +23,41 @@

namespace OCA\TemplateEditor\Controller;

use OC\Theme\ThemeService;
use OCA\TemplateEditor\TemplateEditor;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCA\TemplateEditor\MailTemplate;

class AdminSettingsController extends ApiController {

public function __construct($appName, IRequest $request) {
/**
* @var TemplateEditor
*/
private $templateEditor;

/**
* @param string $appName
* @param IRequest $request
* @param TemplateEditor $templateEditor
*/
public function __construct($appName, IRequest $request, TemplateEditor $templateEditor) {
parent::__construct($appName, $request);

$this->templateEditor = $templateEditor;
}

/**
* @param string $theme
* @param string $themeName
* @param string $template
* @return \OCP\AppFramework\Http\Response
*/
public function renderTemplate( $theme, $template ) {
public function renderTemplate($themeName, $template) {
try {
$template = $this->getMailTemplate($theme, $template);
$template = $this->templateEditor->getMailTemplate($themeName, $template);
return $template->getResponse();
} catch (\Exception $ex) {
return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode());
return new JSONResponse(['message' => $ex->getMessage()], $ex->getCode());
}
}

Expand All @@ -56,13 +67,13 @@ public function renderTemplate( $theme, $template ) {
* @param string $content
* @return JSONResponse
*/
public function updateTemplate( $theme, $template, $content ) {
public function updateTemplate($theme, $template, $content) {
try {
$template = $this->getMailTemplate($theme, $template);
$template->setContent( $content );
$template = $this->templateEditor->getMailTemplate($theme, $template);
$template->setContent($content);
return new JSONResponse();
} catch (\Exception $ex) {
return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode());
return new JSONResponse(['message' => $ex->getMessage()], $ex->getCode());
}
}

Expand All @@ -71,30 +82,16 @@ public function updateTemplate( $theme, $template, $content ) {
* @param string $template
* @return JSONResponse
*/
public function resetTemplate( $theme, $template ) {
public function resetTemplate($theme, $template) {
try {
$template = $this->getMailTemplate($theme, $template);
$template = $this->templateEditor->getMailTemplate($theme, $template);
if ($template->reset()) {
return new JSONResponse();
} else {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
} catch (\Exception $ex) {
return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode());
return new JSONResponse(['message' => $ex->getMessage()], $ex->getCode());
}
}

/**
* @param string $themeName
* @param string $template
* @return MailTemplate
*/
protected function getMailTemplate($themeName, $template){
$themeService = new ThemeService($themeName);
return new MailTemplate(
$themeService->getTheme(),
$template
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/**
* ownCloud - Template Editor
*
* @author Jörn Dreyer
* @copyright 2014 Jörn Dreyer <[email protected]>
* @author Jörn Dreyer <[email protected]>
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -53,5 +54,4 @@ public function __construct($filename, $contentType = 'text/php') {
public function render(){
return file_get_contents($this->filename);
}

}
Loading