Skip to content
Snippets Groups Projects
Commit 10f6ca20 authored by Bjoern Schiessle's avatar Bjoern Schiessle Committed by Lukas Reschke
Browse files

write theme settings to database

parent 363b76fa
No related branches found
No related tags found
No related merge requests found
Showing with 3115 additions and 12 deletions
...@@ -20,4 +20,4 @@ ...@@ -20,4 +20,4 @@
* *
*/ */
\OCP\App::registerAdmin('theming', 'settings/settings-admin'); \OCP\App::registerAdmin('theming', 'settings/settings-admin');
\ No newline at end of file
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Theming\AppInfo;
(new \OCP\AppFramework\App('theming'))->registerRoutes($this, array('routes' => array(
[
'name' => 'Theming#updateStylesheet',
'url' => '/ajax/updateStylesheet',
'verb' => 'POST'
],
[
'name' => 'Theming#undo',
'url' => '/ajax/undoChanges',
'verb' => 'POST'
],
[
'name' => 'Theming#updateLogo',
'url' => '/ajax/updateLogo',
'verb' => 'POST'
],
)));
#theming input { #theming input {
width: 17em; width: 17em;
} }
#theming .upload-logo-field {
display: none;
}
#theming .theme-undo {
cursor: pointer;
}
#theming .icon {
display: inline-block;
}
#theming .theming-label {
min-width: 6em;
display: inline-block;
}
#theming .icon-upload {
display: inline-flex;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -18,3 +18,86 @@ ...@@ -18,3 +18,86 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
function setThemingValue(setting, value) {
$.post(
OC.generateUrl('/apps/theming/ajax/updateStylesheet'), {'setting' : setting, 'value' : value}
);
preview(setting, value);
}
function preview(setting, value) {
if (setting === 'color') {
var headerClass = document.getElementById('header');
headerClass.style.background = value;
headerClass.style.backgroundImage = '../img/logo-icon.svg';
}
if (setting === 'logoName') {
var logos = document.getElementsByClassName('logo-icon');
for (var i = 0; i < logos.length; i++) {
logos[i].style.background= "url('" + OC.getRootPath() + "/themes/theming-app/core/img/" + value + "')";
}
}
}
$(document).ready(function () {
var uploadparms = {
pasteZone: null,
done: function (e, data) {
preview('logoName', data.result.name);
},
submit: function(e, data) {
},
fail: function (e, data){
}
};
$('#uploadlogo').fileupload(uploadparms);
$('#theming-name').keyup(function (e) {
if (e.keyCode == 13) {
setThemingValue('name', $(this).val());
}
}).focusout(function (e) {
setThemingValue('name', $(this).val());
});
$('#theming-url').keyup(function (e) {
if (e.keyCode == 13) {
setThemingValue('url', $(this).val());
}
}).focusout(function (e) {
setThemingValue('url', $(this).val());
});
$('#theming-slogan').keyup(function (e) {
if (e.keyCode == 13) {
setThemingValue('slogan', $(this).val());
}
}).focusout(function (e) {
setThemingValue('slogan', $(this).val());
});
$('#theming-color').change(function (e) {
setThemingValue('color', '#' + $(this).val());
});
$('.theme-undo').click(function (e) {
var setting = $(this).data('setting');
$.post(
OC.generateUrl('/apps/theming/ajax/undoChanges'), {'setting' : setting}
).done(function(data) {
if (setting === 'color') {
var colorPicker = document.getElementById('theming-color');
colorPicker.style.backgroundColor = data.value;
colorPicker.value = data.value.slice(1);
} else if (setting !== 'logoName') {
var input = document.getElementById('theming-'+setting);
input.value = data.value;
}
preview(setting, data.value);
});
});
});
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Theming\Controller;
use OCA\Theming\Template;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
/**
* Class ThemingController
*
* handle ajax requests to update the theme
*
* @package OCA\Theming\Controller
*/
class ThemingController extends Controller {
/** @var Template */
private $template;
public function __construct($appName, IRequest $request, Template $template) {
parent::__construct($appName, $request);
$this->template = $template;
}
/**
* @param $setting
* @param $value
* @return DataResponse
* @internal param string $color
*/
public function updateStylesheet($setting, $value) {
$this->template->set($setting, $value);
return new DataResponse();
}
/**
* update Nextcloud logo
*
* @return DataResponse
*/
public function updateLogo() {
$newLogo = $this->request->getUploadedFile('uploadlogo');
if (empty($newLogo)) {
return new DataResponse(['message' => 'No logo uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY);
}
$this->template->set('logoName', $newLogo['name']);
rename($newLogo['tmp_name'], \OC::$SERVERROOT . '/themes/theming-app/core/img/' . $newLogo['name']);
return new DataResponse(['name' => $newLogo['name']]);
}
/**
* revert setting to default value
*
* @param string $setting setting which should be reverted
* @return DataResponse
*/
public function undo($setting) {
$value = $this->template->undo($setting);
return new DataResponse(['value' => $value]);
}
}
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Theming;
use OCP\App\ManagerEvent;
use OCP\IConfig;
use OCP\ILogger;
/**
* Class Init
*
* Initialize the app and make sure that all directories and files exists
*
* @package OCA\Theming
*/
class Init {
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/**
* Init constructor.
*
* @param IConfig $config
* @param ILogger $logger
*/
public function __construct(IConfig $config, ILogger $logger) {
$this->config = $config;
$this->logger = $logger;
}
/**
* prepare folders with the theming app and add the default values to it
*/
public function prepareThemeFolder() {
if ($this->config->getSystemValue('theme', 'default') === 'theming-app') {
return;
}
if (!is_writable(\OC::$SERVERROOT . '/themes')) {
$this->logger->warning('Themes folder is read only, can not prepare the theming-app folder',
['app' => 'theming']
);
}
$this->config->setSystemValue('theme', 'theming-app');
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app')) {
mkdir(\OC::$SERVERROOT . '/themes/theming-app');
}
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core')) {
mkdir(\OC::$SERVERROOT . '/themes/theming-app/core');
}
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core/img')) {
mkdir(\OC::$SERVERROOT . '/themes/theming-app/core/img');
}
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core/css')) {
mkdir(\OC::$SERVERROOT . '/themes/theming-app/core/css');
}
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core/img/logo-icon.svg')) {
copy(\OC::$SERVERROOT . '/core/img/logo-icon.svg' ,\OC::$SERVERROOT . '/themes/theming-app/core/img/logo-icon.svg');
}
}
}
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Theming;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
/**
* Class Template
*
* Handle all the values which can be modified by this app
*
* @package OCA\Theming
*/
class Template {
/** @var IConfig */
private $config;
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $urlGenerator;
/** @var Init */
private $init;
/** @var string */
private $name;
/** @var string */
private $url;
/** @var string */
private $slogan;
/** @var string */
private $color;
/** @var string */
private $logoName;
/**
* Template constructor.
*
* @param IConfig $config
* @param IL10N $l
* @param IURLGenerator $urlGenerator
* @param Init $init
*/
public function __construct(IConfig $config,
IL10N $l,
IURLGenerator $urlGenerator,
Init $init
) {
$this->config = $config;
$this->l = $l;
$this->urlGenerator = $urlGenerator;
$this->init = $init;
$this->name = 'Nextcloud';
$this->url = 'https://nextcloud.com';
$this->slogan = $this->l->t('a safe home for all your data');
$this->color = '#0082c9';
$this->logoName = 'logo-icon.svg';
}
public function getName() {
return $this->config->getAppValue('theming', 'name', $this->name);
}
public function getUrl() {
return $this->config->getAppValue('theming', 'url', $this->url);
}
public function getSlogan() {
return $this->config->getAppValue('theming', 'slogan', $this->slogan);
}
public function getColor() {
return $this->config->getAppValue('theming', 'color', $this->color);
}
public function getLogoName() {
return $this->config->getAppValue('theming', 'logoName', $this->logoName);
}
/**
* update setting in the database
*
* @param $setting
* @param $value
*/
public function set($setting, $value) {
$this->init->prepareThemeFolder();
$this->config->setAppValue('theming', $setting, $value);
$this->writeCSSFile();
}
/**
* revert settings to the default value
*
* @param string $setting setting which should be reverted
* @return string default value
*/
public function undo($setting) {
$returnValue = '';
if ($this->$setting) {
$this->config->setAppValue('theming', $setting, $this->$setting);
$this->writeCSSFile();
$returnValue = $this->$setting;
}
return $returnValue;
}
/**
* write setting to a css file
*/
private function writeCSSFile() {
$logo = $this->getLogoName();
$color = $this->getColor();
$css = "
#body-user #header,
#body-settings #header,
#body-public #header {
background-color: $color;
}
/* use logos from theme */
#header .logo {
background-image: url('../img/$logo');
width: 250px;
height: 121px;
}
#header .logo-icon {
background-image: url('../img/$logo');
width: 62px;
height: 34px;
}";
$root = \OC::$SERVERROOT . '/themes/theming-app/core';
file_put_contents($root . '/css/styles.css', $css);
}
}
...@@ -22,6 +22,39 @@ ...@@ -22,6 +22,39 @@
\OC_Util::checkAdminUser(); \OC_Util::checkAdminUser();
$config = \OC::$server->getConfig();
$l = \OC::$server->getL10N('theming');
$urlGenerator = \OC::$server->getURLGenerator();
$init = new \OCA\Theming\Init($config, \OC::$server->getLogger());
$theming = new \OCA\Theming\Template(
$config,
$l,
\OC::$server->getURLGenerator(),
$init
);
$themable = true;
$errorMessage = '';
$theme = $config->getSystemValue('theme', 'default');
if ($theme !== 'theming-app' && $theme !== 'default') {
$themable = false;
$errorMessage = $l->t('You already use a custom theme');
} elseif (!is_writable(\OC::$SERVERROOT . '/themes')) {
$themable = false;
$errorMessage = $l->t('Themes folder is read-only, please update the permissions to read-write');
}
$template = new OCP\Template('theming', 'settings-admin'); $template = new OCP\Template('theming', 'settings-admin');
$template->assign('themable', $themable);
$template->assign('errorMessage', $errorMessage);
$template->assign('name', $theming->getName());
$template->assign('url', $theming->getUrl());
$template->assign('slogan', $theming->getSlogan());
$template->assign('color', $theming->getColor());
$path = $urlGenerator->linkToRoute('theming.Theming.updateLogo');
$template->assign('uploadLogoRoute', $path);
return $template->fetchPage(); return $template->fetchPage();
...@@ -2,24 +2,39 @@ ...@@ -2,24 +2,39 @@
/** @var array $_ */ /** @var array $_ */
/** @var OC_L10N $l */ /** @var OC_L10N $l */
script('theming', 'settings-admin'); script('theming', 'settings-admin');
style('theming', 'settings-admin') script('theming', '3rdparty/jscolor/jscolor');
style('theming', 'settings-admin');
?> ?>
<div id="theming" class="section"> <div id="theming" class="section">
<h2><?php p($l->t('Theming')); ?></h2> <h2><?php p($l->t('Theming')); ?></h2>
<?php if ($_['themable'] === false) { ?>
<p> <p>
<input class="theming-name" type="text" placeholder="<?php p($l->t('Name')); ?>"></input> <?php p($_['errorMessage']) ?>
</p> </p>
<?php } else { ?>
<p> <p>
<input class="theming-address" type="text" placeholder="<?php p($l->t('Web address https://…')); ?>"></input> <span class="theming-label">Name:</span> <input id="theming-name" type="text" placeholder="<?php p($l->t('Name')); ?>" value="<?php p($_['name']) ?>"></input>
<span data-setting="name" data-original-title="<?php p($l->t('revert to original value')); ?>" class="theme-undo icon icon-history"></span>
</p> </p>
<p> <p>
<input class="theming-slogan" type="text" placeholder="<?php p($l->t('Slogan')); ?>"></input> <span class="theming-label">URL:</span> <input id="theming-url"type="text" placeholder="<?php p($l->t('Web address https://…')); ?>" value="<?php p($_['url']) ?>"></input>
<span data-setting="url" data-original-title="<?php p($l->t('revert to original value')); ?>" class="theme-undo icon icon-history"></span>
</p> </p>
<p> <p>
<input class="theming-color" type="text" placeholder="<?php p($l->t('Color #0082c9')); ?>"></input> <span class="theming-label">Slogan:</span> <input id="theming-slogan" type="text" placeholder="<?php p($l->t('Slogan')); ?>" value="<?php p($_['slogan']) ?>"></input>
<span data-setting="slogan" data-original-title="<?php p($l->t('revert to original value')); ?>" class="theme-undo icon icon-history"></span>
</p> </p>
<p> <p>
<input class="theming-logo" type="text" placeholder="<?php p($l->t('Logo')); ?>"></input> <span class="theming-label">Color:</span> <input id="theming-color" class="jscolor" value="<?php p($_['color']) ?>"></input>
<span data-setting="color" data-original-title="<?php p($l->t('revert to original value')); ?>" class="theme-undo icon icon-history"></span>
</p> </p>
<p>
<form class="uploadButton" method="post" action="<?php p($_['uploadLogoRoute']) ?>">
<span class="theming-label">Logo:</span>
<input id="uploadlogo" class="upload-logo-field" name="uploadlogo" type="file">
<label for="uploadlogo" class="button icon-upload svg" id="uploadlogo" title="Upload new logo"></label>
<span data-setting="logoName" data-original-title="<?php p($l->t('revert to original value')); ?>" class="theme-undo icon icon-history"></span>
</form>
</p>
<?php } ?>
</div> </div>
...@@ -31,8 +31,13 @@ ...@@ -31,8 +31,13 @@
class OC_Defaults { class OC_Defaults {
private $theme; private $theme;
/** @var \OCP\IL10N */
private $l; private $l;
/** @var \OCA\Theming\Template */
private $template;
private $defaultEntity; private $defaultEntity;
private $defaultName; private $defaultName;
private $defaultTitle; private $defaultTitle;
...@@ -49,21 +54,45 @@ class OC_Defaults { ...@@ -49,21 +54,45 @@ class OC_Defaults {
function __construct() { function __construct() {
$this->l = \OC::$server->getL10N('lib'); $this->l = \OC::$server->getL10N('lib');
$config = \OC::$server->getConfig();
try {
$themingAppEnabled = $config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming');
} catch (\Exception $e) {
$themingAppEnabled = false;
}
$config = \OC::$server->getConfig();
if ($themingAppEnabled) {
$this->template = new \OCA\Theming\Template(
$config,
$this->l,
\OC::$server->getURLGenerator(),
new \OCA\Theming\Init($config, \OC::$server->getLogger())
);
$this->defaultName = $this->template->getName(); /* short name, used when referring to the software */
$this->defaultBaseUrl = $this->template->getUrl();
$this->defaultSlogan = $this->template->getSlogan();
$this->defaultMailHeaderColor = $this->template->getColor(); /* header color of mail notifications */
} else {
$this->defaultName = 'Nextcloud';
$this->defaultBaseUrl = 'https://nextcloud.com';
$this->defaultSlogan = $this->l->t('a safe home for all your data');
$this->defaultMailHeaderColor = '#0082c9'; /* header color of mail notifications */
}
$version = \OCP\Util::getVersion(); $version = \OCP\Util::getVersion();
$this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
$this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
$this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
$this->defaultBaseUrl = 'https://nextcloud.com';
$this->defaultSyncClientUrl = 'https://nextcloud.com/install'; $this->defaultSyncClientUrl = 'https://nextcloud.com/install';
$this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/owncloud/id543672169?mt=8'; $this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/owncloud/id543672169?mt=8';
$this->defaultiTunesAppId = '543672169'; $this->defaultiTunesAppId = '543672169';
$this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.owncloud.android'; $this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.owncloud.android';
$this->defaultDocBaseUrl = 'https://doc.owncloud.org'; $this->defaultDocBaseUrl = 'https://doc.owncloud.org';
$this->defaultDocVersion = $version[0] . '.' . $version[1]; // used to generate doc links $this->defaultDocVersion = $version[0] . '.' . $version[1]; // used to generate doc links
$this->defaultSlogan = $this->l->t('a safe home for all your data');
$this->defaultLogoClaim = ''; $this->defaultLogoClaim = '';
$this->defaultMailHeaderColor = '#0082c9'; /* header color of mail notifications */
$themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
if (file_exists($themePath)) { if (file_exists($themePath)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment