moodle/theme/clean/lib.php

113 lines
3.5 KiB
PHP

<?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/>.
/**
* Moodle's Clean theme, an example of how to make a Bootstrap theme
*
* DO NOT MODIFY THIS THEME!
* COPY IT FIRST, THEN RENAME THE COPY AND MODIFY IT INSTEAD.
*
* For full information about creating Moodle themes, see:
* http://docs.moodle.org/dev/Themes_2.0
*
* @package theme_clean
* @copyright 2013 Moodle, moodle.org
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function clean_process_css($css, $theme) {
// Set the background image for the logo.
$logo = $theme->setting_file_url('logo', 'logo');
$css = clean_set_logo($css, $logo);
// Set custom CSS.
if (!empty($theme->settings->customcss)) {
$customcss = $theme->settings->customcss;
} else {
$customcss = null;
}
$css = clean_set_customcss($css, $customcss);
return $css;
}
function clean_set_logo($css, $logo) {
global $OUTPUT;
$tag = '[[setting:logo]]';
$replacement = $logo;
if (is_null($replacement)) {
$replacement = '';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function theme_clean_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'logo') {
$theme = theme_config::load('clean');
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
} else {
send_file_not_found();
}
}
function clean_set_customcss($css, $customcss) {
$tag = '[[setting:customcss]]';
$replacement = $customcss;
if (is_null($replacement)) {
$replacement = '';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
/**
* Returns an object containing HTML for the areas affected by settings.
*
* @param renderer_base $output Pass in $OUTPUT.
* @param moodle_page $page Pass in $PAGE.
* @return stdClass An object with the following properties:
* - navbarclass A CSS class to use on the navbar. By default ''.
* - heading HTML to use for the heading. A logo if one is selected or the default heading.
* - footnote HTML to use as a footnote. By default ''.
*/
function theme_clean_get_html_for_settings(renderer_base $output, moodle_page $page) {
global $CFG;
$return = new stdClass;
$return->navbarclass = '';
if (!empty($page->theme->settings->invert)) {
$return->navbarclass .= ' navbar-inverse';
}
if (!empty($page->theme->settings->logo)) {
$return->heading = html_writer::link($CFG->wwwroot, '', array('title' => get_string('home'), 'class' => 'logo'));
} else {
$return->heading = $output->page_heading();
}
$return->footnote = '';
if (!empty($page->theme->settings->footnote)) {
$return->footnote = '<div class="footnote text-center">'.$page->theme->settings->footnote.'</div>';
}
return $return;
}