2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 require_once($CFG->dirroot
. '/theme/bootstrapbase/renderers.php');
20 * Clean core renderers.
22 * @package theme_clean
23 * @copyright 2015 Frédéric Massart - FMCorz.net
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 class theme_clean_core_renderer
extends theme_bootstrapbase_core_renderer
{
29 * Either returns the parent version of the header bar, or a version with the logo replacing the header.
32 * @param array $headerinfo An array of header information, dependant on what type of header is being displayed. The following
33 * array example is user specific.
34 * heading => Override the page heading.
35 * user => User object.
36 * usercontext => user context.
37 * @param int $headinglevel What level the 'h' tag will be.
38 * @return string HTML for the header bar.
40 public function context_header($headerinfo = null, $headinglevel = 1) {
42 if ($this->should_render_logo($headinglevel)) {
43 return html_writer
::tag('div', '', array('class' => 'logo'));
45 return parent
::context_header($headerinfo, $headinglevel);
49 * Determines if we should render the logo.
51 * @param int $headinglevel What level the 'h' tag will be.
52 * @return bool Should the logo be rendered.
54 protected function should_render_logo($headinglevel = 1) {
57 // Only render the logo if we're on the front page or login page
58 // and the theme has a logo.
59 $logo = $this->get_logo_url();
60 if ($headinglevel == 1 && !empty($logo)) {
61 if ($PAGE->pagelayout
== 'frontpage' ||
$PAGE->pagelayout
== 'login') {
70 * Returns the navigation bar home reference.
72 * The small logo is only rendered on pages where the logo is not displayed.
74 * @param bool $returnlink Whether to wrap the icon and the site name in links or not
75 * @return string The site name, the small logo or both depending on the theme settings.
77 public function navbar_home($returnlink = true) {
80 $imageurl = $this->get_compact_logo_url(null, 35);
81 if ($this->should_render_logo() ||
empty($imageurl)) {
82 // If there is no small logo we always show the site name.
83 return $this->get_home_ref($returnlink);
85 $image = html_writer
::img($imageurl, get_string('sitelogo', 'theme_' . $this->page
->theme
->name
),
86 array('class' => 'small-logo'));
89 $logocontainer = html_writer
::link(new moodle_url('/'), $image,
90 array('class' => 'small-logo-container', 'title' => get_string('home')));
92 $logocontainer = html_writer
::tag('span', $image, array('class' => 'small-logo-container'));
95 // Sitename setting defaults to true.
96 if (!isset($this->page
->theme
->settings
->sitename
) ||
!empty($this->page
->theme
->settings
->sitename
)) {
97 return $logocontainer . $this->get_home_ref($returnlink);
100 return $logocontainer;
104 * Returns a reference to the site home.
106 * It can be either a link or a span.
108 * @param bool $returnlink
111 protected function get_home_ref($returnlink = true) {
114 $sitename = format_string($SITE->shortname
, true, array('context' => context_course
::instance(SITEID
)));
117 return html_writer
::link(new moodle_url('/'), $sitename, array('class' => 'brand', 'title' => get_string('home')));
120 return html_writer
::tag('span', $sitename, array('class' => 'brand'));
124 * Return the theme logo URL, else the site's logo URL, if any.
126 * Note that maximum sizes are not applied to the theme logo.
128 * @param int $maxwidth The maximum width, or null when the maximum width does not matter.
129 * @param int $maxheight The maximum height, or null when the maximum height does not matter.
130 * @return moodle_url|false
132 public function get_logo_url($maxwidth = null, $maxheight = 100) {
135 if (!empty($this->page
->theme
->settings
->logo
)) {
136 $url = $this->page
->theme
->setting_file_url('logo', 'logo');
137 // Get a URL suitable for moodle_url.
138 $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot
);
139 $url = str_replace($relativebaseurl, '', $url);
140 return new moodle_url($url);
142 return parent
::get_logo_url($maxwidth, $maxheight);
146 * Return the theme's compact logo URL, else the site's compact logo URL, if any.
148 * Note that maximum sizes are not applied to the theme logo.
150 * @param int $maxwidth The maximum width, or null when the maximum width does not matter.
151 * @param int $maxheight The maximum height, or null when the maximum height does not matter.
152 * @return moodle_url|false
154 public function get_compact_logo_url($maxwidth = 100, $maxheight = 100) {
157 if (!empty($this->page
->theme
->settings
->smalllogo
)) {
158 $url = $this->page
->theme
->setting_file_url('smalllogo', 'smalllogo');
159 // Get a URL suitable for moodle_url.
160 $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot
);
161 $url = str_replace($relativebaseurl, '', $url);
162 return new moodle_url($url);
164 return parent
::get_compact_logo_url($maxwidth, $maxheight);