summaryrefslogtreecommitdiffstats
path: root/apps/theming/lib/template.php
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2016-06-09 21:46:30 +0200
committerLukas Reschke <lukas@owncloud.com>2016-06-27 10:26:22 +0200
commit10f6ca20bcf521f125700f892b09bf745a595ea7 (patch)
tree668da5e4ba4580ede60773abf254e42c46fb5a97 /apps/theming/lib/template.php
parent363b76faee862e1cccd826d25a0f208ef656e1bc (diff)
downloadnextcloud-server-10f6ca20bcf521f125700f892b09bf745a595ea7.tar.gz
nextcloud-server-10f6ca20bcf521f125700f892b09bf745a595ea7.zip
write theme settings to database
Diffstat (limited to 'apps/theming/lib/template.php')
-rw-r--r--apps/theming/lib/template.php172
1 files changed, 172 insertions, 0 deletions
diff --git a/apps/theming/lib/template.php b/apps/theming/lib/template.php
new file mode 100644
index 00000000000..177ead69889
--- /dev/null
+++ b/apps/theming/lib/template.php
@@ -0,0 +1,172 @@
+<?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);
+ }
+
+}