diff --git a/flavours/styles.php b/flavours/styles.php deleted file mode 100644 index a2e3b3d345e..00000000000 --- a/flavours/styles.php +++ /dev/null @@ -1,90 +0,0 @@ -. - -/** - * Theme Boost Union - Flavours styles serving - * - * @package theme_boost_union - * @copyright 2022 Alexander Bias, lern.link GmbH - * @copyright on behalf of Zurich University of Applied Sciences (ZHAW) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -// Do not show any debug messages and any errors which might break the shipped CSS. -define('NO_DEBUG_DISPLAY', true); - -// Do not do any upgrade checks here. -define('NO_UPGRADE_CHECK', true); - -// Require config. -// @codingStandardsIgnoreStart -// Let codechecker ignore the next line because otherwise it would complain about a missing login check -// after requiring config.php which is really not needed.require('../config.php'); -require(__DIR__.'/../../../config.php'); -// @codingStandardsIgnoreEnd - -// Require css sending libraries. -require_once($CFG->dirroot.'/lib/csslib.php'); -require_once($CFG->dirroot.'/lib/configonlylib.php'); - -// Get parameters. -$flavourid = required_param('id', PARAM_INT); -$themerev = required_param('rev', PARAM_INT); // We do not really need the theme revision in this script, we just require it - // to support proper cache control in the browser. - -// Initialize SCSS code. -$scss = ''; - -// Get the raw SCSS and the background image from the database, -// throw an exception if it does not exist because then something is really wrong. -try { - // Note: It would be worthwhile to pick this data from a MUC instance instead of fetching it from the DB - // again and again. However, as the result is cached in the browser and the browser should not request - // a flavour's CSS file again and again this should be ok for now. - $flavour = $DB->get_record('theme_boost_union_flavours', - array('id' => $flavourid), 'look_rawscss, look_backgroundimage', MUST_EXIST); - - // Catch the exception. -} catch (\Exception $e) { - // Just die, there is no use to output any error message, it would even be counter-productive if the browser - // tries to interpret it as CSS code. - die; -} - -// If the flavour has raw SCSS code. -// Note: In the current state of implementation, this setting only allows the usage of custom CSS, not SCSS. -// There is a follow-up issue on Github to add SCSS support. -// However, to ease this future improvement, the setting has already been called 'rawscss'. -if (!empty($flavour->look_rawscss)) { - // Add it to the SCSS code. - $scss .= $flavour->look_rawscss; -} - -// If the flavour has a background image. -if ($flavour->look_backgroundimage != null) { - // Compose the URL to the flavour's background image. - $backgroundimageurl = moodle_url::make_pluginfile_url( - context_system::instance()->id, 'theme_boost_union', 'flavours_look_backgroundimage', $flavourid, - '/'.theme_get_revision(), '/'.$flavour->look_backgroundimage); - - // And add it to the SCSS code, adhering the fact that we must not overwrite the login page background image again. - $scss .= 'body:not(.pagelayout-login) { '; - $scss .= 'background-image: url("'.$backgroundimageurl.'");'; - $scss .= '}'; -} - -// Send out the resulting CSS code. The theme revision will be set as etag to support the browser caching. -css_send_cached_css_content($scss, theme_get_revision()); diff --git a/lib.php b/lib.php index 0c3f15ceff3..358412195a3 100644 --- a/lib.php +++ b/lib.php @@ -237,6 +237,20 @@ function theme_boost_union_get_pre_scss($theme) { if ($rawscsspre !== false) { $scss .= "\n/** RAW-SCSS from theme_boost_union_get_pre_scss **/\n" . $rawscsspre; } + + // If the flavour has a background image. + $backgroundimage = theme_boost_union_get_flavour_config_item_for_id($flavourid, 'look_backgroundimage'); + if ($backgroundimage != false) { + // Compose the URL to the flavour's background image. + $backgroundimageurl = moodle_url::make_pluginfile_url( + context_system::instance()->id, 'theme_boost_union', 'flavours_look_backgroundimage', $flavourid, + '/'.theme_get_revision(), '/'.$backgroundimage); + + // And add it to the SCSS code, adhering the fact that we must not overwrite the login page background image again. + $scss .= 'body:not(.pagelayout-login) { '; + $scss .= 'background-image: url("'.$backgroundimageurl.'");'; + $scss .= '}'; + } } // Since setting "precss" is originally from parent boost it is added in theme_boost_get_pre_scss. return $scss; @@ -308,7 +322,7 @@ function theme_boost_union_get_extra_scss($theme) { // Note: Boost Union is also capable of overriding the background image in its flavours. // In contrast to the other flavour assets like the favicon overriding, this isn't done here in place as this function // is composing Moodle core CSS which has to remain flavour-independent. - // Instead, the flavour is overriding the background image later in flavours/styles.php. + // Instead, the flavour is overriding the background image later in theme_boost_union_get_pre_scss() lib.php. // For the rest of this function, we add SCSS snippets to the SCSS stack based on enabled admin settings. // This is done here as it is quite easy to do. As an alternative, it could also been done in post.css by using @@ -527,9 +541,6 @@ function theme_boost_union_before_standard_html_head() { // Add the FontAwesome icons to the page. theme_boost_union_add_fontawesome_to_page(); - // Add the flavour CSS to the page. - theme_boost_union_add_flavourcss_to_page(); // Todo remove em when flavour pre/post scss goes prod. - // Return an empty string to keep the caller happy. return $html; } diff --git a/locallib.php b/locallib.php index 479c88bccbf..38e3ab72422 100644 --- a/locallib.php +++ b/locallib.php @@ -1215,32 +1215,6 @@ function theme_boost_union_add_fontawesome_to_page() { } } -/** - * Helper function which adds the CSS file from the flavour to the Moodle page. - * It's meant to be called by theme_boost_union_before_standard_html_head() only. - * * - * @throws coding_exception - * @throws dml_exception - * @throws moodle_exception - */ -function theme_boost_union_add_flavourcss_to_page() { - global $CFG, $PAGE; - - // Require flavours library. - require_once($CFG->dirroot . '/theme/boost_union/flavours/flavourslib.php'); - - // If any flavour applies to this page. - $flavour = theme_boost_union_get_flavour_which_applies(); - if ($flavour != null) { - // Build the flavour CSS file URL. - $flavourcssurl = new moodle_url('/theme/boost_union/flavours/styles.php', - array('id' => $flavour->id, 'rev' => theme_get_revision())); - - // Add the CSS file to the page. - $PAGE->requires->css($flavourcssurl); - } -} - /** * Helper function which returns the course header image url, picking the current course from the course settings * or the fallback image from the theme.