From 6961f78dcae1c0e217e6e0817813570f15af3d54 Mon Sep 17 00:00:00 2001 From: Craig R Morton Date: Fri, 6 Jan 2017 13:48:07 +0800 Subject: [PATCH] MDL-60309 theme_boost: Add background image filepicker to Boost --- theme/boost/lang/en/theme_boost.php | 2 ++ theme/boost/lib.php | 38 ++++++++++++++++++++++++++++- theme/boost/settings.php | 8 ++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/theme/boost/lang/en/theme_boost.php b/theme/boost/lang/en/theme_boost.php index 332b5ff621a..d3941ee9ae2 100644 --- a/theme/boost/lang/en/theme_boost.php +++ b/theme/boost/lang/en/theme_boost.php @@ -25,6 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $string['advancedsettings'] = 'Advanced settings'; +$string['backgroundimage'] = 'Background image'; +$string['backgroundimage_desc'] = 'The image to display as a background of the site. The background image you upload here will override the background image in your theme preset files.'; $string['brandcolor'] = 'Brand colour'; $string['brandcolor_desc'] = 'The accent colour.'; $string['choosereadme'] = 'Boost is a modern highly-customisable theme. This theme is intended to be used directly, or as a parent theme when creating new themes utilising Bootstrap 4.'; diff --git a/theme/boost/lib.php b/theme/boost/lib.php index e662f64c939..ecccd5119f2 100644 --- a/theme/boost/lib.php +++ b/theme/boost/lib.php @@ -42,7 +42,43 @@ function theme_boost_css_tree_post_processor($tree, $theme) { * @return string */ function theme_boost_get_extra_scss($theme) { - return !empty($theme->settings->scss) ? $theme->settings->scss : ''; + $content = ''; + $imageurl = $theme->setting_file_url('backgroundimage', 'backgroundimage'); + + // Sets the background image, and its settings. + if (!empty($imageurl)) { + $content .= 'body { '; + $content .= "background-image: url('$imageurl');"; + $content .= ' }'; + } + + // Always return the background image with the scss when we have it. + return !empty($theme->settings->scss) ? $theme->settings->scss . ' ' . $content : $content; +} + +/** + * Serves any files associated with the theme settings. + * + * @param stdClass $course + * @param stdClass $cm + * @param context $context + * @param string $filearea + * @param array $args + * @param bool $forcedownload + * @param array $options + * @return bool + */ +function theme_boost_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { + if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'logo' || $filearea === 'backgroundimage')) { + $theme = theme_config::load('boost'); + // By default, theme files must be cache-able by both browsers and proxies. + if (!array_key_exists('cacheability', $options)) { + $options['cacheability'] = 'public'; + } + return $theme->setting_file_serve($filearea, $args, $forcedownload, $options); + } else { + send_file_not_found(); + } } /** diff --git a/theme/boost/settings.php b/theme/boost/settings.php index 15b2c391040..c7cde2b2017 100644 --- a/theme/boost/settings.php +++ b/theme/boost/settings.php @@ -57,6 +57,14 @@ if ($ADMIN->fulltree) { array('maxfiles' => 20, 'accepted_types' => array('.scss'))); $page->add($setting); + // Background image setting. + $name = 'theme_boost/backgroundimage'; + $title = get_string('backgroundimage', 'theme_boost'); + $description = get_string('backgroundimage_desc', 'theme_boost'); + $setting = new admin_setting_configstoredfile($name, $title, $description, 'backgroundimage'); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + // Variable $body-color. // We use an empty default value because the default colour should come from the preset. $name = 'theme_boost/brandcolor';