MDL-44357 theme_more: New customizable theme
AMOS BEGIN
CPY [choosereadme,theme_clean],[choosereadme,theme_more]
CPY [configtitle,theme_clean],[configtitle,theme_more]
CPY [customcss,theme_clean],[customcss,theme_more]
CPY [customcssdesc,theme_clean],[customcssdesc,theme_more]
CPY [footnote,theme_clean],[footnote,theme_more]
CPY [footnotedesc,theme_clean],[footnotedesc,theme_more]
CPY [invert,theme_clean],[invert,theme_more]
CPY [invertdesc,theme_clean],[invertdesc,theme_more]
CPY [logo,theme_clean],[logo,theme_more]
CPY [logodesc,theme_clean],[logodesc,theme_more]
CPY [pluginname,theme_clean],[pluginname,theme_more]
CPY [region-side-post,theme_clean],[region-side-post,theme_more]
CPY [region-side-pre,theme_clean],[region-side-pre,theme_more]
AMOS END
2014-03-17 14:43:23 +08:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle 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 General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme More lib.
|
|
|
|
*
|
|
|
|
* @package theme_more
|
|
|
|
* @copyright 2014 Frédéric Massart
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2014-03-18 17:59:11 +08:00
|
|
|
/**
|
|
|
|
* Extra LESS code to inject.
|
|
|
|
*
|
|
|
|
* This will generate some LESS code from the settings used by the user. We cannot use
|
|
|
|
* the {@link theme_more_less_variables()} here because we need to create selectors or
|
|
|
|
* alter existing ones.
|
|
|
|
*
|
|
|
|
* @param theme_config $theme The theme config object.
|
|
|
|
* @return string Raw LESS code.
|
|
|
|
*/
|
|
|
|
function theme_more_extra_less($theme) {
|
|
|
|
$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');";
|
|
|
|
if (!empty($theme->settings->backgroundfixed)) {
|
|
|
|
$content .= 'background-attachment: fixed;';
|
|
|
|
}
|
|
|
|
if (!empty($theme->settings->backgroundposition)) {
|
|
|
|
$content .= 'background-position: ' . str_replace('_', ' ', $theme->settings->backgroundposition) . ';';
|
|
|
|
}
|
|
|
|
if (!empty($theme->settings->backgroundrepeat)) {
|
|
|
|
$content .= 'background-repeat: ' . $theme->settings->backgroundrepeat . ';';
|
|
|
|
}
|
|
|
|
$content .= ' }';
|
|
|
|
}
|
|
|
|
// If there the user wants a background for the content, we need to make it look consistent,
|
|
|
|
// therefore we need to round its borders, and adapt the border colour.
|
|
|
|
if (!empty($theme->settings->contentbackground)) {
|
|
|
|
$content .= '
|
|
|
|
#region-main {
|
|
|
|
.well;
|
|
|
|
background-color: ' . $theme->settings->contentbackground . ';
|
|
|
|
border-color: darken(' . $theme->settings->contentbackground . ', 7%);
|
|
|
|
}';
|
|
|
|
}
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns variables for LESS.
|
|
|
|
*
|
|
|
|
* We will inject some LESS variables from the settings that the user has defined
|
|
|
|
* for the theme. No need to write some custom LESS for this.
|
|
|
|
*
|
|
|
|
* @param theme_config $theme The theme config object.
|
|
|
|
* @return array of LESS variables without the @.
|
|
|
|
*/
|
|
|
|
function theme_more_less_variables($theme) {
|
|
|
|
$variables = array();
|
|
|
|
if (!empty($theme->settings->bodybackground)) {
|
|
|
|
$variables['bodyBackground'] = $theme->settings->bodybackground;
|
|
|
|
}
|
|
|
|
if (!empty($theme->settings->textcolor)) {
|
|
|
|
$variables['textColor'] = $theme->settings->textcolor;
|
|
|
|
}
|
|
|
|
if (!empty($theme->settings->linkcolor)) {
|
|
|
|
$variables['linkColor'] = $theme->settings->linkcolor;
|
|
|
|
}
|
|
|
|
if (!empty($theme->settings->secondarybackground)) {
|
|
|
|
$variables['wellBackground'] = $theme->settings->secondarybackground;
|
|
|
|
}
|
|
|
|
return $variables;
|
|
|
|
}
|
|
|
|
|
MDL-44357 theme_more: New customizable theme
AMOS BEGIN
CPY [choosereadme,theme_clean],[choosereadme,theme_more]
CPY [configtitle,theme_clean],[configtitle,theme_more]
CPY [customcss,theme_clean],[customcss,theme_more]
CPY [customcssdesc,theme_clean],[customcssdesc,theme_more]
CPY [footnote,theme_clean],[footnote,theme_more]
CPY [footnotedesc,theme_clean],[footnotedesc,theme_more]
CPY [invert,theme_clean],[invert,theme_more]
CPY [invertdesc,theme_clean],[invertdesc,theme_more]
CPY [logo,theme_clean],[logo,theme_more]
CPY [logodesc,theme_clean],[logodesc,theme_more]
CPY [pluginname,theme_clean],[pluginname,theme_more]
CPY [region-side-post,theme_clean],[region-side-post,theme_more]
CPY [region-side-pre,theme_clean],[region-side-pre,theme_more]
AMOS END
2014-03-17 14:43:23 +08:00
|
|
|
/**
|
|
|
|
* Parses CSS before it is cached.
|
|
|
|
*
|
|
|
|
* This function can make alterations and replace patterns within the CSS.
|
|
|
|
*
|
|
|
|
* @param string $css The CSS
|
|
|
|
* @param theme_config $theme The theme config object.
|
|
|
|
* @return string The parsed CSS The parsed CSS.
|
|
|
|
*/
|
|
|
|
function theme_more_process_css($css, $theme) {
|
2016-08-11 14:22:57 +08:00
|
|
|
global $OUTPUT;
|
MDL-44357 theme_more: New customizable theme
AMOS BEGIN
CPY [choosereadme,theme_clean],[choosereadme,theme_more]
CPY [configtitle,theme_clean],[configtitle,theme_more]
CPY [customcss,theme_clean],[customcss,theme_more]
CPY [customcssdesc,theme_clean],[customcssdesc,theme_more]
CPY [footnote,theme_clean],[footnote,theme_more]
CPY [footnotedesc,theme_clean],[footnotedesc,theme_more]
CPY [invert,theme_clean],[invert,theme_more]
CPY [invertdesc,theme_clean],[invertdesc,theme_more]
CPY [logo,theme_clean],[logo,theme_more]
CPY [logodesc,theme_clean],[logodesc,theme_more]
CPY [pluginname,theme_clean],[pluginname,theme_more]
CPY [region-side-post,theme_clean],[region-side-post,theme_more]
CPY [region-side-pre,theme_clean],[region-side-pre,theme_more]
AMOS END
2014-03-17 14:43:23 +08:00
|
|
|
|
|
|
|
// Set the background image for the logo.
|
2016-08-11 14:22:57 +08:00
|
|
|
$logo = $OUTPUT->get_logo_url(null, 100);
|
MDL-44357 theme_more: New customizable theme
AMOS BEGIN
CPY [choosereadme,theme_clean],[choosereadme,theme_more]
CPY [configtitle,theme_clean],[configtitle,theme_more]
CPY [customcss,theme_clean],[customcss,theme_more]
CPY [customcssdesc,theme_clean],[customcssdesc,theme_more]
CPY [footnote,theme_clean],[footnote,theme_more]
CPY [footnotedesc,theme_clean],[footnotedesc,theme_more]
CPY [invert,theme_clean],[invert,theme_more]
CPY [invertdesc,theme_clean],[invertdesc,theme_more]
CPY [logo,theme_clean],[logo,theme_more]
CPY [logodesc,theme_clean],[logodesc,theme_more]
CPY [pluginname,theme_clean],[pluginname,theme_more]
CPY [region-side-post,theme_clean],[region-side-post,theme_more]
CPY [region-side-pre,theme_clean],[region-side-pre,theme_more]
AMOS END
2014-03-17 14:43:23 +08:00
|
|
|
$css = theme_more_set_logo($css, $logo);
|
|
|
|
|
|
|
|
// Set custom CSS.
|
|
|
|
if (!empty($theme->settings->customcss)) {
|
|
|
|
$customcss = $theme->settings->customcss;
|
|
|
|
} else {
|
|
|
|
$customcss = null;
|
|
|
|
}
|
|
|
|
$css = theme_more_set_customcss($css, $customcss);
|
|
|
|
|
|
|
|
return $css;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the logo to CSS.
|
|
|
|
*
|
|
|
|
* @param string $css The CSS.
|
|
|
|
* @param string $logo The URL of the logo.
|
|
|
|
* @return string The parsed CSS
|
|
|
|
*/
|
|
|
|
function theme_more_set_logo($css, $logo) {
|
|
|
|
$tag = '[[setting:logo]]';
|
|
|
|
$replacement = $logo;
|
|
|
|
if (is_null($replacement)) {
|
|
|
|
$replacement = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$css = str_replace($tag, $replacement, $css);
|
|
|
|
|
|
|
|
return $css;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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_more_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
|
2015-11-11 15:34:19 +08:00
|
|
|
if ($context->contextlevel == CONTEXT_SYSTEM &&
|
|
|
|
($filearea === 'logo' || $filearea === 'smalllogo' || $filearea === 'backgroundimage')) {
|
MDL-44357 theme_more: New customizable theme
AMOS BEGIN
CPY [choosereadme,theme_clean],[choosereadme,theme_more]
CPY [configtitle,theme_clean],[configtitle,theme_more]
CPY [customcss,theme_clean],[customcss,theme_more]
CPY [customcssdesc,theme_clean],[customcssdesc,theme_more]
CPY [footnote,theme_clean],[footnote,theme_more]
CPY [footnotedesc,theme_clean],[footnotedesc,theme_more]
CPY [invert,theme_clean],[invert,theme_more]
CPY [invertdesc,theme_clean],[invertdesc,theme_more]
CPY [logo,theme_clean],[logo,theme_more]
CPY [logodesc,theme_clean],[logodesc,theme_more]
CPY [pluginname,theme_clean],[pluginname,theme_more]
CPY [region-side-post,theme_clean],[region-side-post,theme_more]
CPY [region-side-pre,theme_clean],[region-side-pre,theme_more]
AMOS END
2014-03-17 14:43:23 +08:00
|
|
|
$theme = theme_config::load('more');
|
2014-11-09 08:06:46 +01:00
|
|
|
// By default, theme files must be cache-able by both browsers and proxies.
|
|
|
|
if (!array_key_exists('cacheability', $options)) {
|
|
|
|
$options['cacheability'] = 'public';
|
|
|
|
}
|
2014-03-18 17:59:11 +08:00
|
|
|
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
|
MDL-44357 theme_more: New customizable theme
AMOS BEGIN
CPY [choosereadme,theme_clean],[choosereadme,theme_more]
CPY [configtitle,theme_clean],[configtitle,theme_more]
CPY [customcss,theme_clean],[customcss,theme_more]
CPY [customcssdesc,theme_clean],[customcssdesc,theme_more]
CPY [footnote,theme_clean],[footnote,theme_more]
CPY [footnotedesc,theme_clean],[footnotedesc,theme_more]
CPY [invert,theme_clean],[invert,theme_more]
CPY [invertdesc,theme_clean],[invertdesc,theme_more]
CPY [logo,theme_clean],[logo,theme_more]
CPY [logodesc,theme_clean],[logodesc,theme_more]
CPY [pluginname,theme_clean],[pluginname,theme_more]
CPY [region-side-post,theme_clean],[region-side-post,theme_more]
CPY [region-side-pre,theme_clean],[region-side-pre,theme_more]
AMOS END
2014-03-17 14:43:23 +08:00
|
|
|
} else {
|
|
|
|
send_file_not_found();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds any custom CSS to the CSS before it is cached.
|
|
|
|
*
|
|
|
|
* @param string $css The original CSS.
|
|
|
|
* @param string $customcss The custom CSS to add.
|
|
|
|
* @return string The CSS which now contains our custom CSS.
|
|
|
|
*/
|
|
|
|
function theme_more_set_customcss($css, $customcss) {
|
|
|
|
$tag = '[[setting:customcss]]';
|
|
|
|
$replacement = $customcss;
|
|
|
|
if (is_null($replacement)) {
|
|
|
|
$replacement = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$css = str_replace($tag, $replacement, $css);
|
|
|
|
|
|
|
|
return $css;
|
|
|
|
}
|