Closes #231 -- Allow custom CSS branding on public and internal pages.
This commit is contained in:
parent
9ca833d846
commit
316e43886f
|
@ -12,6 +12,11 @@ return [
|
|||
'icon' => 'zmdi zmdi-settings',
|
||||
'permission' => 'administer settings',
|
||||
],
|
||||
_('Custom Branding') => [
|
||||
'url' => 'admin:branding:index',
|
||||
'icon' => 'zmdi zmdi-brush',
|
||||
'permission' => 'administer settings',
|
||||
],
|
||||
_('API Keys') => [
|
||||
'url' => 'admin:api:index',
|
||||
'icon' => 'zmdi zmdi-key',
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
$settings = $di['app_settings'];
|
||||
|
||||
return [
|
||||
'method' => 'post',
|
||||
|
||||
'elements' => [
|
||||
|
||||
'public_theme' => [
|
||||
'radio',
|
||||
[
|
||||
'label' => _('Base Theme for Public Pages'),
|
||||
'description' => _('Select a theme to use as a base for station public pages and the login page.'),
|
||||
'options' => $settings['themes']['available'],
|
||||
'default' => $settings['themes']['default'],
|
||||
]
|
||||
],
|
||||
|
||||
'custom_css_public' => [
|
||||
'textarea',
|
||||
[
|
||||
'label' => _('Custom CSS for Public Pages'),
|
||||
'description' => _('This CSS will be applied to the station public pages and login page.'),
|
||||
'class' => 'css-editor',
|
||||
]
|
||||
],
|
||||
|
||||
'custom_css_internal' => [
|
||||
'textarea',
|
||||
[
|
||||
'label' => _('Custom CSS for Internal Pages'),
|
||||
'description' => _('This CSS will be applied to the main management pages, like this one.'),
|
||||
'class' => 'css-editor',
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
|
||||
'submit' => [
|
||||
'submit',
|
||||
[
|
||||
'type' => 'submit',
|
||||
'label' => _('Save Changes'),
|
||||
'class' => 'btn btn-lg btn-primary',
|
||||
]
|
||||
],
|
||||
|
||||
],
|
||||
];
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
namespace Controller\Admin;
|
||||
|
||||
use Entity\Repository;
|
||||
use Entity\Settings;
|
||||
|
||||
class BrandingController extends BaseController
|
||||
{
|
||||
public function permissions()
|
||||
{
|
||||
return $this->acl->isAllowed('administer settings');
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
/** @var Repository\SettingsRepository $settings_repo */
|
||||
$settings_repo = $this->em->getRepository(Settings::class);
|
||||
|
||||
$cleanup_filter = function($val) {
|
||||
return strip_tags($val);
|
||||
};
|
||||
|
||||
$form_config = $this->config->forms->branding->toArray();
|
||||
foreach($form_config['elements'] as $element_key => $element_info) {
|
||||
if (substr($element_key, 0, 10) === 'custom_css') {
|
||||
$form_config['elements'][$element_key][1]['filter'] = $cleanup_filter;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new \App\Form($form_config);
|
||||
|
||||
$existing_settings = $settings_repo->fetchArray(false);
|
||||
$form->setDefaults($existing_settings);
|
||||
|
||||
if (!empty($_POST) && $form->isValid($_POST)) {
|
||||
$data = $form->getValues();
|
||||
unset($data['submit']);
|
||||
|
||||
$settings_repo->setSettings($data);
|
||||
|
||||
$this->alert(_('Changes saved.'), 'green');
|
||||
|
||||
return $this->redirectHere();
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,8 @@ class SettingsController extends BaseController
|
|||
|
||||
if (!empty($_POST) && $form->isValid($_POST)) {
|
||||
$data = $form->getValues();
|
||||
unset($data['submit']);
|
||||
|
||||
$settings_repo->setSettings($data);
|
||||
|
||||
$this->alert(_('Changes saved.'), 'green');
|
||||
|
|
|
@ -30,6 +30,7 @@ return function(\Slim\App $app) {
|
|||
});
|
||||
|
||||
$this->map(['GET', 'POST'], '/settings', 'admin:settings:index')->setName('admin:settings:index');
|
||||
$this->map(['GET', 'POST'], '/branding', 'admin:branding:index')->setName('admin:branding:index');
|
||||
|
||||
$this->group('/stations', function () {
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php $this->layout('main', ['title' => _('Custom Branding')]); ?>
|
||||
|
||||
<?=$this->fetch('partials/form') ?>
|
||||
|
||||
<?php $this->start('custom_js') ?>
|
||||
<script type="text/javascript" src="<?=$url->content('bower_components/codemirror/lib/codemirror.js') ?>"></script>
|
||||
<script type="text/javascript" src="<?=$url->content('bower_components/codemirror/mode/css/css.js') ?>"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
|
||||
$('textarea.css-editor').each(function() {
|
||||
CodeMirror.fromTextArea($(this)[0], {
|
||||
lineNumbers: true,
|
||||
theme: 'default material'
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php $this->stop('custom_js') ?>
|
||||
<?php $this->start('custom_css') ?>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$url->content('bower_components/codemirror/lib/codemirror.css') ?>">
|
||||
|
||||
<?php if ($customization->getTheme() !== 'light'): ?>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$url->content('bower_components/codemirror/theme/material.css') ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $this->stop('custom_css') ?>
|
|
@ -104,4 +104,34 @@ class Customization
|
|||
|
||||
return $instance_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the theme name to be used in public (non-logged-in) pages.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicTheme()
|
||||
{
|
||||
return $this->settings_repo->getSetting('public_theme', $this->app_settings['themes']['default']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the administrator-supplied custom CSS for public (minimal layout) pages, if specified.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCustomPublicCss()
|
||||
{
|
||||
return (string)$this->settings_repo->getSetting('custom_css_public', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the administrator-supplied custom CSS for internal (full layout) pages, if specified.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCustomInternalCss()
|
||||
{
|
||||
return (string)$this->settings_repo->getSetting('custom_css_internal', '');
|
||||
}
|
||||
}
|
|
@ -38,6 +38,10 @@ if (!APP_IN_PRODUCTION)
|
|||
|
||||
<?=$this->section('custom_css') ?>
|
||||
|
||||
<style type="text/css">
|
||||
<?=$customization->getCustomInternalCss() ?>
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="<?=$assets->getPath('css/'.$customization->getTheme().'.css') ?>">
|
||||
|
||||
<script type="text/javascript" src="<?=$url->content('bower_components/jquery/dist/jquery.min.js') ?>"></script>
|
||||
|
|
|
@ -32,10 +32,14 @@ if (!APP_IN_PRODUCTION)
|
|||
|
||||
<link rel="stylesheet" type="text/css" href="<?=$url->content('bower_components/animate.css/animate.min.css') ?>">
|
||||
<link rel="stylesheet" type="text/css" href="<?=$url->content('bower_components/material-design-iconic-font/dist/css/material-design-iconic-font.min.css') ?>">
|
||||
<link rel="stylesheet" type="text/css" href="<?=$url->content('css/'.$customization->getTheme().'.css') ?>">
|
||||
<link rel="stylesheet" type="text/css" href="<?=$url->content('css/'.$customization->getPublicTheme().'.css') ?>">
|
||||
|
||||
<?=$this->section('custom_css') ?>
|
||||
|
||||
<style type="text/css">
|
||||
<?=$customization->getCustomPublicCss() ?>
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="<?=$url->content('bower_components/jquery/dist/jquery.min.js') ?>"></script>
|
||||
<script type="text/javascript" src="<?=$url->content('bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
|
||||
<script type="text/javascript" src="<?= $url->content('bower_components/vue/dist/' . (APP_IN_PRODUCTION ? 'vue.min.js' : 'vue.js')) ?>"></script>
|
||||
|
|
|
@ -513,32 +513,32 @@
|
|||
},
|
||||
{
|
||||
"name": "doctrine/instantiator",
|
||||
"version": "1.0.5",
|
||||
"version": "1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/instantiator.git",
|
||||
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
|
||||
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
|
||||
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
|
||||
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
|
||||
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3,<8.0-DEV"
|
||||
"php": "^7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"athletic/athletic": "~0.1.8",
|
||||
"ext-pdo": "*",
|
||||
"ext-phar": "*",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
"phpunit/phpunit": "^6.2.3",
|
||||
"squizlabs/php_codesniffer": "^3.0.2"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
"dev-master": "1.2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -563,7 +563,7 @@
|
|||
"constructor",
|
||||
"instantiate"
|
||||
],
|
||||
"time": "2015-06-14T21:17:01+00:00"
|
||||
"time": "2017-07-22T11:58:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/lexer",
|
||||
|
@ -695,16 +695,16 @@
|
|||
},
|
||||
{
|
||||
"name": "doctrine/orm",
|
||||
"version": "v2.5.10",
|
||||
"version": "v2.5.11",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/doctrine2.git",
|
||||
"reference": "c78afd51721804f4f76ff30d9b6f6159eb046161"
|
||||
"reference": "249b737094f1e7cba4f0a8d19acf5be6cf3ed504"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/doctrine2/zipball/c78afd51721804f4f76ff30d9b6f6159eb046161",
|
||||
"reference": "c78afd51721804f4f76ff30d9b6f6159eb046161",
|
||||
"url": "https://api.github.com/repos/doctrine/doctrine2/zipball/249b737094f1e7cba4f0a8d19acf5be6cf3ed504",
|
||||
"reference": "249b737094f1e7cba4f0a8d19acf5be6cf3ed504",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -712,7 +712,7 @@
|
|||
"doctrine/collections": "~1.2",
|
||||
"doctrine/common": ">=2.5-dev,<2.9-dev",
|
||||
"doctrine/dbal": ">=2.5-dev,<2.7-dev",
|
||||
"doctrine/instantiator": "~1.0.1",
|
||||
"doctrine/instantiator": "^1.0.1",
|
||||
"ext-pdo": "*",
|
||||
"php": ">=5.4",
|
||||
"symfony/console": "~2.5|~3.0"
|
||||
|
@ -767,7 +767,7 @@
|
|||
"database",
|
||||
"orm"
|
||||
],
|
||||
"time": "2017-08-18T19:17:35+00:00"
|
||||
"time": "2017-09-18T06:50:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "electrolinux/phpquery",
|
||||
|
|
Loading…
Reference in New Issue