Custom JS in public page (#461)

* Add custom JS field in Branding configuration page to add custom script in public webpages.
This commit is contained in:
Brett Montgomery 2018-02-28 16:25:33 +01:00 committed by Buster "Silver Eagle" Neece
parent 49210ddeba
commit e5fc9e9636
5 changed files with 40 additions and 3 deletions

View File

@ -37,6 +37,16 @@ return [
]
],
'custom_js_public' => [
'textarea',
[
'label' => _('Custom JS for Public Pages'),
'description' => _('This javascript code will be applied to the station public pages and login page.'),
'class' => 'js-editor',
'filter' => function($val) { return strip_tags($val); }
]
],
'custom_css_internal' => [
'textarea',
[

View File

@ -682,7 +682,7 @@ msgstr ""
#: /var/azuracast/www/app/config/forms/rename.conf.php:18
#: /var/azuracast/www/app/config/forms/song.conf.php:47
#: /var/azuracast/www/app/config/forms/streamer.conf.php:61
#: /var/azuracast/www/app/config/forms/branding.conf.php:56
#: /var/azuracast/www/app/config/forms/branding.conf.php:66
#: /var/azuracast/www/app/config/forms/webhook/generic.conf.php:49
#: /var/azuracast/www/app/config/forms/webhook/twitter.conf.php:95
#: /var/azuracast/www/app/config/forms/webhook/discord.conf.php:115
@ -1779,10 +1779,18 @@ msgid "This CSS will be applied to the station public pages and login page."
msgstr ""
#: /var/azuracast/www/app/config/forms/branding.conf.php:43
msgid "Custom CSS for Internal Pages"
msgid "Custom CSS for Public Pages"
msgstr ""
#: /var/azuracast/www/app/config/forms/branding.conf.php:44
msgid "This CSS will be applied to the station public pages and login page."
msgstr ""
#: /var/azuracast/www/app/config/forms/branding.conf.php:53
msgid "Custom CSS for Internal Pages"
msgstr ""
#: /var/azuracast/www/app/config/forms/branding.conf.php:54
msgid "This CSS will be applied to the main management pages, like this one."
msgstr ""

View File

@ -183,6 +183,16 @@ class Customization
return (string)$this->settings_repo->getSetting('custom_css_public', '');
}
/**
* Return the administrator-supplied custom JS for public (minimal layout) pages, if specified.
*
* @return string
*/
public function getCustomPublicJs()
{
return (string)$this->settings_repo->getSetting('custom_js_public', '');
}
/**
* Return the administrator-supplied custom CSS for internal (full layout) pages, if specified.
*
@ -202,4 +212,4 @@ class Customization
{
return (bool)$this->settings_repo->getSetting('hide_product_name', false);
}
}
}

View File

@ -16,6 +16,12 @@ $assets
});
});
$('textarea.js-editor').each(function() {
CodeMirror.fromTextArea($(this)[0], {
lineNumbers: true,
theme: '<?=(($customization->getTheme() === 'light') ? 'default' : 'material') ?>'
});
});
});
</script>

View File

@ -66,5 +66,8 @@ $assets
});
</script>
<?php endif; ?>
<script type="text/javascript" nonce="<?=$assets->getCspNonce() ?>">
<?=$customization->getCustomPublicJs() ?>
</script>
</body>
</html>