Automatically generated installer lang files
[moodle.git] / lib / outputrenderers.php
blob829815e4b97fd77c4b056d239bf0694ce4e101a8
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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 /**
18 * Classes for rendering HTML output for Moodle.
20 * Please see {@link http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML}
21 * for an overview.
23 * Included in this file are the primary renderer classes:
24 * - renderer_base: The renderer outline class that all renderers
25 * should inherit from.
26 * - core_renderer: The standard HTML renderer.
27 * - core_renderer_cli: An adaption of the standard renderer for CLI scripts.
28 * - core_renderer_ajax: An adaption of the standard renderer for AJAX scripts.
29 * - plugin_renderer_base: A renderer class that should be extended by all
30 * plugin renderers.
32 * @package core
33 * @category output
34 * @copyright 2009 Tim Hunt
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 defined('MOODLE_INTERNAL') || die();
40 /**
41 * Simple base class for Moodle renderers.
43 * Tracks the xhtml_container_stack to use, which is passed in in the constructor.
45 * Also has methods to facilitate generating HTML output.
47 * @copyright 2009 Tim Hunt
48 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
49 * @since Moodle 2.0
50 * @package core
51 * @category output
53 class renderer_base {
54 /**
55 * @var xhtml_container_stack The xhtml_container_stack to use.
57 protected $opencontainers;
59 /**
60 * @var moodle_page The Moodle page the renderer has been created to assist with.
62 protected $page;
64 /**
65 * @var string The requested rendering target.
67 protected $target;
69 /**
70 * @var Mustache_Engine $mustache The mustache template compiler
72 private $mustache;
74 /**
75 * Return an instance of the mustache class.
77 * @since 2.9
78 * @return Mustache_Engine
80 protected function get_mustache() {
81 global $CFG;
83 if ($this->mustache === null) {
84 require_once("{$CFG->libdir}/filelib.php");
86 $themename = $this->page->theme->name;
87 $themerev = theme_get_revision();
89 // Create new localcache directory.
90 $cachedir = make_localcache_directory("mustache/$themerev/$themename");
92 // Remove old localcache directories.
93 $mustachecachedirs = glob("{$CFG->localcachedir}/mustache/*", GLOB_ONLYDIR);
94 foreach ($mustachecachedirs as $localcachedir) {
95 $cachedrev = [];
96 preg_match("/\/mustache\/([0-9]+)$/", $localcachedir, $cachedrev);
97 $cachedrev = isset($cachedrev[1]) ? intval($cachedrev[1]) : 0;
98 if ($cachedrev > 0 && $cachedrev < $themerev) {
99 fulldelete($localcachedir);
103 $loader = new \core\output\mustache_filesystem_loader();
104 $stringhelper = new \core\output\mustache_string_helper();
105 $quotehelper = new \core\output\mustache_quote_helper();
106 $jshelper = new \core\output\mustache_javascript_helper($this->page);
107 $pixhelper = new \core\output\mustache_pix_helper($this);
108 $shortentexthelper = new \core\output\mustache_shorten_text_helper();
109 $userdatehelper = new \core\output\mustache_user_date_helper();
111 // We only expose the variables that are exposed to JS templates.
112 $safeconfig = $this->page->requires->get_config_for_javascript($this->page, $this);
114 $helpers = array('config' => $safeconfig,
115 'str' => array($stringhelper, 'str'),
116 'quote' => array($quotehelper, 'quote'),
117 'js' => array($jshelper, 'help'),
118 'pix' => array($pixhelper, 'pix'),
119 'shortentext' => array($shortentexthelper, 'shorten'),
120 'userdate' => array($userdatehelper, 'transform'),
123 $this->mustache = new \core\output\mustache_engine(array(
124 'cache' => $cachedir,
125 'escape' => 's',
126 'loader' => $loader,
127 'helpers' => $helpers,
128 'pragmas' => [Mustache_Engine::PRAGMA_BLOCKS],
129 // Don't allow the JavaScript helper to be executed from within another
130 // helper. If it's allowed it can be used by users to inject malicious
131 // JS into the page.
132 'blacklistednestedhelpers' => ['js']));
136 return $this->mustache;
141 * Constructor
143 * The constructor takes two arguments. The first is the page that the renderer
144 * has been created to assist with, and the second is the target.
145 * The target is an additional identifier that can be used to load different
146 * renderers for different options.
148 * @param moodle_page $page the page we are doing output for.
149 * @param string $target one of rendering target constants
151 public function __construct(moodle_page $page, $target) {
152 $this->opencontainers = $page->opencontainers;
153 $this->page = $page;
154 $this->target = $target;
158 * Renders a template by name with the given context.
160 * The provided data needs to be array/stdClass made up of only simple types.
161 * Simple types are array,stdClass,bool,int,float,string
163 * @since 2.9
164 * @param array|stdClass $context Context containing data for the template.
165 * @return string|boolean
167 public function render_from_template($templatename, $context) {
168 static $templatecache = array();
169 $mustache = $this->get_mustache();
171 try {
172 // Grab a copy of the existing helper to be restored later.
173 $uniqidhelper = $mustache->getHelper('uniqid');
174 } catch (Mustache_Exception_UnknownHelperException $e) {
175 // Helper doesn't exist.
176 $uniqidhelper = null;
179 // Provide 1 random value that will not change within a template
180 // but will be different from template to template. This is useful for
181 // e.g. aria attributes that only work with id attributes and must be
182 // unique in a page.
183 $mustache->addHelper('uniqid', new \core\output\mustache_uniqid_helper());
184 if (isset($templatecache[$templatename])) {
185 $template = $templatecache[$templatename];
186 } else {
187 try {
188 $template = $mustache->loadTemplate($templatename);
189 $templatecache[$templatename] = $template;
190 } catch (Mustache_Exception_UnknownTemplateException $e) {
191 throw new moodle_exception('Unknown template: ' . $templatename);
195 $renderedtemplate = trim($template->render($context));
197 // If we had an existing uniqid helper then we need to restore it to allow
198 // handle nested calls of render_from_template.
199 if ($uniqidhelper) {
200 $mustache->addHelper('uniqid', $uniqidhelper);
203 return $renderedtemplate;
208 * Returns rendered widget.
210 * The provided widget needs to be an object that extends the renderable
211 * interface.
212 * If will then be rendered by a method based upon the classname for the widget.
213 * For instance a widget of class `crazywidget` will be rendered by a protected
214 * render_crazywidget method of this renderer.
215 * If no render_crazywidget method exists and crazywidget implements templatable,
216 * look for the 'crazywidget' template in the same component and render that.
218 * @param renderable $widget instance with renderable interface
219 * @return string
221 public function render(renderable $widget) {
222 $classparts = explode('\\', get_class($widget));
223 // Strip namespaces.
224 $classname = array_pop($classparts);
225 // Remove _renderable suffixes
226 $classname = preg_replace('/_renderable$/', '', $classname);
228 $rendermethod = 'render_'.$classname;
229 if (method_exists($this, $rendermethod)) {
230 return $this->$rendermethod($widget);
232 if ($widget instanceof templatable) {
233 $component = array_shift($classparts);
234 if (!$component) {
235 $component = 'core';
237 $template = $component . '/' . $classname;
238 $context = $widget->export_for_template($this);
239 return $this->render_from_template($template, $context);
241 throw new coding_exception('Can not render widget, renderer method ('.$rendermethod.') not found.');
245 * Adds a JS action for the element with the provided id.
247 * This method adds a JS event for the provided component action to the page
248 * and then returns the id that the event has been attached to.
249 * If no id has been provided then a new ID is generated by {@link html_writer::random_id()}
251 * @param component_action $action
252 * @param string $id
253 * @return string id of element, either original submitted or random new if not supplied
255 public function add_action_handler(component_action $action, $id = null) {
256 if (!$id) {
257 $id = html_writer::random_id($action->event);
259 $this->page->requires->event_handler("#$id", $action->event, $action->jsfunction, $action->jsfunctionargs);
260 return $id;
264 * Returns true is output has already started, and false if not.
266 * @return boolean true if the header has been printed.
268 public function has_started() {
269 return $this->page->state >= moodle_page::STATE_IN_BODY;
273 * Given an array or space-separated list of classes, prepares and returns the HTML class attribute value
275 * @param mixed $classes Space-separated string or array of classes
276 * @return string HTML class attribute value
278 public static function prepare_classes($classes) {
279 if (is_array($classes)) {
280 return implode(' ', array_unique($classes));
282 return $classes;
286 * Return the direct URL for an image from the pix folder.
288 * Use this function sparingly and never for icons. For icons use pix_icon or the pix helper in a mustache template.
290 * @deprecated since Moodle 3.3
291 * @param string $imagename the name of the icon.
292 * @param string $component specification of one plugin like in get_string()
293 * @return moodle_url
295 public function pix_url($imagename, $component = 'moodle') {
296 debugging('pix_url is deprecated. Use image_url for images and pix_icon for icons.', DEBUG_DEVELOPER);
297 return $this->page->theme->image_url($imagename, $component);
301 * Return the moodle_url for an image.
303 * The exact image location and extension is determined
304 * automatically by searching for gif|png|jpg|jpeg, please
305 * note there can not be diferent images with the different
306 * extension. The imagename is for historical reasons
307 * a relative path name, it may be changed later for core
308 * images. It is recommended to not use subdirectories
309 * in plugin and theme pix directories.
311 * There are three types of images:
312 * 1/ theme images - stored in theme/mytheme/pix/,
313 * use component 'theme'
314 * 2/ core images - stored in /pix/,
315 * overridden via theme/mytheme/pix_core/
316 * 3/ plugin images - stored in mod/mymodule/pix,
317 * overridden via theme/mytheme/pix_plugins/mod/mymodule/,
318 * example: image_url('comment', 'mod_glossary')
320 * @param string $imagename the pathname of the image
321 * @param string $component full plugin name (aka component) or 'theme'
322 * @return moodle_url
324 public function image_url($imagename, $component = 'moodle') {
325 return $this->page->theme->image_url($imagename, $component);
329 * Return the site's logo URL, if any.
331 * @param int $maxwidth The maximum width, or null when the maximum width does not matter.
332 * @param int $maxheight The maximum height, or null when the maximum height does not matter.
333 * @return moodle_url|false
335 public function get_logo_url($maxwidth = null, $maxheight = 200) {
336 global $CFG;
337 $logo = get_config('core_admin', 'logo');
338 if (empty($logo)) {
339 return false;
342 // 200px high is the default image size which should be displayed at 100px in the page to account for retina displays.
343 // It's not worth the overhead of detecting and serving 2 different images based on the device.
345 // Hide the requested size in the file path.
346 $filepath = ((int) $maxwidth . 'x' . (int) $maxheight) . '/';
348 // Use $CFG->themerev to prevent browser caching when the file changes.
349 return moodle_url::make_pluginfile_url(context_system::instance()->id, 'core_admin', 'logo', $filepath,
350 theme_get_revision(), $logo);
354 * Return the site's compact logo URL, if any.
356 * @param int $maxwidth The maximum width, or null when the maximum width does not matter.
357 * @param int $maxheight The maximum height, or null when the maximum height does not matter.
358 * @return moodle_url|false
360 public function get_compact_logo_url($maxwidth = 100, $maxheight = 100) {
361 global $CFG;
362 $logo = get_config('core_admin', 'logocompact');
363 if (empty($logo)) {
364 return false;
367 // Hide the requested size in the file path.
368 $filepath = ((int) $maxwidth . 'x' . (int) $maxheight) . '/';
370 // Use $CFG->themerev to prevent browser caching when the file changes.
371 return moodle_url::make_pluginfile_url(context_system::instance()->id, 'core_admin', 'logocompact', $filepath,
372 theme_get_revision(), $logo);
379 * Basis for all plugin renderers.
381 * @copyright Petr Skoda (skodak)
382 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
383 * @since Moodle 2.0
384 * @package core
385 * @category output
387 class plugin_renderer_base extends renderer_base {
390 * @var renderer_base|core_renderer A reference to the current renderer.
391 * The renderer provided here will be determined by the page but will in 90%
392 * of cases by the {@link core_renderer}
394 protected $output;
397 * Constructor method, calls the parent constructor
399 * @param moodle_page $page
400 * @param string $target one of rendering target constants
402 public function __construct(moodle_page $page, $target) {
403 if (empty($target) && $page->pagelayout === 'maintenance') {
404 // If the page is using the maintenance layout then we're going to force the target to maintenance.
405 // This way we'll get a special maintenance renderer that is designed to block access to API's that are likely
406 // unavailable for this page layout.
407 $target = RENDERER_TARGET_MAINTENANCE;
409 $this->output = $page->get_renderer('core', null, $target);
410 parent::__construct($page, $target);
414 * Renders the provided widget and returns the HTML to display it.
416 * @param renderable $widget instance with renderable interface
417 * @return string
419 public function render(renderable $widget) {
420 $classname = get_class($widget);
421 // Strip namespaces.
422 $classname = preg_replace('/^.*\\\/', '', $classname);
423 // Keep a copy at this point, we may need to look for a deprecated method.
424 $deprecatedmethod = 'render_'.$classname;
425 // Remove _renderable suffixes
426 $classname = preg_replace('/_renderable$/', '', $classname);
428 $rendermethod = 'render_'.$classname;
429 if (method_exists($this, $rendermethod)) {
430 return $this->$rendermethod($widget);
432 if ($rendermethod !== $deprecatedmethod && method_exists($this, $deprecatedmethod)) {
433 // This is exactly where we don't want to be.
434 // If you have arrived here you have a renderable component within your plugin that has the name
435 // blah_renderable, and you have a render method render_blah_renderable on your plugin.
436 // In 2.8 we revamped output, as part of this change we changed slightly how renderables got rendered
437 // and the _renderable suffix now gets removed when looking for a render method.
438 // You need to change your renderers render_blah_renderable to render_blah.
439 // Until you do this it will not be possible for a theme to override the renderer to override your method.
440 // Please do it ASAP.
441 static $debugged = array();
442 if (!isset($debugged[$deprecatedmethod])) {
443 debugging(sprintf('Deprecated call. Please rename your renderables render method from %s to %s.',
444 $deprecatedmethod, $rendermethod), DEBUG_DEVELOPER);
445 $debugged[$deprecatedmethod] = true;
447 return $this->$deprecatedmethod($widget);
449 // pass to core renderer if method not found here
450 return $this->output->render($widget);
454 * Magic method used to pass calls otherwise meant for the standard renderer
455 * to it to ensure we don't go causing unnecessary grief.
457 * @param string $method
458 * @param array $arguments
459 * @return mixed
461 public function __call($method, $arguments) {
462 if (method_exists('renderer_base', $method)) {
463 throw new coding_exception('Protected method called against '.get_class($this).' :: '.$method);
465 if (method_exists($this->output, $method)) {
466 return call_user_func_array(array($this->output, $method), $arguments);
467 } else {
468 throw new coding_exception('Unknown method called against '.get_class($this).' :: '.$method);
475 * The standard implementation of the core_renderer interface.
477 * @copyright 2009 Tim Hunt
478 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
479 * @since Moodle 2.0
480 * @package core
481 * @category output
483 class core_renderer extends renderer_base {
485 * Do NOT use, please use <?php echo $OUTPUT->main_content() ?>
486 * in layout files instead.
487 * @deprecated
488 * @var string used in {@link core_renderer::header()}.
490 const MAIN_CONTENT_TOKEN = '[MAIN CONTENT GOES HERE]';
493 * @var string Used to pass information from {@link core_renderer::doctype()} to
494 * {@link core_renderer::standard_head_html()}.
496 protected $contenttype;
499 * @var string Used by {@link core_renderer::redirect_message()} method to communicate
500 * with {@link core_renderer::header()}.
502 protected $metarefreshtag = '';
505 * @var string Unique token for the closing HTML
507 protected $unique_end_html_token;
510 * @var string Unique token for performance information
512 protected $unique_performance_info_token;
515 * @var string Unique token for the main content.
517 protected $unique_main_content_token;
520 * Constructor
522 * @param moodle_page $page the page we are doing output for.
523 * @param string $target one of rendering target constants
525 public function __construct(moodle_page $page, $target) {
526 $this->opencontainers = $page->opencontainers;
527 $this->page = $page;
528 $this->target = $target;
530 $this->unique_end_html_token = '%%ENDHTML-'.sesskey().'%%';
531 $this->unique_performance_info_token = '%%PERFORMANCEINFO-'.sesskey().'%%';
532 $this->unique_main_content_token = '[MAIN CONTENT GOES HERE - '.sesskey().']';
536 * Get the DOCTYPE declaration that should be used with this page. Designed to
537 * be called in theme layout.php files.
539 * @return string the DOCTYPE declaration that should be used.
541 public function doctype() {
542 if ($this->page->theme->doctype === 'html5') {
543 $this->contenttype = 'text/html; charset=utf-8';
544 return "<!DOCTYPE html>\n";
546 } else if ($this->page->theme->doctype === 'xhtml5') {
547 $this->contenttype = 'application/xhtml+xml; charset=utf-8';
548 return "<!DOCTYPE html>\n";
550 } else {
551 // legacy xhtml 1.0
552 $this->contenttype = 'text/html; charset=utf-8';
553 return ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n");
558 * The attributes that should be added to the <html> tag. Designed to
559 * be called in theme layout.php files.
561 * @return string HTML fragment.
563 public function htmlattributes() {
564 $return = get_html_lang(true);
565 $attributes = array();
566 if ($this->page->theme->doctype !== 'html5') {
567 $attributes['xmlns'] = 'http://www.w3.org/1999/xhtml';
570 // Give plugins an opportunity to add things like xml namespaces to the html element.
571 // This function should return an array of html attribute names => values.
572 $pluginswithfunction = get_plugins_with_function('add_htmlattributes', 'lib.php');
573 foreach ($pluginswithfunction as $plugins) {
574 foreach ($plugins as $function) {
575 $newattrs = $function();
576 unset($newattrs['dir']);
577 unset($newattrs['lang']);
578 unset($newattrs['xmlns']);
579 unset($newattrs['xml:lang']);
580 $attributes += $newattrs;
584 foreach ($attributes as $key => $val) {
585 $val = s($val);
586 $return .= " $key=\"$val\"";
589 return $return;
593 * The standard tags (meta tags, links to stylesheets and JavaScript, etc.)
594 * that should be included in the <head> tag. Designed to be called in theme
595 * layout.php files.
597 * @return string HTML fragment.
599 public function standard_head_html() {
600 global $CFG, $SESSION;
602 // Before we output any content, we need to ensure that certain
603 // page components are set up.
605 // Blocks must be set up early as they may require javascript which
606 // has to be included in the page header before output is created.
607 foreach ($this->page->blocks->get_regions() as $region) {
608 $this->page->blocks->ensure_content_created($region, $this);
611 $output = '';
613 // Give plugins an opportunity to add any head elements. The callback
614 // must always return a string containing valid html head content.
615 $pluginswithfunction = get_plugins_with_function('before_standard_html_head', 'lib.php');
616 foreach ($pluginswithfunction as $plugins) {
617 foreach ($plugins as $function) {
618 $output .= $function();
622 // Allow a url_rewrite plugin to setup any dynamic head content.
623 if (isset($CFG->urlrewriteclass) && !isset($CFG->upgraderunning)) {
624 $class = $CFG->urlrewriteclass;
625 $output .= $class::html_head_setup();
628 $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n";
629 $output .= '<meta name="keywords" content="moodle, ' . $this->page->title . '" />' . "\n";
630 // This is only set by the {@link redirect()} method
631 $output .= $this->metarefreshtag;
633 // Check if a periodic refresh delay has been set and make sure we arn't
634 // already meta refreshing
635 if ($this->metarefreshtag=='' && $this->page->periodicrefreshdelay!==null) {
636 $output .= '<meta http-equiv="refresh" content="'.$this->page->periodicrefreshdelay.';url='.$this->page->url->out().'" />';
639 // Set up help link popups for all links with the helptooltip class
640 $this->page->requires->js_init_call('M.util.help_popups.setup');
642 $focus = $this->page->focuscontrol;
643 if (!empty($focus)) {
644 if (preg_match("#forms\['([a-zA-Z0-9]+)'\].elements\['([a-zA-Z0-9]+)'\]#", $focus, $matches)) {
645 // This is a horrifically bad way to handle focus but it is passed in
646 // through messy formslib::moodleform
647 $this->page->requires->js_function_call('old_onload_focus', array($matches[1], $matches[2]));
648 } else if (strpos($focus, '.')!==false) {
649 // Old style of focus, bad way to do it
650 debugging('This code is using the old style focus event, Please update this code to focus on an element id or the moodleform focus method.', DEBUG_DEVELOPER);
651 $this->page->requires->js_function_call('old_onload_focus', explode('.', $focus, 2));
652 } else {
653 // Focus element with given id
654 $this->page->requires->js_function_call('focuscontrol', array($focus));
658 // Get the theme stylesheet - this has to be always first CSS, this loads also styles.css from all plugins;
659 // any other custom CSS can not be overridden via themes and is highly discouraged
660 $urls = $this->page->theme->css_urls($this->page);
661 foreach ($urls as $url) {
662 $this->page->requires->css_theme($url);
665 // Get the theme javascript head and footer
666 if ($jsurl = $this->page->theme->javascript_url(true)) {
667 $this->page->requires->js($jsurl, true);
669 if ($jsurl = $this->page->theme->javascript_url(false)) {
670 $this->page->requires->js($jsurl);
673 // Get any HTML from the page_requirements_manager.
674 $output .= $this->page->requires->get_head_code($this->page, $this);
676 // List alternate versions.
677 foreach ($this->page->alternateversions as $type => $alt) {
678 $output .= html_writer::empty_tag('link', array('rel' => 'alternate',
679 'type' => $type, 'title' => $alt->title, 'href' => $alt->url));
682 // Add noindex tag if relevant page and setting applied.
683 $allowindexing = isset($CFG->allowindexing) ? $CFG->allowindexing : 0;
684 $loginpages = array('login-index', 'login-signup');
685 if ($allowindexing == 2 || ($allowindexing == 0 && in_array($this->page->pagetype, $loginpages))) {
686 if (!isset($CFG->additionalhtmlhead)) {
687 $CFG->additionalhtmlhead = '';
689 $CFG->additionalhtmlhead .= '<meta name="robots" content="noindex" />';
692 if (!empty($CFG->additionalhtmlhead)) {
693 $output .= "\n".$CFG->additionalhtmlhead;
696 return $output;
700 * The standard tags (typically skip links) that should be output just inside
701 * the start of the <body> tag. Designed to be called in theme layout.php files.
703 * @return string HTML fragment.
705 public function standard_top_of_body_html() {
706 global $CFG;
707 $output = $this->page->requires->get_top_of_body_code($this);
708 if ($this->page->pagelayout !== 'embedded' && !empty($CFG->additionalhtmltopofbody)) {
709 $output .= "\n".$CFG->additionalhtmltopofbody;
712 // Give plugins an opportunity to inject extra html content. The callback
713 // must always return a string containing valid html.
714 $pluginswithfunction = get_plugins_with_function('before_standard_top_of_body_html', 'lib.php');
715 foreach ($pluginswithfunction as $plugins) {
716 foreach ($plugins as $function) {
717 $output .= $function();
721 $output .= $this->maintenance_warning();
723 return $output;
727 * Scheduled maintenance warning message.
729 * Note: This is a nasty hack to display maintenance notice, this should be moved
730 * to some general notification area once we have it.
732 * @return string
734 public function maintenance_warning() {
735 global $CFG;
737 $output = '';
738 if (isset($CFG->maintenance_later) and $CFG->maintenance_later > time()) {
739 $timeleft = $CFG->maintenance_later - time();
740 // If timeleft less than 30 sec, set the class on block to error to highlight.
741 $errorclass = ($timeleft < 30) ? 'alert-error alert-danger' : 'alert-warning';
742 $output .= $this->box_start($errorclass . ' moodle-has-zindex maintenancewarning m-a-1 alert');
743 $a = new stdClass();
744 $a->hour = (int)($timeleft / 3600);
745 $a->min = (int)(($timeleft / 60) % 60);
746 $a->sec = (int)($timeleft % 60);
747 if ($a->hour > 0) {
748 $output .= get_string('maintenancemodeisscheduledlong', 'admin', $a);
749 } else {
750 $output .= get_string('maintenancemodeisscheduled', 'admin', $a);
753 $output .= $this->box_end();
754 $this->page->requires->yui_module('moodle-core-maintenancemodetimer', 'M.core.maintenancemodetimer',
755 array(array('timeleftinsec' => $timeleft)));
756 $this->page->requires->strings_for_js(
757 array('maintenancemodeisscheduled', 'maintenancemodeisscheduledlong', 'sitemaintenance'),
758 'admin');
760 return $output;
764 * The standard tags (typically performance information and validation links,
765 * if we are in developer debug mode) that should be output in the footer area
766 * of the page. Designed to be called in theme layout.php files.
768 * @return string HTML fragment.
770 public function standard_footer_html() {
771 global $CFG, $SCRIPT;
773 $output = '';
774 if (during_initial_install()) {
775 // Debugging info can not work before install is finished,
776 // in any case we do not want any links during installation!
777 return $output;
780 // Give plugins an opportunity to add any footer elements.
781 // The callback must always return a string containing valid html footer content.
782 $pluginswithfunction = get_plugins_with_function('standard_footer_html', 'lib.php');
783 foreach ($pluginswithfunction as $plugins) {
784 foreach ($plugins as $function) {
785 $output .= $function();
789 // This function is normally called from a layout.php file in {@link core_renderer::header()}
790 // but some of the content won't be known until later, so we return a placeholder
791 // for now. This will be replaced with the real content in {@link core_renderer::footer()}.
792 $output .= $this->unique_performance_info_token;
793 if ($this->page->devicetypeinuse == 'legacy') {
794 // The legacy theme is in use print the notification
795 $output .= html_writer::tag('div', get_string('legacythemeinuse'), array('class'=>'legacythemeinuse'));
798 // Get links to switch device types (only shown for users not on a default device)
799 $output .= $this->theme_switch_links();
801 if (!empty($CFG->debugpageinfo)) {
802 $output .= '<div class="performanceinfo pageinfo">' . get_string('pageinfodebugsummary', 'core_admin',
803 $this->page->debug_summary()) . '</div>';
805 if (debugging(null, DEBUG_DEVELOPER) and has_capability('moodle/site:config', context_system::instance())) { // Only in developer mode
806 // Add link to profiling report if necessary
807 if (function_exists('profiling_is_running') && profiling_is_running()) {
808 $txt = get_string('profiledscript', 'admin');
809 $title = get_string('profiledscriptview', 'admin');
810 $url = $CFG->wwwroot . '/admin/tool/profiling/index.php?script=' . urlencode($SCRIPT);
811 $link= '<a title="' . $title . '" href="' . $url . '">' . $txt . '</a>';
812 $output .= '<div class="profilingfooter">' . $link . '</div>';
814 $purgeurl = new moodle_url('/admin/purgecaches.php', array('confirm' => 1,
815 'sesskey' => sesskey(), 'returnurl' => $this->page->url->out_as_local_url(false)));
816 $output .= '<div class="purgecaches">' .
817 html_writer::link($purgeurl, get_string('purgecaches', 'admin')) . '</div>';
819 if (!empty($CFG->debugvalidators)) {
820 // NOTE: this is not a nice hack, $PAGE->url is not always accurate and $FULLME neither, it is not a bug if it fails. --skodak
821 $output .= '<div class="validators"><ul class="list-unstyled m-l-1">
822 <li><a href="http://validator.w3.org/check?verbose=1&amp;ss=1&amp;uri=' . urlencode(qualified_me()) . '">Validate HTML</a></li>
823 <li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=-1&amp;url1=' . urlencode(qualified_me()) . '">Section 508 Check</a></li>
824 <li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=0&amp;warnp2n3e=1&amp;url1=' . urlencode(qualified_me()) . '">WCAG 1 (2,3) Check</a></li>
825 </ul></div>';
827 return $output;
831 * Returns standard main content placeholder.
832 * Designed to be called in theme layout.php files.
834 * @return string HTML fragment.
836 public function main_content() {
837 // This is here because it is the only place we can inject the "main" role over the entire main content area
838 // without requiring all theme's to manually do it, and without creating yet another thing people need to
839 // remember in the theme.
840 // This is an unfortunate hack. DO NO EVER add anything more here.
841 // DO NOT add classes.
842 // DO NOT add an id.
843 return '<div role="main">'.$this->unique_main_content_token.'</div>';
847 * Returns standard navigation between activities in a course.
849 * @return string the navigation HTML.
851 public function activity_navigation() {
852 // First we should check if we want to add navigation.
853 $context = $this->page->context;
854 if (($this->page->pagelayout !== 'incourse' && $this->page->pagelayout !== 'frametop')
855 || $context->contextlevel != CONTEXT_MODULE) {
856 return '';
859 // If the activity is in stealth mode, show no links.
860 if ($this->page->cm->is_stealth()) {
861 return '';
864 // Get a list of all the activities in the course.
865 $course = $this->page->cm->get_course();
866 $modules = get_fast_modinfo($course->id)->get_cms();
868 // Put the modules into an array in order by the position they are shown in the course.
869 $mods = [];
870 $activitylist = [];
871 foreach ($modules as $module) {
872 // Only add activities the user can access, aren't in stealth mode and have a url (eg. mod_label does not).
873 if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
874 continue;
876 $mods[$module->id] = $module;
878 // No need to add the current module to the list for the activity dropdown menu.
879 if ($module->id == $this->page->cm->id) {
880 continue;
882 // Module name.
883 $modname = $module->get_formatted_name();
884 // Display the hidden text if necessary.
885 if (!$module->visible) {
886 $modname .= ' ' . get_string('hiddenwithbrackets');
888 // Module URL.
889 $linkurl = new moodle_url($module->url, array('forceview' => 1));
890 // Add module URL (as key) and name (as value) to the activity list array.
891 $activitylist[$linkurl->out(false)] = $modname;
894 $nummods = count($mods);
896 // If there is only one mod then do nothing.
897 if ($nummods == 1) {
898 return '';
901 // Get an array of just the course module ids used to get the cmid value based on their position in the course.
902 $modids = array_keys($mods);
904 // Get the position in the array of the course module we are viewing.
905 $position = array_search($this->page->cm->id, $modids);
907 $prevmod = null;
908 $nextmod = null;
910 // Check if we have a previous mod to show.
911 if ($position > 0) {
912 $prevmod = $mods[$modids[$position - 1]];
915 // Check if we have a next mod to show.
916 if ($position < ($nummods - 1)) {
917 $nextmod = $mods[$modids[$position + 1]];
920 $activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod, $activitylist);
921 $renderer = $this->page->get_renderer('core', 'course');
922 return $renderer->render($activitynav);
926 * The standard tags (typically script tags that are not needed earlier) that
927 * should be output after everything else. Designed to be called in theme layout.php files.
929 * @return string HTML fragment.
931 public function standard_end_of_body_html() {
932 global $CFG;
934 // This function is normally called from a layout.php file in {@link core_renderer::header()}
935 // but some of the content won't be known until later, so we return a placeholder
936 // for now. This will be replaced with the real content in {@link core_renderer::footer()}.
937 $output = '';
938 if ($this->page->pagelayout !== 'embedded' && !empty($CFG->additionalhtmlfooter)) {
939 $output .= "\n".$CFG->additionalhtmlfooter;
941 $output .= $this->unique_end_html_token;
942 return $output;
946 * Return the standard string that says whether you are logged in (and switched
947 * roles/logged in as another user).
948 * @param bool $withlinks if false, then don't include any links in the HTML produced.
949 * If not set, the default is the nologinlinks option from the theme config.php file,
950 * and if that is not set, then links are included.
951 * @return string HTML fragment.
953 public function login_info($withlinks = null) {
954 global $USER, $CFG, $DB, $SESSION;
956 if (during_initial_install()) {
957 return '';
960 if (is_null($withlinks)) {
961 $withlinks = empty($this->page->layout_options['nologinlinks']);
964 $course = $this->page->course;
965 if (\core\session\manager::is_loggedinas()) {
966 $realuser = \core\session\manager::get_realuser();
967 $fullname = fullname($realuser, true);
968 if ($withlinks) {
969 $loginastitle = get_string('loginas');
970 $realuserinfo = " [<a href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;sesskey=".sesskey()."\"";
971 $realuserinfo .= "title =\"".$loginastitle."\">$fullname</a>] ";
972 } else {
973 $realuserinfo = " [$fullname] ";
975 } else {
976 $realuserinfo = '';
979 $loginpage = $this->is_login_page();
980 $loginurl = get_login_url();
982 if (empty($course->id)) {
983 // $course->id is not defined during installation
984 return '';
985 } else if (isloggedin()) {
986 $context = context_course::instance($course->id);
988 $fullname = fullname($USER, true);
989 // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
990 if ($withlinks) {
991 $linktitle = get_string('viewprofile');
992 $username = "<a href=\"$CFG->wwwroot/user/profile.php?id=$USER->id\" title=\"$linktitle\">$fullname</a>";
993 } else {
994 $username = $fullname;
996 if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
997 if ($withlinks) {
998 $username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
999 } else {
1000 $username .= " from {$idprovider->name}";
1003 if (isguestuser()) {
1004 $loggedinas = $realuserinfo.get_string('loggedinasguest');
1005 if (!$loginpage && $withlinks) {
1006 $loggedinas .= " (<a href=\"$loginurl\">".get_string('login').'</a>)';
1008 } else if (is_role_switched($course->id)) { // Has switched roles
1009 $rolename = '';
1010 if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) {
1011 $rolename = ': '.role_get_name($role, $context);
1013 $loggedinas = get_string('loggedinas', 'moodle', $username).$rolename;
1014 if ($withlinks) {
1015 $url = new moodle_url('/course/switchrole.php', array('id'=>$course->id,'sesskey'=>sesskey(), 'switchrole'=>0, 'returnurl'=>$this->page->url->out_as_local_url(false)));
1016 $loggedinas .= ' ('.html_writer::tag('a', get_string('switchrolereturn'), array('href' => $url)).')';
1018 } else {
1019 $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username);
1020 if ($withlinks) {
1021 $loggedinas .= " (<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
1024 } else {
1025 $loggedinas = get_string('loggedinnot', 'moodle');
1026 if (!$loginpage && $withlinks) {
1027 $loggedinas .= " (<a href=\"$loginurl\">".get_string('login').'</a>)';
1031 $loggedinas = '<div class="logininfo">'.$loggedinas.'</div>';
1033 if (isset($SESSION->justloggedin)) {
1034 unset($SESSION->justloggedin);
1035 if (!empty($CFG->displayloginfailures)) {
1036 if (!isguestuser()) {
1037 // Include this file only when required.
1038 require_once($CFG->dirroot . '/user/lib.php');
1039 if ($count = user_count_login_failures($USER)) {
1040 $loggedinas .= '<div class="loginfailures">';
1041 $a = new stdClass();
1042 $a->attempts = $count;
1043 $loggedinas .= get_string('failedloginattempts', '', $a);
1044 if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
1045 $loggedinas .= ' ('.html_writer::link(new moodle_url('/report/log/index.php', array('chooselog' => 1,
1046 'id' => 0 , 'modid' => 'site_errors')), get_string('logs')).')';
1048 $loggedinas .= '</div>';
1054 return $loggedinas;
1058 * Check whether the current page is a login page.
1060 * @since Moodle 2.9
1061 * @return bool
1063 protected function is_login_page() {
1064 // This is a real bit of a hack, but its a rarety that we need to do something like this.
1065 // In fact the login pages should be only these two pages and as exposing this as an option for all pages
1066 // could lead to abuse (or at least unneedingly complex code) the hack is the way to go.
1067 return in_array(
1068 $this->page->url->out_as_local_url(false, array()),
1069 array(
1070 '/login/index.php',
1071 '/login/forgot_password.php',
1077 * Return the 'back' link that normally appears in the footer.
1079 * @return string HTML fragment.
1081 public function home_link() {
1082 global $CFG, $SITE;
1084 if ($this->page->pagetype == 'site-index') {
1085 // Special case for site home page - please do not remove
1086 return '<div class="sitelink">' .
1087 '<a title="Moodle" href="http://moodle.org/">' .
1088 '<img src="' . $this->image_url('moodlelogo') . '" alt="'.get_string('moodlelogo').'" /></a></div>';
1090 } else if (!empty($CFG->target_release) && $CFG->target_release != $CFG->release) {
1091 // Special case for during install/upgrade.
1092 return '<div class="sitelink">'.
1093 '<a title="Moodle" href="http://docs.moodle.org/en/Administrator_documentation" onclick="this.target=\'_blank\'">' .
1094 '<img src="' . $this->image_url('moodlelogo') . '" alt="'.get_string('moodlelogo').'" /></a></div>';
1096 } else if ($this->page->course->id == $SITE->id || strpos($this->page->pagetype, 'course-view') === 0) {
1097 return '<div class="homelink"><a href="' . $CFG->wwwroot . '/">' .
1098 get_string('home') . '</a></div>';
1100 } else {
1101 return '<div class="homelink"><a href="' . $CFG->wwwroot . '/course/view.php?id=' . $this->page->course->id . '">' .
1102 format_string($this->page->course->shortname, true, array('context' => $this->page->context)) . '</a></div>';
1107 * Redirects the user by any means possible given the current state
1109 * This function should not be called directly, it should always be called using
1110 * the redirect function in lib/weblib.php
1112 * The redirect function should really only be called before page output has started
1113 * however it will allow itself to be called during the state STATE_IN_BODY
1115 * @param string $encodedurl The URL to send to encoded if required
1116 * @param string $message The message to display to the user if any
1117 * @param int $delay The delay before redirecting a user, if $message has been
1118 * set this is a requirement and defaults to 3, set to 0 no delay
1119 * @param boolean $debugdisableredirect this redirect has been disabled for
1120 * debugging purposes. Display a message that explains, and don't
1121 * trigger the redirect.
1122 * @param string $messagetype The type of notification to show the message in.
1123 * See constants on \core\output\notification.
1124 * @return string The HTML to display to the user before dying, may contain
1125 * meta refresh, javascript refresh, and may have set header redirects
1127 public function redirect_message($encodedurl, $message, $delay, $debugdisableredirect,
1128 $messagetype = \core\output\notification::NOTIFY_INFO) {
1129 global $CFG;
1130 $url = str_replace('&amp;', '&', $encodedurl);
1132 switch ($this->page->state) {
1133 case moodle_page::STATE_BEFORE_HEADER :
1134 // No output yet it is safe to delivery the full arsenal of redirect methods
1135 if (!$debugdisableredirect) {
1136 // Don't use exactly the same time here, it can cause problems when both redirects fire at the same time.
1137 $this->metarefreshtag = '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />'."\n";
1138 $this->page->requires->js_function_call('document.location.replace', array($url), false, ($delay + 3));
1140 $output = $this->header();
1141 break;
1142 case moodle_page::STATE_PRINTING_HEADER :
1143 // We should hopefully never get here
1144 throw new coding_exception('You cannot redirect while printing the page header');
1145 break;
1146 case moodle_page::STATE_IN_BODY :
1147 // We really shouldn't be here but we can deal with this
1148 debugging("You should really redirect before you start page output");
1149 if (!$debugdisableredirect) {
1150 $this->page->requires->js_function_call('document.location.replace', array($url), false, $delay);
1152 $output = $this->opencontainers->pop_all_but_last();
1153 break;
1154 case moodle_page::STATE_DONE :
1155 // Too late to be calling redirect now
1156 throw new coding_exception('You cannot redirect after the entire page has been generated');
1157 break;
1159 $output .= $this->notification($message, $messagetype);
1160 $output .= '<div class="continuebutton">(<a href="'. $encodedurl .'">'. get_string('continue') .'</a>)</div>';
1161 if ($debugdisableredirect) {
1162 $output .= '<p><strong>'.get_string('erroroutput', 'error').'</strong></p>';
1164 $output .= $this->footer();
1165 return $output;
1169 * Start output by sending the HTTP headers, and printing the HTML <head>
1170 * and the start of the <body>.
1172 * To control what is printed, you should set properties on $PAGE. If you
1173 * are familiar with the old {@link print_header()} function from Moodle 1.9
1174 * you will find that there are properties on $PAGE that correspond to most
1175 * of the old parameters to could be passed to print_header.
1177 * Not that, in due course, the remaining $navigation, $menu parameters here
1178 * will be replaced by more properties of $PAGE, but that is still to do.
1180 * @return string HTML that you must output this, preferably immediately.
1182 public function header() {
1183 global $USER, $CFG, $SESSION;
1185 // Give plugins an opportunity touch things before the http headers are sent
1186 // such as adding additional headers. The return value is ignored.
1187 $pluginswithfunction = get_plugins_with_function('before_http_headers', 'lib.php');
1188 foreach ($pluginswithfunction as $plugins) {
1189 foreach ($plugins as $function) {
1190 $function();
1194 if (\core\session\manager::is_loggedinas()) {
1195 $this->page->add_body_class('userloggedinas');
1198 if (isset($SESSION->justloggedin) && !empty($CFG->displayloginfailures)) {
1199 require_once($CFG->dirroot . '/user/lib.php');
1200 // Set second parameter to false as we do not want reset the counter, the same message appears on footer.
1201 if ($count = user_count_login_failures($USER, false)) {
1202 $this->page->add_body_class('loginfailures');
1206 // If the user is logged in, and we're not in initial install,
1207 // check to see if the user is role-switched and add the appropriate
1208 // CSS class to the body element.
1209 if (!during_initial_install() && isloggedin() && is_role_switched($this->page->course->id)) {
1210 $this->page->add_body_class('userswitchedrole');
1213 // Give themes a chance to init/alter the page object.
1214 $this->page->theme->init_page($this->page);
1216 $this->page->set_state(moodle_page::STATE_PRINTING_HEADER);
1218 // Find the appropriate page layout file, based on $this->page->pagelayout.
1219 $layoutfile = $this->page->theme->layout_file($this->page->pagelayout);
1220 // Render the layout using the layout file.
1221 $rendered = $this->render_page_layout($layoutfile);
1223 // Slice the rendered output into header and footer.
1224 $cutpos = strpos($rendered, $this->unique_main_content_token);
1225 if ($cutpos === false) {
1226 $cutpos = strpos($rendered, self::MAIN_CONTENT_TOKEN);
1227 $token = self::MAIN_CONTENT_TOKEN;
1228 } else {
1229 $token = $this->unique_main_content_token;
1232 if ($cutpos === false) {
1233 throw new coding_exception('page layout file ' . $layoutfile . ' does not contain the main content placeholder, please include "<?php echo $OUTPUT->main_content() ?>" in theme layout file.');
1235 $header = substr($rendered, 0, $cutpos);
1236 $footer = substr($rendered, $cutpos + strlen($token));
1238 if (empty($this->contenttype)) {
1239 debugging('The page layout file did not call $OUTPUT->doctype()');
1240 $header = $this->doctype() . $header;
1243 // If this theme version is below 2.4 release and this is a course view page
1244 if ((!isset($this->page->theme->settings->version) || $this->page->theme->settings->version < 2012101500) &&
1245 $this->page->pagelayout === 'course' && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
1246 // check if course content header/footer have not been output during render of theme layout
1247 $coursecontentheader = $this->course_content_header(true);
1248 $coursecontentfooter = $this->course_content_footer(true);
1249 if (!empty($coursecontentheader)) {
1250 // display debug message and add header and footer right above and below main content
1251 // Please note that course header and footer (to be displayed above and below the whole page)
1252 // are not displayed in this case at all.
1253 // Besides the content header and footer are not displayed on any other course page
1254 debugging('The current theme is not optimised for 2.4, the course-specific header and footer defined in course format will not be output', DEBUG_DEVELOPER);
1255 $header .= $coursecontentheader;
1256 $footer = $coursecontentfooter. $footer;
1260 send_headers($this->contenttype, $this->page->cacheable);
1262 $this->opencontainers->push('header/footer', $footer);
1263 $this->page->set_state(moodle_page::STATE_IN_BODY);
1265 return $header . $this->skip_link_target('maincontent');
1269 * Renders and outputs the page layout file.
1271 * This is done by preparing the normal globals available to a script, and
1272 * then including the layout file provided by the current theme for the
1273 * requested layout.
1275 * @param string $layoutfile The name of the layout file
1276 * @return string HTML code
1278 protected function render_page_layout($layoutfile) {
1279 global $CFG, $SITE, $USER;
1280 // The next lines are a bit tricky. The point is, here we are in a method
1281 // of a renderer class, and this object may, or may not, be the same as
1282 // the global $OUTPUT object. When rendering the page layout file, we want to use
1283 // this object. However, people writing Moodle code expect the current
1284 // renderer to be called $OUTPUT, not $this, so define a variable called
1285 // $OUTPUT pointing at $this. The same comment applies to $PAGE and $COURSE.
1286 $OUTPUT = $this;
1287 $PAGE = $this->page;
1288 $COURSE = $this->page->course;
1290 ob_start();
1291 include($layoutfile);
1292 $rendered = ob_get_contents();
1293 ob_end_clean();
1294 return $rendered;
1298 * Outputs the page's footer
1300 * @return string HTML fragment
1302 public function footer() {
1303 global $CFG, $DB, $PAGE;
1305 // Give plugins an opportunity to touch the page before JS is finalized.
1306 $pluginswithfunction = get_plugins_with_function('before_footer', 'lib.php');
1307 foreach ($pluginswithfunction as $plugins) {
1308 foreach ($plugins as $function) {
1309 $function();
1313 $output = $this->container_end_all(true);
1315 $footer = $this->opencontainers->pop('header/footer');
1317 if (debugging() and $DB and $DB->is_transaction_started()) {
1318 // TODO: MDL-20625 print warning - transaction will be rolled back
1321 // Provide some performance info if required
1322 $performanceinfo = '';
1323 if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
1324 $perf = get_performance_info();
1325 if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) {
1326 $performanceinfo = $perf['html'];
1330 // We always want performance data when running a performance test, even if the user is redirected to another page.
1331 if (MDL_PERF_TEST && strpos($footer, $this->unique_performance_info_token) === false) {
1332 $footer = $this->unique_performance_info_token . $footer;
1334 $footer = str_replace($this->unique_performance_info_token, $performanceinfo, $footer);
1336 // Only show notifications when we have a $PAGE context id.
1337 if (!empty($PAGE->context->id)) {
1338 $this->page->requires->js_call_amd('core/notification', 'init', array(
1339 $PAGE->context->id,
1340 \core\notification::fetch_as_array($this)
1343 $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer);
1345 $this->page->set_state(moodle_page::STATE_DONE);
1347 return $output . $footer;
1351 * Close all but the last open container. This is useful in places like error
1352 * handling, where you want to close all the open containers (apart from <body>)
1353 * before outputting the error message.
1355 * @param bool $shouldbenone assert that the stack should be empty now - causes a
1356 * developer debug warning if it isn't.
1357 * @return string the HTML required to close any open containers inside <body>.
1359 public function container_end_all($shouldbenone = false) {
1360 return $this->opencontainers->pop_all_but_last($shouldbenone);
1364 * Returns course-specific information to be output immediately above content on any course page
1365 * (for the current course)
1367 * @param bool $onlyifnotcalledbefore output content only if it has not been output before
1368 * @return string
1370 public function course_content_header($onlyifnotcalledbefore = false) {
1371 global $CFG;
1372 static $functioncalled = false;
1373 if ($functioncalled && $onlyifnotcalledbefore) {
1374 // we have already output the content header
1375 return '';
1378 // Output any session notification.
1379 $notifications = \core\notification::fetch();
1381 $bodynotifications = '';
1382 foreach ($notifications as $notification) {
1383 $bodynotifications .= $this->render_from_template(
1384 $notification->get_template_name(),
1385 $notification->export_for_template($this)
1389 $output = html_writer::span($bodynotifications, 'notifications', array('id' => 'user-notifications'));
1391 if ($this->page->course->id == SITEID) {
1392 // return immediately and do not include /course/lib.php if not necessary
1393 return $output;
1396 require_once($CFG->dirroot.'/course/lib.php');
1397 $functioncalled = true;
1398 $courseformat = course_get_format($this->page->course);
1399 if (($obj = $courseformat->course_content_header()) !== null) {
1400 $output .= html_writer::div($courseformat->get_renderer($this->page)->render($obj), 'course-content-header');
1402 return $output;
1406 * Returns course-specific information to be output immediately below content on any course page
1407 * (for the current course)
1409 * @param bool $onlyifnotcalledbefore output content only if it has not been output before
1410 * @return string
1412 public function course_content_footer($onlyifnotcalledbefore = false) {
1413 global $CFG;
1414 if ($this->page->course->id == SITEID) {
1415 // return immediately and do not include /course/lib.php if not necessary
1416 return '';
1418 static $functioncalled = false;
1419 if ($functioncalled && $onlyifnotcalledbefore) {
1420 // we have already output the content footer
1421 return '';
1423 $functioncalled = true;
1424 require_once($CFG->dirroot.'/course/lib.php');
1425 $courseformat = course_get_format($this->page->course);
1426 if (($obj = $courseformat->course_content_footer()) !== null) {
1427 return html_writer::div($courseformat->get_renderer($this->page)->render($obj), 'course-content-footer');
1429 return '';
1433 * Returns course-specific information to be output on any course page in the header area
1434 * (for the current course)
1436 * @return string
1438 public function course_header() {
1439 global $CFG;
1440 if ($this->page->course->id == SITEID) {
1441 // return immediately and do not include /course/lib.php if not necessary
1442 return '';
1444 require_once($CFG->dirroot.'/course/lib.php');
1445 $courseformat = course_get_format($this->page->course);
1446 if (($obj = $courseformat->course_header()) !== null) {
1447 return $courseformat->get_renderer($this->page)->render($obj);
1449 return '';
1453 * Returns course-specific information to be output on any course page in the footer area
1454 * (for the current course)
1456 * @return string
1458 public function course_footer() {
1459 global $CFG;
1460 if ($this->page->course->id == SITEID) {
1461 // return immediately and do not include /course/lib.php if not necessary
1462 return '';
1464 require_once($CFG->dirroot.'/course/lib.php');
1465 $courseformat = course_get_format($this->page->course);
1466 if (($obj = $courseformat->course_footer()) !== null) {
1467 return $courseformat->get_renderer($this->page)->render($obj);
1469 return '';
1473 * Returns lang menu or '', this method also checks forcing of languages in courses.
1475 * This function calls {@link core_renderer::render_single_select()} to actually display the language menu.
1477 * @return string The lang menu HTML or empty string
1479 public function lang_menu() {
1480 global $CFG;
1482 if (empty($CFG->langmenu)) {
1483 return '';
1486 if ($this->page->course != SITEID and !empty($this->page->course->lang)) {
1487 // do not show lang menu if language forced
1488 return '';
1491 $currlang = current_language();
1492 $langs = get_string_manager()->get_list_of_translations();
1494 if (count($langs) < 2) {
1495 return '';
1498 $s = new single_select($this->page->url, 'lang', $langs, $currlang, null);
1499 $s->label = get_accesshide(get_string('language'));
1500 $s->class = 'langmenu';
1501 return $this->render($s);
1505 * Output the row of editing icons for a block, as defined by the controls array.
1507 * @param array $controls an array like {@link block_contents::$controls}.
1508 * @param string $blockid The ID given to the block.
1509 * @return string HTML fragment.
1511 public function block_controls($actions, $blockid = null) {
1512 global $CFG;
1513 if (empty($actions)) {
1514 return '';
1516 $menu = new action_menu($actions);
1517 if ($blockid !== null) {
1518 $menu->set_owner_selector('#'.$blockid);
1520 $menu->set_constraint('.block-region');
1521 $menu->attributes['class'] .= ' block-control-actions commands';
1522 return $this->render($menu);
1526 * Renders an action menu component.
1528 * ARIA references:
1529 * - http://www.w3.org/WAI/GL/wiki/Using_ARIA_menus
1530 * - http://stackoverflow.com/questions/12279113/recommended-wai-aria-implementation-for-navigation-bar-menu
1532 * @param action_menu $menu
1533 * @return string HTML
1535 public function render_action_menu(action_menu $menu) {
1536 $context = $menu->export_for_template($this);
1537 return $this->render_from_template('core/action_menu', $context);
1541 * Renders an action_menu_link item.
1543 * @param action_menu_link $action
1544 * @return string HTML fragment
1546 protected function render_action_menu_link(action_menu_link $action) {
1547 return $this->render_from_template('core/action_menu_link', $action->export_for_template($this));
1551 * Renders a primary action_menu_filler item.
1553 * @param action_menu_link_filler $action
1554 * @return string HTML fragment
1556 protected function render_action_menu_filler(action_menu_filler $action) {
1557 return html_writer::span('&nbsp;', 'filler');
1561 * Renders a primary action_menu_link item.
1563 * @param action_menu_link_primary $action
1564 * @return string HTML fragment
1566 protected function render_action_menu_link_primary(action_menu_link_primary $action) {
1567 return $this->render_action_menu_link($action);
1571 * Renders a secondary action_menu_link item.
1573 * @param action_menu_link_secondary $action
1574 * @return string HTML fragment
1576 protected function render_action_menu_link_secondary(action_menu_link_secondary $action) {
1577 return $this->render_action_menu_link($action);
1581 * Prints a nice side block with an optional header.
1583 * The content is described
1584 * by a {@link core_renderer::block_contents} object.
1586 * <div id="inst{$instanceid}" class="block_{$blockname} block">
1587 * <div class="header"></div>
1588 * <div class="content">
1589 * ...CONTENT...
1590 * <div class="footer">
1591 * </div>
1592 * </div>
1593 * <div class="annotation">
1594 * </div>
1595 * </div>
1597 * @param block_contents $bc HTML for the content
1598 * @param string $region the region the block is appearing in.
1599 * @return string the HTML to be output.
1601 public function block(block_contents $bc, $region) {
1602 $bc = clone($bc); // Avoid messing up the object passed in.
1603 if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
1604 $bc->collapsible = block_contents::NOT_HIDEABLE;
1606 if (!empty($bc->blockinstanceid)) {
1607 $bc->attributes['data-instanceid'] = $bc->blockinstanceid;
1609 $skiptitle = strip_tags($bc->title);
1610 if ($bc->blockinstanceid && !empty($skiptitle)) {
1611 $bc->attributes['aria-labelledby'] = 'instance-'.$bc->blockinstanceid.'-header';
1612 } else if (!empty($bc->arialabel)) {
1613 $bc->attributes['aria-label'] = $bc->arialabel;
1615 if ($bc->dockable) {
1616 $bc->attributes['data-dockable'] = 1;
1618 if ($bc->collapsible == block_contents::HIDDEN) {
1619 $bc->add_class('hidden');
1621 if (!empty($bc->controls)) {
1622 $bc->add_class('block_with_controls');
1626 if (empty($skiptitle)) {
1627 $output = '';
1628 $skipdest = '';
1629 } else {
1630 $output = html_writer::link('#sb-'.$bc->skipid, get_string('skipa', 'access', $skiptitle),
1631 array('class' => 'skip skip-block', 'id' => 'fsb-' . $bc->skipid));
1632 $skipdest = html_writer::span('', 'skip-block-to',
1633 array('id' => 'sb-' . $bc->skipid));
1636 $output .= html_writer::start_tag('div', $bc->attributes);
1638 $output .= $this->block_header($bc);
1639 $output .= $this->block_content($bc);
1641 $output .= html_writer::end_tag('div');
1643 $output .= $this->block_annotation($bc);
1645 $output .= $skipdest;
1647 $this->init_block_hider_js($bc);
1648 return $output;
1652 * Produces a header for a block
1654 * @param block_contents $bc
1655 * @return string
1657 protected function block_header(block_contents $bc) {
1659 $title = '';
1660 if ($bc->title) {
1661 $attributes = array();
1662 if ($bc->blockinstanceid) {
1663 $attributes['id'] = 'instance-'.$bc->blockinstanceid.'-header';
1665 $title = html_writer::tag('h2', $bc->title, $attributes);
1668 $blockid = null;
1669 if (isset($bc->attributes['id'])) {
1670 $blockid = $bc->attributes['id'];
1672 $controlshtml = $this->block_controls($bc->controls, $blockid);
1674 $output = '';
1675 if ($title || $controlshtml) {
1676 $output .= html_writer::tag('div', html_writer::tag('div', html_writer::tag('div', '', array('class'=>'block_action')). $title . $controlshtml, array('class' => 'title')), array('class' => 'header'));
1678 return $output;
1682 * Produces the content area for a block
1684 * @param block_contents $bc
1685 * @return string
1687 protected function block_content(block_contents $bc) {
1688 $output = html_writer::start_tag('div', array('class' => 'content'));
1689 if (!$bc->title && !$this->block_controls($bc->controls)) {
1690 $output .= html_writer::tag('div', '', array('class'=>'block_action notitle'));
1692 $output .= $bc->content;
1693 $output .= $this->block_footer($bc);
1694 $output .= html_writer::end_tag('div');
1696 return $output;
1700 * Produces the footer for a block
1702 * @param block_contents $bc
1703 * @return string
1705 protected function block_footer(block_contents $bc) {
1706 $output = '';
1707 if ($bc->footer) {
1708 $output .= html_writer::tag('div', $bc->footer, array('class' => 'footer'));
1710 return $output;
1714 * Produces the annotation for a block
1716 * @param block_contents $bc
1717 * @return string
1719 protected function block_annotation(block_contents $bc) {
1720 $output = '';
1721 if ($bc->annotation) {
1722 $output .= html_writer::tag('div', $bc->annotation, array('class' => 'blockannotation'));
1724 return $output;
1728 * Calls the JS require function to hide a block.
1730 * @param block_contents $bc A block_contents object
1732 protected function init_block_hider_js(block_contents $bc) {
1733 if (!empty($bc->attributes['id']) and $bc->collapsible != block_contents::NOT_HIDEABLE) {
1734 $config = new stdClass;
1735 $config->id = $bc->attributes['id'];
1736 $config->title = strip_tags($bc->title);
1737 $config->preference = 'block' . $bc->blockinstanceid . 'hidden';
1738 $config->tooltipVisible = get_string('hideblocka', 'access', $config->title);
1739 $config->tooltipHidden = get_string('showblocka', 'access', $config->title);
1741 $this->page->requires->js_init_call('M.util.init_block_hider', array($config));
1742 user_preference_allow_ajax_update($config->preference, PARAM_BOOL);
1747 * Render the contents of a block_list.
1749 * @param array $icons the icon for each item.
1750 * @param array $items the content of each item.
1751 * @return string HTML
1753 public function list_block_contents($icons, $items) {
1754 $row = 0;
1755 $lis = array();
1756 foreach ($items as $key => $string) {
1757 $item = html_writer::start_tag('li', array('class' => 'r' . $row));
1758 if (!empty($icons[$key])) { //test if the content has an assigned icon
1759 $item .= html_writer::tag('div', $icons[$key], array('class' => 'icon column c0'));
1761 $item .= html_writer::tag('div', $string, array('class' => 'column c1'));
1762 $item .= html_writer::end_tag('li');
1763 $lis[] = $item;
1764 $row = 1 - $row; // Flip even/odd.
1766 return html_writer::tag('ul', implode("\n", $lis), array('class' => 'unlist'));
1770 * Output all the blocks in a particular region.
1772 * @param string $region the name of a region on this page.
1773 * @return string the HTML to be output.
1775 public function blocks_for_region($region) {
1776 $blockcontents = $this->page->blocks->get_content_for_region($region, $this);
1777 $blocks = $this->page->blocks->get_blocks_for_region($region);
1778 $lastblock = null;
1779 $zones = array();
1780 foreach ($blocks as $block) {
1781 $zones[] = $block->title;
1783 $output = '';
1785 foreach ($blockcontents as $bc) {
1786 if ($bc instanceof block_contents) {
1787 $output .= $this->block($bc, $region);
1788 $lastblock = $bc->title;
1789 } else if ($bc instanceof block_move_target) {
1790 $output .= $this->block_move_target($bc, $zones, $lastblock, $region);
1791 } else {
1792 throw new coding_exception('Unexpected type of thing (' . get_class($bc) . ') found in list of block contents.');
1795 return $output;
1799 * Output a place where the block that is currently being moved can be dropped.
1801 * @param block_move_target $target with the necessary details.
1802 * @param array $zones array of areas where the block can be moved to
1803 * @param string $previous the block located before the area currently being rendered.
1804 * @param string $region the name of the region
1805 * @return string the HTML to be output.
1807 public function block_move_target($target, $zones, $previous, $region) {
1808 if ($previous == null) {
1809 if (empty($zones)) {
1810 // There are no zones, probably because there are no blocks.
1811 $regions = $this->page->theme->get_all_block_regions();
1812 $position = get_string('moveblockinregion', 'block', $regions[$region]);
1813 } else {
1814 $position = get_string('moveblockbefore', 'block', $zones[0]);
1816 } else {
1817 $position = get_string('moveblockafter', 'block', $previous);
1819 return html_writer::tag('a', html_writer::tag('span', $position, array('class' => 'accesshide')), array('href' => $target->url, 'class' => 'blockmovetarget'));
1823 * Renders a special html link with attached action
1825 * Theme developers: DO NOT OVERRIDE! Please override function
1826 * {@link core_renderer::render_action_link()} instead.
1828 * @param string|moodle_url $url
1829 * @param string $text HTML fragment
1830 * @param component_action $action
1831 * @param array $attributes associative array of html link attributes + disabled
1832 * @param pix_icon optional pix icon to render with the link
1833 * @return string HTML fragment
1835 public function action_link($url, $text, component_action $action = null, array $attributes = null, $icon = null) {
1836 if (!($url instanceof moodle_url)) {
1837 $url = new moodle_url($url);
1839 $link = new action_link($url, $text, $action, $attributes, $icon);
1841 return $this->render($link);
1845 * Renders an action_link object.
1847 * The provided link is renderer and the HTML returned. At the same time the
1848 * associated actions are setup in JS by {@link core_renderer::add_action_handler()}
1850 * @param action_link $link
1851 * @return string HTML fragment
1853 protected function render_action_link(action_link $link) {
1854 return $this->render_from_template('core/action_link', $link->export_for_template($this));
1858 * Renders an action_icon.
1860 * This function uses the {@link core_renderer::action_link()} method for the
1861 * most part. What it does different is prepare the icon as HTML and use it
1862 * as the link text.
1864 * Theme developers: If you want to change how action links and/or icons are rendered,
1865 * consider overriding function {@link core_renderer::render_action_link()} and
1866 * {@link core_renderer::render_pix_icon()}.
1868 * @param string|moodle_url $url A string URL or moodel_url
1869 * @param pix_icon $pixicon
1870 * @param component_action $action
1871 * @param array $attributes associative array of html link attributes + disabled
1872 * @param bool $linktext show title next to image in link
1873 * @return string HTML fragment
1875 public function action_icon($url, pix_icon $pixicon, component_action $action = null, array $attributes = null, $linktext=false) {
1876 if (!($url instanceof moodle_url)) {
1877 $url = new moodle_url($url);
1879 $attributes = (array)$attributes;
1881 if (empty($attributes['class'])) {
1882 // let ppl override the class via $options
1883 $attributes['class'] = 'action-icon';
1886 $icon = $this->render($pixicon);
1888 if ($linktext) {
1889 $text = $pixicon->attributes['alt'];
1890 } else {
1891 $text = '';
1894 return $this->action_link($url, $text.$icon, $action, $attributes);
1898 * Print a message along with button choices for Continue/Cancel
1900 * If a string or moodle_url is given instead of a single_button, method defaults to post.
1902 * @param string $message The question to ask the user
1903 * @param single_button|moodle_url|string $continue The single_button component representing the Continue answer. Can also be a moodle_url or string URL
1904 * @param single_button|moodle_url|string $cancel The single_button component representing the Cancel answer. Can also be a moodle_url or string URL
1905 * @return string HTML fragment
1907 public function confirm($message, $continue, $cancel) {
1908 if ($continue instanceof single_button) {
1909 // ok
1910 $continue->primary = true;
1911 } else if (is_string($continue)) {
1912 $continue = new single_button(new moodle_url($continue), get_string('continue'), 'post', true);
1913 } else if ($continue instanceof moodle_url) {
1914 $continue = new single_button($continue, get_string('continue'), 'post', true);
1915 } else {
1916 throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a single_button instance.');
1919 if ($cancel instanceof single_button) {
1920 // ok
1921 } else if (is_string($cancel)) {
1922 $cancel = new single_button(new moodle_url($cancel), get_string('cancel'), 'get');
1923 } else if ($cancel instanceof moodle_url) {
1924 $cancel = new single_button($cancel, get_string('cancel'), 'get');
1925 } else {
1926 throw new coding_exception('The cancel param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a single_button instance.');
1929 $output = $this->box_start('generalbox modal modal-dialog modal-in-page show', 'notice');
1930 $output .= $this->box_start('modal-content', 'modal-content');
1931 $output .= $this->box_start('modal-header p-x-1', 'modal-header');
1932 $output .= html_writer::tag('h4', get_string('confirm'));
1933 $output .= $this->box_end();
1934 $output .= $this->box_start('modal-body', 'modal-body');
1935 $output .= html_writer::tag('p', $message);
1936 $output .= $this->box_end();
1937 $output .= $this->box_start('modal-footer', 'modal-footer');
1938 $output .= html_writer::tag('div', $this->render($continue) . $this->render($cancel), array('class' => 'buttons'));
1939 $output .= $this->box_end();
1940 $output .= $this->box_end();
1941 $output .= $this->box_end();
1942 return $output;
1946 * Returns a form with a single button.
1948 * Theme developers: DO NOT OVERRIDE! Please override function
1949 * {@link core_renderer::render_single_button()} instead.
1951 * @param string|moodle_url $url
1952 * @param string $label button text
1953 * @param string $method get or post submit method
1954 * @param array $options associative array {disabled, title, etc.}
1955 * @return string HTML fragment
1957 public function single_button($url, $label, $method='post', array $options=null) {
1958 if (!($url instanceof moodle_url)) {
1959 $url = new moodle_url($url);
1961 $button = new single_button($url, $label, $method);
1963 foreach ((array)$options as $key=>$value) {
1964 if (array_key_exists($key, $button)) {
1965 $button->$key = $value;
1969 return $this->render($button);
1973 * Renders a single button widget.
1975 * This will return HTML to display a form containing a single button.
1977 * @param single_button $button
1978 * @return string HTML fragment
1980 protected function render_single_button(single_button $button) {
1981 $attributes = array('type' => 'submit',
1982 'value' => $button->label,
1983 'disabled' => $button->disabled ? 'disabled' : null,
1984 'title' => $button->tooltip);
1986 if ($button->actions) {
1987 $id = html_writer::random_id('single_button');
1988 $attributes['id'] = $id;
1989 foreach ($button->actions as $action) {
1990 $this->add_action_handler($action, $id);
1994 // first the input element
1995 $output = html_writer::empty_tag('input', $attributes);
1997 // then hidden fields
1998 $params = $button->url->params();
1999 if ($button->method === 'post') {
2000 $params['sesskey'] = sesskey();
2002 foreach ($params as $var => $val) {
2003 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
2006 // then div wrapper for xhtml strictness
2007 $output = html_writer::tag('div', $output);
2009 // now the form itself around it
2010 if ($button->method === 'get') {
2011 $url = $button->url->out_omit_querystring(true); // url without params, the anchor part allowed
2012 } else {
2013 $url = $button->url->out_omit_querystring(); // url without params, the anchor part not allowed
2015 if ($url === '') {
2016 $url = '#'; // there has to be always some action
2018 $attributes = array('method' => $button->method,
2019 'action' => $url,
2020 'id' => $button->formid);
2021 $output = html_writer::tag('form', $output, $attributes);
2023 // and finally one more wrapper with class
2024 return html_writer::tag('div', $output, array('class' => $button->class));
2028 * Returns a form with a single select widget.
2030 * Theme developers: DO NOT OVERRIDE! Please override function
2031 * {@link core_renderer::render_single_select()} instead.
2033 * @param moodle_url $url form action target, includes hidden fields
2034 * @param string $name name of selection field - the changing parameter in url
2035 * @param array $options list of options
2036 * @param string $selected selected element
2037 * @param array $nothing
2038 * @param string $formid
2039 * @param array $attributes other attributes for the single select
2040 * @return string HTML fragment
2042 public function single_select($url, $name, array $options, $selected = '',
2043 $nothing = array('' => 'choosedots'), $formid = null, $attributes = array()) {
2044 if (!($url instanceof moodle_url)) {
2045 $url = new moodle_url($url);
2047 $select = new single_select($url, $name, $options, $selected, $nothing, $formid);
2049 if (array_key_exists('label', $attributes)) {
2050 $select->set_label($attributes['label']);
2051 unset($attributes['label']);
2053 $select->attributes = $attributes;
2055 return $this->render($select);
2059 * Returns a dataformat selection and download form
2061 * @param string $label A text label
2062 * @param moodle_url|string $base The download page url
2063 * @param string $name The query param which will hold the type of the download
2064 * @param array $params Extra params sent to the download page
2065 * @return string HTML fragment
2067 public function download_dataformat_selector($label, $base, $name = 'dataformat', $params = array()) {
2069 $formats = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
2070 $options = array();
2071 foreach ($formats as $format) {
2072 if ($format->is_enabled()) {
2073 $options[] = array(
2074 'value' => $format->name,
2075 'label' => get_string('dataformat', $format->component),
2079 $hiddenparams = array();
2080 foreach ($params as $key => $value) {
2081 $hiddenparams[] = array(
2082 'name' => $key,
2083 'value' => $value,
2086 $data = array(
2087 'label' => $label,
2088 'base' => $base,
2089 'name' => $name,
2090 'params' => $hiddenparams,
2091 'options' => $options,
2092 'sesskey' => sesskey(),
2093 'submit' => get_string('download'),
2096 return $this->render_from_template('core/dataformat_selector', $data);
2101 * Internal implementation of single_select rendering
2103 * @param single_select $select
2104 * @return string HTML fragment
2106 protected function render_single_select(single_select $select) {
2107 return $this->render_from_template('core/single_select', $select->export_for_template($this));
2111 * Returns a form with a url select widget.
2113 * Theme developers: DO NOT OVERRIDE! Please override function
2114 * {@link core_renderer::render_url_select()} instead.
2116 * @param array $urls list of urls - array('/course/view.php?id=1'=>'Frontpage', ....)
2117 * @param string $selected selected element
2118 * @param array $nothing
2119 * @param string $formid
2120 * @return string HTML fragment
2122 public function url_select(array $urls, $selected, $nothing = array('' => 'choosedots'), $formid = null) {
2123 $select = new url_select($urls, $selected, $nothing, $formid);
2124 return $this->render($select);
2128 * Internal implementation of url_select rendering
2130 * @param url_select $select
2131 * @return string HTML fragment
2133 protected function render_url_select(url_select $select) {
2134 return $this->render_from_template('core/url_select', $select->export_for_template($this));
2138 * Returns a string containing a link to the user documentation.
2139 * Also contains an icon by default. Shown to teachers and admin only.
2141 * @param string $path The page link after doc root and language, no leading slash.
2142 * @param string $text The text to be displayed for the link
2143 * @param boolean $forcepopup Whether to force a popup regardless of the value of $CFG->doctonewwindow
2144 * @return string
2146 public function doc_link($path, $text = '', $forcepopup = false) {
2147 global $CFG;
2149 $icon = $this->pix_icon('docs', '', 'moodle', array('class'=>'iconhelp icon-pre', 'role'=>'presentation'));
2151 $url = new moodle_url(get_docs_url($path));
2153 $attributes = array('href'=>$url);
2154 if (!empty($CFG->doctonewwindow) || $forcepopup) {
2155 $attributes['class'] = 'helplinkpopup';
2158 return html_writer::tag('a', $icon.$text, $attributes);
2162 * Return HTML for an image_icon.
2164 * Theme developers: DO NOT OVERRIDE! Please override function
2165 * {@link core_renderer::render_image_icon()} instead.
2167 * @param string $pix short pix name
2168 * @param string $alt mandatory alt attribute
2169 * @param string $component standard compoennt name like 'moodle', 'mod_forum', etc.
2170 * @param array $attributes htm lattributes
2171 * @return string HTML fragment
2173 public function image_icon($pix, $alt, $component='moodle', array $attributes = null) {
2174 $icon = new image_icon($pix, $alt, $component, $attributes);
2175 return $this->render($icon);
2179 * Renders a pix_icon widget and returns the HTML to display it.
2181 * @param image_icon $icon
2182 * @return string HTML fragment
2184 protected function render_image_icon(image_icon $icon) {
2185 $system = \core\output\icon_system::instance(\core\output\icon_system::STANDARD);
2186 return $system->render_pix_icon($this, $icon);
2190 * Return HTML for a pix_icon.
2192 * Theme developers: DO NOT OVERRIDE! Please override function
2193 * {@link core_renderer::render_pix_icon()} instead.
2195 * @param string $pix short pix name
2196 * @param string $alt mandatory alt attribute
2197 * @param string $component standard compoennt name like 'moodle', 'mod_forum', etc.
2198 * @param array $attributes htm lattributes
2199 * @return string HTML fragment
2201 public function pix_icon($pix, $alt, $component='moodle', array $attributes = null) {
2202 $icon = new pix_icon($pix, $alt, $component, $attributes);
2203 return $this->render($icon);
2207 * Renders a pix_icon widget and returns the HTML to display it.
2209 * @param pix_icon $icon
2210 * @return string HTML fragment
2212 protected function render_pix_icon(pix_icon $icon) {
2213 $system = \core\output\icon_system::instance();
2214 return $system->render_pix_icon($this, $icon);
2218 * Return HTML to display an emoticon icon.
2220 * @param pix_emoticon $emoticon
2221 * @return string HTML fragment
2223 protected function render_pix_emoticon(pix_emoticon $emoticon) {
2224 $system = \core\output\icon_system::instance(\core\output\icon_system::STANDARD);
2225 return $system->render_pix_icon($this, $emoticon);
2229 * Produces the html that represents this rating in the UI
2231 * @param rating $rating the page object on which this rating will appear
2232 * @return string
2234 function render_rating(rating $rating) {
2235 global $CFG, $USER;
2237 if ($rating->settings->aggregationmethod == RATING_AGGREGATE_NONE) {
2238 return null;//ratings are turned off
2241 $ratingmanager = new rating_manager();
2242 // Initialise the JavaScript so ratings can be done by AJAX.
2243 $ratingmanager->initialise_rating_javascript($this->page);
2245 $strrate = get_string("rate", "rating");
2246 $ratinghtml = ''; //the string we'll return
2248 // permissions check - can they view the aggregate?
2249 if ($rating->user_can_view_aggregate()) {
2251 $aggregatelabel = $ratingmanager->get_aggregate_label($rating->settings->aggregationmethod);
2252 $aggregatestr = $rating->get_aggregate_string();
2254 $aggregatehtml = html_writer::tag('span', $aggregatestr, array('id' => 'ratingaggregate'.$rating->itemid, 'class' => 'ratingaggregate')).' ';
2255 if ($rating->count > 0) {
2256 $countstr = "({$rating->count})";
2257 } else {
2258 $countstr = '-';
2260 $aggregatehtml .= html_writer::tag('span', $countstr, array('id'=>"ratingcount{$rating->itemid}", 'class' => 'ratingcount')).' ';
2262 $ratinghtml .= html_writer::tag('span', $aggregatelabel, array('class'=>'rating-aggregate-label'));
2263 if ($rating->settings->permissions->viewall && $rating->settings->pluginpermissions->viewall) {
2265 $nonpopuplink = $rating->get_view_ratings_url();
2266 $popuplink = $rating->get_view_ratings_url(true);
2268 $action = new popup_action('click', $popuplink, 'ratings', array('height' => 400, 'width' => 600));
2269 $ratinghtml .= $this->action_link($nonpopuplink, $aggregatehtml, $action);
2270 } else {
2271 $ratinghtml .= $aggregatehtml;
2275 $formstart = null;
2276 // if the item doesn't belong to the current user, the user has permission to rate
2277 // and we're within the assessable period
2278 if ($rating->user_can_rate()) {
2280 $rateurl = $rating->get_rate_url();
2281 $inputs = $rateurl->params();
2283 //start the rating form
2284 $formattrs = array(
2285 'id' => "postrating{$rating->itemid}",
2286 'class' => 'postratingform',
2287 'method' => 'post',
2288 'action' => $rateurl->out_omit_querystring()
2290 $formstart = html_writer::start_tag('form', $formattrs);
2291 $formstart .= html_writer::start_tag('div', array('class' => 'ratingform'));
2293 // add the hidden inputs
2294 foreach ($inputs as $name => $value) {
2295 $attributes = array('type' => 'hidden', 'class' => 'ratinginput', 'name' => $name, 'value' => $value);
2296 $formstart .= html_writer::empty_tag('input', $attributes);
2299 if (empty($ratinghtml)) {
2300 $ratinghtml .= $strrate.': ';
2302 $ratinghtml = $formstart.$ratinghtml;
2304 $scalearray = array(RATING_UNSET_RATING => $strrate.'...') + $rating->settings->scale->scaleitems;
2305 $scaleattrs = array('class'=>'postratingmenu ratinginput','id'=>'menurating'.$rating->itemid);
2306 $ratinghtml .= html_writer::label($rating->rating, 'menurating'.$rating->itemid, false, array('class' => 'accesshide'));
2307 $ratinghtml .= html_writer::select($scalearray, 'rating', $rating->rating, false, $scaleattrs);
2309 //output submit button
2310 $ratinghtml .= html_writer::start_tag('span', array('class'=>"ratingsubmit"));
2312 $attributes = array('type' => 'submit', 'class' => 'postratingmenusubmit', 'id' => 'postratingsubmit'.$rating->itemid, 'value' => s(get_string('rate', 'rating')));
2313 $ratinghtml .= html_writer::empty_tag('input', $attributes);
2315 if (!$rating->settings->scale->isnumeric) {
2316 // If a global scale, try to find current course ID from the context
2317 if (empty($rating->settings->scale->courseid) and $coursecontext = $rating->context->get_course_context(false)) {
2318 $courseid = $coursecontext->instanceid;
2319 } else {
2320 $courseid = $rating->settings->scale->courseid;
2322 $ratinghtml .= $this->help_icon_scale($courseid, $rating->settings->scale);
2324 $ratinghtml .= html_writer::end_tag('span');
2325 $ratinghtml .= html_writer::end_tag('div');
2326 $ratinghtml .= html_writer::end_tag('form');
2329 return $ratinghtml;
2333 * Centered heading with attached help button (same title text)
2334 * and optional icon attached.
2336 * @param string $text A heading text
2337 * @param string $helpidentifier The keyword that defines a help page
2338 * @param string $component component name
2339 * @param string|moodle_url $icon
2340 * @param string $iconalt icon alt text
2341 * @param int $level The level of importance of the heading. Defaulting to 2
2342 * @param string $classnames A space-separated list of CSS classes. Defaulting to null
2343 * @return string HTML fragment
2345 public function heading_with_help($text, $helpidentifier, $component = 'moodle', $icon = '', $iconalt = '', $level = 2, $classnames = null) {
2346 $image = '';
2347 if ($icon) {
2348 $image = $this->pix_icon($icon, $iconalt, $component, array('class'=>'icon iconlarge'));
2351 $help = '';
2352 if ($helpidentifier) {
2353 $help = $this->help_icon($helpidentifier, $component);
2356 return $this->heading($image.$text.$help, $level, $classnames);
2360 * Returns HTML to display a help icon.
2362 * @deprecated since Moodle 2.0
2364 public function old_help_icon($helpidentifier, $title, $component = 'moodle', $linktext = '') {
2365 throw new coding_exception('old_help_icon() can not be used any more, please see help_icon().');
2369 * Returns HTML to display a help icon.
2371 * Theme developers: DO NOT OVERRIDE! Please override function
2372 * {@link core_renderer::render_help_icon()} instead.
2374 * @param string $identifier The keyword that defines a help page
2375 * @param string $component component name
2376 * @param string|bool $linktext true means use $title as link text, string means link text value
2377 * @return string HTML fragment
2379 public function help_icon($identifier, $component = 'moodle', $linktext = '') {
2380 $icon = new help_icon($identifier, $component);
2381 $icon->diag_strings();
2382 if ($linktext === true) {
2383 $icon->linktext = get_string($icon->identifier, $icon->component);
2384 } else if (!empty($linktext)) {
2385 $icon->linktext = $linktext;
2387 return $this->render($icon);
2391 * Implementation of user image rendering.
2393 * @param help_icon $helpicon A help icon instance
2394 * @return string HTML fragment
2396 protected function render_help_icon(help_icon $helpicon) {
2397 return $this->render_from_template('core/help_icon', $helpicon->export_for_template($this));
2401 * Returns HTML to display a scale help icon.
2403 * @param int $courseid
2404 * @param stdClass $scale instance
2405 * @return string HTML fragment
2407 public function help_icon_scale($courseid, stdClass $scale) {
2408 global $CFG;
2410 $title = get_string('helpprefix2', '', $scale->name) .' ('.get_string('newwindow').')';
2412 $icon = $this->pix_icon('help', get_string('scales'), 'moodle', array('class'=>'iconhelp'));
2414 $scaleid = abs($scale->id);
2416 $link = new moodle_url('/course/scales.php', array('id' => $courseid, 'list' => true, 'scaleid' => $scaleid));
2417 $action = new popup_action('click', $link, 'ratingscale');
2419 return html_writer::tag('span', $this->action_link($link, $icon, $action), array('class' => 'helplink'));
2423 * Creates and returns a spacer image with optional line break.
2425 * @param array $attributes Any HTML attributes to add to the spaced.
2426 * @param bool $br Include a BR after the spacer.... DON'T USE THIS. Don't be
2427 * laxy do it with CSS which is a much better solution.
2428 * @return string HTML fragment
2430 public function spacer(array $attributes = null, $br = false) {
2431 $attributes = (array)$attributes;
2432 if (empty($attributes['width'])) {
2433 $attributes['width'] = 1;
2435 if (empty($attributes['height'])) {
2436 $attributes['height'] = 1;
2438 $attributes['class'] = 'spacer';
2440 $output = $this->pix_icon('spacer', '', 'moodle', $attributes);
2442 if (!empty($br)) {
2443 $output .= '<br />';
2446 return $output;
2450 * Returns HTML to display the specified user's avatar.
2452 * User avatar may be obtained in two ways:
2453 * <pre>
2454 * // Option 1: (shortcut for simple cases, preferred way)
2455 * // $user has come from the DB and has fields id, picture, imagealt, firstname and lastname
2456 * $OUTPUT->user_picture($user, array('popup'=>true));
2458 * // Option 2:
2459 * $userpic = new user_picture($user);
2460 * // Set properties of $userpic
2461 * $userpic->popup = true;
2462 * $OUTPUT->render($userpic);
2463 * </pre>
2465 * Theme developers: DO NOT OVERRIDE! Please override function
2466 * {@link core_renderer::render_user_picture()} instead.
2468 * @param stdClass $user Object with at least fields id, picture, imagealt, firstname, lastname
2469 * If any of these are missing, the database is queried. Avoid this
2470 * if at all possible, particularly for reports. It is very bad for performance.
2471 * @param array $options associative array with user picture options, used only if not a user_picture object,
2472 * options are:
2473 * - courseid=$this->page->course->id (course id of user profile in link)
2474 * - size=35 (size of image)
2475 * - link=true (make image clickable - the link leads to user profile)
2476 * - popup=false (open in popup)
2477 * - alttext=true (add image alt attribute)
2478 * - class = image class attribute (default 'userpicture')
2479 * - visibletoscreenreaders=true (whether to be visible to screen readers)
2480 * - includefullname=false (whether to include the user's full name together with the user picture)
2481 * @return string HTML fragment
2483 public function user_picture(stdClass $user, array $options = null) {
2484 $userpicture = new user_picture($user);
2485 foreach ((array)$options as $key=>$value) {
2486 if (array_key_exists($key, $userpicture)) {
2487 $userpicture->$key = $value;
2490 return $this->render($userpicture);
2494 * Internal implementation of user image rendering.
2496 * @param user_picture $userpicture
2497 * @return string
2499 protected function render_user_picture(user_picture $userpicture) {
2500 global $CFG, $DB;
2502 $user = $userpicture->user;
2503 $canviewfullnames = has_capability('moodle/site:viewfullnames', $this->page->context);
2505 if ($userpicture->alttext) {
2506 if (!empty($user->imagealt)) {
2507 $alt = $user->imagealt;
2508 } else {
2509 $alt = get_string('pictureof', '', fullname($user, $canviewfullnames));
2511 } else {
2512 $alt = '';
2515 if (empty($userpicture->size)) {
2516 $size = 35;
2517 } else if ($userpicture->size === true or $userpicture->size == 1) {
2518 $size = 100;
2519 } else {
2520 $size = $userpicture->size;
2523 $class = $userpicture->class;
2525 if ($user->picture == 0) {
2526 $class .= ' defaultuserpic';
2529 $src = $userpicture->get_url($this->page, $this);
2531 $attributes = array('src' => $src, 'class' => $class, 'width' => $size, 'height' => $size);
2532 if (!$userpicture->visibletoscreenreaders) {
2533 $attributes['role'] = 'presentation';
2534 $alt = '';
2535 $attributes['aria-hidden'] = 'true';
2538 if (!empty($alt)) {
2539 $attributes['alt'] = $alt;
2540 $attributes['title'] = $alt;
2543 // get the image html output fisrt
2544 $output = html_writer::empty_tag('img', $attributes);
2546 // Show fullname together with the picture when desired.
2547 if ($userpicture->includefullname) {
2548 $output .= fullname($userpicture->user, $canviewfullnames);
2551 // then wrap it in link if needed
2552 if (!$userpicture->link) {
2553 return $output;
2556 if (empty($userpicture->courseid)) {
2557 $courseid = $this->page->course->id;
2558 } else {
2559 $courseid = $userpicture->courseid;
2562 if ($courseid == SITEID) {
2563 $url = new moodle_url('/user/profile.php', array('id' => $user->id));
2564 } else {
2565 $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid));
2568 $attributes = array('href'=>$url);
2569 if (!$userpicture->visibletoscreenreaders) {
2570 $attributes['tabindex'] = '-1';
2571 $attributes['aria-hidden'] = 'true';
2574 if ($userpicture->popup) {
2575 $id = html_writer::random_id('userpicture');
2576 $attributes['id'] = $id;
2577 $this->add_action_handler(new popup_action('click', $url), $id);
2580 return html_writer::tag('a', $output, $attributes);
2584 * Internal implementation of file tree viewer items rendering.
2586 * @param array $dir
2587 * @return string
2589 public function htmllize_file_tree($dir) {
2590 if (empty($dir['subdirs']) and empty($dir['files'])) {
2591 return '';
2593 $result = '<ul>';
2594 foreach ($dir['subdirs'] as $subdir) {
2595 $result .= '<li>'.s($subdir['dirname']).' '.$this->htmllize_file_tree($subdir).'</li>';
2597 foreach ($dir['files'] as $file) {
2598 $filename = $file->get_filename();
2599 $result .= '<li><span>'.html_writer::link($file->fileurl, $filename).'</span></li>';
2601 $result .= '</ul>';
2603 return $result;
2607 * Returns HTML to display the file picker
2609 * <pre>
2610 * $OUTPUT->file_picker($options);
2611 * </pre>
2613 * Theme developers: DO NOT OVERRIDE! Please override function
2614 * {@link core_renderer::render_file_picker()} instead.
2616 * @param array $options associative array with file manager options
2617 * options are:
2618 * maxbytes=>-1,
2619 * itemid=>0,
2620 * client_id=>uniqid(),
2621 * acepted_types=>'*',
2622 * return_types=>FILE_INTERNAL,
2623 * context=>$PAGE->context
2624 * @return string HTML fragment
2626 public function file_picker($options) {
2627 $fp = new file_picker($options);
2628 return $this->render($fp);
2632 * Internal implementation of file picker rendering.
2634 * @param file_picker $fp
2635 * @return string
2637 public function render_file_picker(file_picker $fp) {
2638 global $CFG, $OUTPUT, $USER;
2639 $options = $fp->options;
2640 $client_id = $options->client_id;
2641 $strsaved = get_string('filesaved', 'repository');
2642 $straddfile = get_string('openpicker', 'repository');
2643 $strloading = get_string('loading', 'repository');
2644 $strdndenabled = get_string('dndenabled_inbox', 'moodle');
2645 $strdroptoupload = get_string('droptoupload', 'moodle');
2646 $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
2648 $currentfile = $options->currentfile;
2649 if (empty($currentfile)) {
2650 $currentfile = '';
2651 } else {
2652 $currentfile .= ' - ';
2654 if ($options->maxbytes) {
2655 $size = $options->maxbytes;
2656 } else {
2657 $size = get_max_upload_file_size();
2659 if ($size == -1) {
2660 $maxsize = '';
2661 } else {
2662 $maxsize = get_string('maxfilesize', 'moodle', display_size($size));
2664 if ($options->buttonname) {
2665 $buttonname = ' name="' . $options->buttonname . '"';
2666 } else {
2667 $buttonname = '';
2669 $html = <<<EOD
2670 <div class="filemanager-loading mdl-align" id='filepicker-loading-{$client_id}'>
2671 $icon_progress
2672 </div>
2673 <div id="filepicker-wrapper-{$client_id}" class="mdl-left w-100" style="display:none">
2674 <div>
2675 <input type="button" class="btn btn-secondary fp-btn-choose" id="filepicker-button-{$client_id}" value="{$straddfile}"{$buttonname}/>
2676 <span> $maxsize </span>
2677 </div>
2678 EOD;
2679 if ($options->env != 'url') {
2680 $html .= <<<EOD
2681 <div id="file_info_{$client_id}" class="mdl-left filepicker-filelist" style="position: relative">
2682 <div class="filepicker-filename">
2683 <div class="filepicker-container">$currentfile<div class="dndupload-message">$strdndenabled <br/><div class="dndupload-arrow"></div></div></div>
2684 <div class="dndupload-progressbars"></div>
2685 </div>
2686 <div><div class="dndupload-target">{$strdroptoupload}<br/><div class="dndupload-arrow"></div></div></div>
2687 </div>
2688 EOD;
2690 $html .= '</div>';
2691 return $html;
2695 * Returns HTML to display the 'Update this Modulename' button that appears on module pages.
2697 * @deprecated since Moodle 3.2
2699 * @param string $cmid the course_module id.
2700 * @param string $modulename the module name, eg. "forum", "quiz" or "workshop"
2701 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
2703 public function update_module_button($cmid, $modulename) {
2704 global $CFG;
2706 debugging('core_renderer::update_module_button() has been deprecated and should not be used anymore. Activity modules ' .
2707 'should not add the edit module button, the link is already available in the Administration block. Themes can choose ' .
2708 'to display the link in the buttons row consistently for all module types.', DEBUG_DEVELOPER);
2710 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
2711 $modulename = get_string('modulename', $modulename);
2712 $string = get_string('updatethis', '', $modulename);
2713 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
2714 return $this->single_button($url, $string);
2715 } else {
2716 return '';
2721 * Returns HTML to display a "Turn editing on/off" button in a form.
2723 * @param moodle_url $url The URL + params to send through when clicking the button
2724 * @return string HTML the button
2726 public function edit_button(moodle_url $url) {
2728 $url->param('sesskey', sesskey());
2729 if ($this->page->user_is_editing()) {
2730 $url->param('edit', 'off');
2731 $editstring = get_string('turneditingoff');
2732 } else {
2733 $url->param('edit', 'on');
2734 $editstring = get_string('turneditingon');
2737 return $this->single_button($url, $editstring);
2741 * Returns HTML to display a simple button to close a window
2743 * @param string $text The lang string for the button's label (already output from get_string())
2744 * @return string html fragment
2746 public function close_window_button($text='') {
2747 if (empty($text)) {
2748 $text = get_string('closewindow');
2750 $button = new single_button(new moodle_url('#'), $text, 'get');
2751 $button->add_action(new component_action('click', 'close_window'));
2753 return $this->container($this->render($button), 'closewindow');
2757 * Output an error message. By default wraps the error message in <span class="error">.
2758 * If the error message is blank, nothing is output.
2760 * @param string $message the error message.
2761 * @return string the HTML to output.
2763 public function error_text($message) {
2764 if (empty($message)) {
2765 return '';
2767 $message = $this->pix_icon('i/warning', get_string('error'), '', array('class' => 'icon icon-pre', 'title'=>'')) . $message;
2768 return html_writer::tag('span', $message, array('class' => 'error'));
2772 * Do not call this function directly.
2774 * To terminate the current script with a fatal error, call the {@link print_error}
2775 * function, or throw an exception. Doing either of those things will then call this
2776 * function to display the error, before terminating the execution.
2778 * @param string $message The message to output
2779 * @param string $moreinfourl URL where more info can be found about the error
2780 * @param string $link Link for the Continue button
2781 * @param array $backtrace The execution backtrace
2782 * @param string $debuginfo Debugging information
2783 * @return string the HTML to output.
2785 public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null, $errorcode = "") {
2786 global $CFG;
2788 $output = '';
2789 $obbuffer = '';
2791 if ($this->has_started()) {
2792 // we can not always recover properly here, we have problems with output buffering,
2793 // html tables, etc.
2794 $output .= $this->opencontainers->pop_all_but_last();
2796 } else {
2797 // It is really bad if library code throws exception when output buffering is on,
2798 // because the buffered text would be printed before our start of page.
2799 // NOTE: this hack might be behave unexpectedly in case output buffering is enabled in PHP.ini
2800 error_reporting(0); // disable notices from gzip compression, etc.
2801 while (ob_get_level() > 0) {
2802 $buff = ob_get_clean();
2803 if ($buff === false) {
2804 break;
2806 $obbuffer .= $buff;
2808 error_reporting($CFG->debug);
2810 // Output not yet started.
2811 $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
2812 if (empty($_SERVER['HTTP_RANGE'])) {
2813 @header($protocol . ' 404 Not Found');
2814 } else if (core_useragent::check_safari_ios_version(602) && !empty($_SERVER['HTTP_X_PLAYBACK_SESSION_ID'])) {
2815 // Coax iOS 10 into sending the session cookie.
2816 @header($protocol . ' 403 Forbidden');
2817 } else {
2818 // Must stop byteserving attempts somehow,
2819 // this is weird but Chrome PDF viewer can be stopped only with 407!
2820 @header($protocol . ' 407 Proxy Authentication Required');
2823 $this->page->set_context(null); // ugly hack - make sure page context is set to something, we do not want bogus warnings here
2824 $this->page->set_url('/'); // no url
2825 //$this->page->set_pagelayout('base'); //TODO: MDL-20676 blocks on error pages are weird, unfortunately it somehow detect the pagelayout from URL :-(
2826 $this->page->set_title(get_string('error'));
2827 $this->page->set_heading($this->page->course->fullname);
2828 $output .= $this->header();
2831 $message = '<p class="errormessage">' . s($message) . '</p>'.
2832 '<p class="errorcode"><a href="' . s($moreinfourl) . '">' .
2833 get_string('moreinformation') . '</a></p>';
2834 if (empty($CFG->rolesactive)) {
2835 $message .= '<p class="errormessage">' . get_string('installproblem', 'error') . '</p>';
2836 //It is usually not possible to recover from errors triggered during installation, you may need to create a new database or use a different database prefix for new installation.
2838 $output .= $this->box($message, 'errorbox alert alert-danger', null, array('data-rel' => 'fatalerror'));
2840 if ($CFG->debugdeveloper) {
2841 if (!empty($debuginfo)) {
2842 $debuginfo = s($debuginfo); // removes all nasty JS
2843 $debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines
2844 $output .= $this->notification('<strong>Debug info:</strong> '.$debuginfo, 'notifytiny');
2846 if (!empty($backtrace)) {
2847 $output .= $this->notification('<strong>Stack trace:</strong> '.format_backtrace($backtrace), 'notifytiny');
2849 if ($obbuffer !== '' ) {
2850 $output .= $this->notification('<strong>Output buffer:</strong> '.s($obbuffer), 'notifytiny');
2854 if (empty($CFG->rolesactive)) {
2855 // continue does not make much sense if moodle is not installed yet because error is most probably not recoverable
2856 } else if (!empty($link)) {
2857 $output .= $this->continue_button($link);
2860 $output .= $this->footer();
2862 // Padding to encourage IE to display our error page, rather than its own.
2863 $output .= str_repeat(' ', 512);
2865 return $output;
2869 * Output a notification (that is, a status message about something that has just happened).
2871 * Note: \core\notification::add() may be more suitable for your usage.
2873 * @param string $message The message to print out.
2874 * @param string $type The type of notification. See constants on \core\output\notification.
2875 * @return string the HTML to output.
2877 public function notification($message, $type = null) {
2878 $typemappings = [
2879 // Valid types.
2880 'success' => \core\output\notification::NOTIFY_SUCCESS,
2881 'info' => \core\output\notification::NOTIFY_INFO,
2882 'warning' => \core\output\notification::NOTIFY_WARNING,
2883 'error' => \core\output\notification::NOTIFY_ERROR,
2885 // Legacy types mapped to current types.
2886 'notifyproblem' => \core\output\notification::NOTIFY_ERROR,
2887 'notifytiny' => \core\output\notification::NOTIFY_ERROR,
2888 'notifyerror' => \core\output\notification::NOTIFY_ERROR,
2889 'notifysuccess' => \core\output\notification::NOTIFY_SUCCESS,
2890 'notifymessage' => \core\output\notification::NOTIFY_INFO,
2891 'notifyredirect' => \core\output\notification::NOTIFY_INFO,
2892 'redirectmessage' => \core\output\notification::NOTIFY_INFO,
2895 $extraclasses = [];
2897 if ($type) {
2898 if (strpos($type, ' ') === false) {
2899 // No spaces in the list of classes, therefore no need to loop over and determine the class.
2900 if (isset($typemappings[$type])) {
2901 $type = $typemappings[$type];
2902 } else {
2903 // The value provided did not match a known type. It must be an extra class.
2904 $extraclasses = [$type];
2906 } else {
2907 // Identify what type of notification this is.
2908 $classarray = explode(' ', self::prepare_classes($type));
2910 // Separate out the type of notification from the extra classes.
2911 foreach ($classarray as $class) {
2912 if (isset($typemappings[$class])) {
2913 $type = $typemappings[$class];
2914 } else {
2915 $extraclasses[] = $class;
2921 $notification = new \core\output\notification($message, $type);
2922 if (count($extraclasses)) {
2923 $notification->set_extra_classes($extraclasses);
2926 // Return the rendered template.
2927 return $this->render_from_template($notification->get_template_name(), $notification->export_for_template($this));
2931 * @deprecated since Moodle 3.1 MDL-30811 - please do not use this function any more.
2933 public function notify_problem() {
2934 throw new coding_exception('core_renderer::notify_problem() can not be used any more, '.
2935 'please use \core\notification::add(), or \core\output\notification as required.');
2939 * @deprecated since Moodle 3.1 MDL-30811 - please do not use this function any more.
2941 public function notify_success() {
2942 throw new coding_exception('core_renderer::notify_success() can not be used any more, '.
2943 'please use \core\notification::add(), or \core\output\notification as required.');
2947 * @deprecated since Moodle 3.1 MDL-30811 - please do not use this function any more.
2949 public function notify_message() {
2950 throw new coding_exception('core_renderer::notify_message() can not be used any more, '.
2951 'please use \core\notification::add(), or \core\output\notification as required.');
2955 * @deprecated since Moodle 3.1 MDL-30811 - please do not use this function any more.
2957 public function notify_redirect() {
2958 throw new coding_exception('core_renderer::notify_redirect() can not be used any more, '.
2959 'please use \core\notification::add(), or \core\output\notification as required.');
2963 * Render a notification (that is, a status message about something that has
2964 * just happened).
2966 * @param \core\output\notification $notification the notification to print out
2967 * @return string the HTML to output.
2969 protected function render_notification(\core\output\notification $notification) {
2970 return $this->render_from_template($notification->get_template_name(), $notification->export_for_template($this));
2974 * Returns HTML to display a continue button that goes to a particular URL.
2976 * @param string|moodle_url $url The url the button goes to.
2977 * @return string the HTML to output.
2979 public function continue_button($url) {
2980 if (!($url instanceof moodle_url)) {
2981 $url = new moodle_url($url);
2983 $button = new single_button($url, get_string('continue'), 'get', true);
2984 $button->class = 'continuebutton';
2986 return $this->render($button);
2990 * Returns HTML to display a single paging bar to provide access to other pages (usually in a search)
2992 * Theme developers: DO NOT OVERRIDE! Please override function
2993 * {@link core_renderer::render_paging_bar()} instead.
2995 * @param int $totalcount The total number of entries available to be paged through
2996 * @param int $page The page you are currently viewing
2997 * @param int $perpage The number of entries that should be shown per page
2998 * @param string|moodle_url $baseurl url of the current page, the $pagevar parameter is added
2999 * @param string $pagevar name of page parameter that holds the page number
3000 * @return string the HTML to output.
3002 public function paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar = 'page') {
3003 $pb = new paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar);
3004 return $this->render($pb);
3008 * Internal implementation of paging bar rendering.
3010 * @param paging_bar $pagingbar
3011 * @return string
3013 protected function render_paging_bar(paging_bar $pagingbar) {
3014 $output = '';
3015 $pagingbar = clone($pagingbar);
3016 $pagingbar->prepare($this, $this->page, $this->target);
3018 if ($pagingbar->totalcount > $pagingbar->perpage) {
3019 $output .= get_string('page') . ':';
3021 if (!empty($pagingbar->previouslink)) {
3022 $output .= ' (' . $pagingbar->previouslink . ') ';
3025 if (!empty($pagingbar->firstlink)) {
3026 $output .= ' ' . $pagingbar->firstlink . ' ...';
3029 foreach ($pagingbar->pagelinks as $link) {
3030 $output .= " $link";
3033 if (!empty($pagingbar->lastlink)) {
3034 $output .= ' ... ' . $pagingbar->lastlink . ' ';
3037 if (!empty($pagingbar->nextlink)) {
3038 $output .= ' (' . $pagingbar->nextlink . ')';
3042 return html_writer::tag('div', $output, array('class' => 'paging'));
3046 * Returns HTML to display initials bar to provide access to other pages (usually in a search)
3048 * @param string $current the currently selected letter.
3049 * @param string $class class name to add to this initial bar.
3050 * @param string $title the name to put in front of this initial bar.
3051 * @param string $urlvar URL parameter name for this initial.
3052 * @param string $url URL object.
3053 * @param array $alpha of letters in the alphabet.
3054 * @return string the HTML to output.
3056 public function initials_bar($current, $class, $title, $urlvar, $url, $alpha = null) {
3057 $ib = new initials_bar($current, $class, $title, $urlvar, $url, $alpha);
3058 return $this->render($ib);
3062 * Internal implementation of initials bar rendering.
3064 * @param initials_bar $initialsbar
3065 * @return string
3067 protected function render_initials_bar(initials_bar $initialsbar) {
3068 return $this->render_from_template('core/initials_bar', $initialsbar->export_for_template($this));
3072 * Output the place a skip link goes to.
3074 * @param string $id The target name from the corresponding $PAGE->requires->skip_link_to($target) call.
3075 * @return string the HTML to output.
3077 public function skip_link_target($id = null) {
3078 return html_writer::span('', '', array('id' => $id));
3082 * Outputs a heading
3084 * @param string $text The text of the heading
3085 * @param int $level The level of importance of the heading. Defaulting to 2
3086 * @param string $classes A space-separated list of CSS classes. Defaulting to null
3087 * @param string $id An optional ID
3088 * @return string the HTML to output.
3090 public function heading($text, $level = 2, $classes = null, $id = null) {
3091 $level = (integer) $level;
3092 if ($level < 1 or $level > 6) {
3093 throw new coding_exception('Heading level must be an integer between 1 and 6.');
3095 return html_writer::tag('h' . $level, $text, array('id' => $id, 'class' => renderer_base::prepare_classes($classes)));
3099 * Outputs a box.
3101 * @param string $contents The contents of the box
3102 * @param string $classes A space-separated list of CSS classes
3103 * @param string $id An optional ID
3104 * @param array $attributes An array of other attributes to give the box.
3105 * @return string the HTML to output.
3107 public function box($contents, $classes = 'generalbox', $id = null, $attributes = array()) {
3108 return $this->box_start($classes, $id, $attributes) . $contents . $this->box_end();
3112 * Outputs the opening section of a box.
3114 * @param string $classes A space-separated list of CSS classes
3115 * @param string $id An optional ID
3116 * @param array $attributes An array of other attributes to give the box.
3117 * @return string the HTML to output.
3119 public function box_start($classes = 'generalbox', $id = null, $attributes = array()) {
3120 $this->opencontainers->push('box', html_writer::end_tag('div'));
3121 $attributes['id'] = $id;
3122 $attributes['class'] = 'box ' . renderer_base::prepare_classes($classes);
3123 return html_writer::start_tag('div', $attributes);
3127 * Outputs the closing section of a box.
3129 * @return string the HTML to output.
3131 public function box_end() {
3132 return $this->opencontainers->pop('box');
3136 * Outputs a container.
3138 * @param string $contents The contents of the box
3139 * @param string $classes A space-separated list of CSS classes
3140 * @param string $id An optional ID
3141 * @return string the HTML to output.
3143 public function container($contents, $classes = null, $id = null) {
3144 return $this->container_start($classes, $id) . $contents . $this->container_end();
3148 * Outputs the opening section of a container.
3150 * @param string $classes A space-separated list of CSS classes
3151 * @param string $id An optional ID
3152 * @return string the HTML to output.
3154 public function container_start($classes = null, $id = null) {
3155 $this->opencontainers->push('container', html_writer::end_tag('div'));
3156 return html_writer::start_tag('div', array('id' => $id,
3157 'class' => renderer_base::prepare_classes($classes)));
3161 * Outputs the closing section of a container.
3163 * @return string the HTML to output.
3165 public function container_end() {
3166 return $this->opencontainers->pop('container');
3170 * Make nested HTML lists out of the items
3172 * The resulting list will look something like this:
3174 * <pre>
3175 * <<ul>>
3176 * <<li>><div class='tree_item parent'>(item contents)</div>
3177 * <<ul>
3178 * <<li>><div class='tree_item'>(item contents)</div><</li>>
3179 * <</ul>>
3180 * <</li>>
3181 * <</ul>>
3182 * </pre>
3184 * @param array $items
3185 * @param array $attrs html attributes passed to the top ofs the list
3186 * @return string HTML
3188 public function tree_block_contents($items, $attrs = array()) {
3189 // exit if empty, we don't want an empty ul element
3190 if (empty($items)) {
3191 return '';
3193 // array of nested li elements
3194 $lis = array();
3195 foreach ($items as $item) {
3196 // this applies to the li item which contains all child lists too
3197 $content = $item->content($this);
3198 $liclasses = array($item->get_css_type());
3199 if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count()==0 && $item->nodetype==navigation_node::NODETYPE_BRANCH)) {
3200 $liclasses[] = 'collapsed';
3202 if ($item->isactive === true) {
3203 $liclasses[] = 'current_branch';
3205 $liattr = array('class'=>join(' ',$liclasses));
3206 // class attribute on the div item which only contains the item content
3207 $divclasses = array('tree_item');
3208 if ($item->children->count()>0 || $item->nodetype==navigation_node::NODETYPE_BRANCH) {
3209 $divclasses[] = 'branch';
3210 } else {
3211 $divclasses[] = 'leaf';
3213 if (!empty($item->classes) && count($item->classes)>0) {
3214 $divclasses[] = join(' ', $item->classes);
3216 $divattr = array('class'=>join(' ', $divclasses));
3217 if (!empty($item->id)) {
3218 $divattr['id'] = $item->id;
3220 $content = html_writer::tag('p', $content, $divattr) . $this->tree_block_contents($item->children);
3221 if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
3222 $content = html_writer::empty_tag('hr') . $content;
3224 $content = html_writer::tag('li', $content, $liattr);
3225 $lis[] = $content;
3227 return html_writer::tag('ul', implode("\n", $lis), $attrs);
3231 * Returns a search box.
3233 * @param string $id The search box wrapper div id, defaults to an autogenerated one.
3234 * @return string HTML with the search form hidden by default.
3236 public function search_box($id = false) {
3237 global $CFG;
3239 // Accessing $CFG directly as using \core_search::is_global_search_enabled would
3240 // result in an extra included file for each site, even the ones where global search
3241 // is disabled.
3242 if (empty($CFG->enableglobalsearch) || !has_capability('moodle/search:query', context_system::instance())) {
3243 return '';
3246 if ($id == false) {
3247 $id = uniqid();
3248 } else {
3249 // Needs to be cleaned, we use it for the input id.
3250 $id = clean_param($id, PARAM_ALPHANUMEXT);
3253 // JS to animate the form.
3254 $this->page->requires->js_call_amd('core/search-input', 'init', array($id));
3256 $searchicon = html_writer::tag('div', $this->pix_icon('a/search', get_string('search', 'search'), 'moodle'),
3257 array('role' => 'button', 'tabindex' => 0));
3258 $formattrs = array('class' => 'search-input-form', 'action' => $CFG->wwwroot . '/search/index.php');
3259 $inputattrs = array('type' => 'text', 'name' => 'q', 'placeholder' => get_string('search', 'search'),
3260 'size' => 13, 'tabindex' => -1, 'id' => 'id_q_' . $id, 'class' => 'form-control');
3262 $contents = html_writer::tag('label', get_string('enteryoursearchquery', 'search'),
3263 array('for' => 'id_q_' . $id, 'class' => 'accesshide')) . html_writer::tag('input', '', $inputattrs);
3264 if ($this->page->context && $this->page->context->contextlevel !== CONTEXT_SYSTEM) {
3265 $contents .= html_writer::empty_tag('input', ['type' => 'hidden',
3266 'name' => 'context', 'value' => $this->page->context->id]);
3268 $searchinput = html_writer::tag('form', $contents, $formattrs);
3270 return html_writer::tag('div', $searchicon . $searchinput, array('class' => 'search-input-wrapper nav-link', 'id' => $id));
3274 * Allow plugins to provide some content to be rendered in the navbar.
3275 * The plugin must define a PLUGIN_render_navbar_output function that returns
3276 * the HTML they wish to add to the navbar.
3278 * @return string HTML for the navbar
3280 public function navbar_plugin_output() {
3281 $output = '';
3283 if ($pluginsfunction = get_plugins_with_function('render_navbar_output')) {
3284 foreach ($pluginsfunction as $plugintype => $plugins) {
3285 foreach ($plugins as $pluginfunction) {
3286 $output .= $pluginfunction($this);
3291 return $output;
3295 * Construct a user menu, returning HTML that can be echoed out by a
3296 * layout file.
3298 * @param stdClass $user A user object, usually $USER.
3299 * @param bool $withlinks true if a dropdown should be built.
3300 * @return string HTML fragment.
3302 public function user_menu($user = null, $withlinks = null) {
3303 global $USER, $CFG;
3304 require_once($CFG->dirroot . '/user/lib.php');
3306 if (is_null($user)) {
3307 $user = $USER;
3310 // Note: this behaviour is intended to match that of core_renderer::login_info,
3311 // but should not be considered to be good practice; layout options are
3312 // intended to be theme-specific. Please don't copy this snippet anywhere else.
3313 if (is_null($withlinks)) {
3314 $withlinks = empty($this->page->layout_options['nologinlinks']);
3317 // Add a class for when $withlinks is false.
3318 $usermenuclasses = 'usermenu';
3319 if (!$withlinks) {
3320 $usermenuclasses .= ' withoutlinks';
3323 $returnstr = "";
3325 // If during initial install, return the empty return string.
3326 if (during_initial_install()) {
3327 return $returnstr;
3330 $loginpage = $this->is_login_page();
3331 $loginurl = get_login_url();
3332 // If not logged in, show the typical not-logged-in string.
3333 if (!isloggedin()) {
3334 $returnstr = get_string('loggedinnot', 'moodle');
3335 if (!$loginpage) {
3336 $returnstr .= " (<a href=\"$loginurl\">" . get_string('login') . '</a>)';
3338 return html_writer::div(
3339 html_writer::span(
3340 $returnstr,
3341 'login'
3343 $usermenuclasses
3348 // If logged in as a guest user, show a string to that effect.
3349 if (isguestuser()) {
3350 $returnstr = get_string('loggedinasguest');
3351 if (!$loginpage && $withlinks) {
3352 $returnstr .= " (<a href=\"$loginurl\">".get_string('login').'</a>)';
3355 return html_writer::div(
3356 html_writer::span(
3357 $returnstr,
3358 'login'
3360 $usermenuclasses
3364 // Get some navigation opts.
3365 $opts = user_get_user_navigation_info($user, $this->page);
3367 $avatarclasses = "avatars";
3368 $avatarcontents = html_writer::span($opts->metadata['useravatar'], 'avatar current');
3369 $usertextcontents = $opts->metadata['userfullname'];
3371 // Other user.
3372 if (!empty($opts->metadata['asotheruser'])) {
3373 $avatarcontents .= html_writer::span(
3374 $opts->metadata['realuseravatar'],
3375 'avatar realuser'
3377 $usertextcontents = $opts->metadata['realuserfullname'];
3378 $usertextcontents .= html_writer::tag(
3379 'span',
3380 get_string(
3381 'loggedinas',
3382 'moodle',
3383 html_writer::span(
3384 $opts->metadata['userfullname'],
3385 'value'
3388 array('class' => 'meta viewingas')
3392 // Role.
3393 if (!empty($opts->metadata['asotherrole'])) {
3394 $role = core_text::strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['rolename'])));
3395 $usertextcontents .= html_writer::span(
3396 $opts->metadata['rolename'],
3397 'meta role role-' . $role
3401 // User login failures.
3402 if (!empty($opts->metadata['userloginfail'])) {
3403 $usertextcontents .= html_writer::span(
3404 $opts->metadata['userloginfail'],
3405 'meta loginfailures'
3409 // MNet.
3410 if (!empty($opts->metadata['asmnetuser'])) {
3411 $mnet = strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['mnetidprovidername'])));
3412 $usertextcontents .= html_writer::span(
3413 $opts->metadata['mnetidprovidername'],
3414 'meta mnet mnet-' . $mnet
3418 $returnstr .= html_writer::span(
3419 html_writer::span($usertextcontents, 'usertext mr-1') .
3420 html_writer::span($avatarcontents, $avatarclasses),
3421 'userbutton'
3424 // Create a divider (well, a filler).
3425 $divider = new action_menu_filler();
3426 $divider->primary = false;
3428 $am = new action_menu();
3429 $am->set_menu_trigger(
3430 $returnstr
3432 $am->set_action_label(get_string('usermenu'));
3433 $am->set_alignment(action_menu::TR, action_menu::BR);
3434 $am->set_nowrap_on_items();
3435 if ($withlinks) {
3436 $navitemcount = count($opts->navitems);
3437 $idx = 0;
3438 foreach ($opts->navitems as $key => $value) {
3440 switch ($value->itemtype) {
3441 case 'divider':
3442 // If the nav item is a divider, add one and skip link processing.
3443 $am->add($divider);
3444 break;
3446 case 'invalid':
3447 // Silently skip invalid entries (should we post a notification?).
3448 break;
3450 case 'link':
3451 // Process this as a link item.
3452 $pix = null;
3453 if (isset($value->pix) && !empty($value->pix)) {
3454 $pix = new pix_icon($value->pix, '', null, array('class' => 'iconsmall'));
3455 } else if (isset($value->imgsrc) && !empty($value->imgsrc)) {
3456 $value->title = html_writer::img(
3457 $value->imgsrc,
3458 $value->title,
3459 array('class' => 'iconsmall')
3460 ) . $value->title;
3463 $al = new action_menu_link_secondary(
3464 $value->url,
3465 $pix,
3466 $value->title,
3467 array('class' => 'icon')
3469 if (!empty($value->titleidentifier)) {
3470 $al->attributes['data-title'] = $value->titleidentifier;
3472 $am->add($al);
3473 break;
3476 $idx++;
3478 // Add dividers after the first item and before the last item.
3479 if ($idx == 1 || $idx == $navitemcount - 1) {
3480 $am->add($divider);
3485 return html_writer::div(
3486 $this->render($am),
3487 $usermenuclasses
3492 * Return the navbar content so that it can be echoed out by the layout
3494 * @return string XHTML navbar
3496 public function navbar() {
3497 $items = $this->page->navbar->get_items();
3498 $itemcount = count($items);
3499 if ($itemcount === 0) {
3500 return '';
3503 $htmlblocks = array();
3504 // Iterate the navarray and display each node
3505 $separator = get_separator();
3506 for ($i=0;$i < $itemcount;$i++) {
3507 $item = $items[$i];
3508 $item->hideicon = true;
3509 if ($i===0) {
3510 $content = html_writer::tag('li', $this->render($item));
3511 } else {
3512 $content = html_writer::tag('li', $separator.$this->render($item));
3514 $htmlblocks[] = $content;
3517 //accessibility: heading for navbar list (MDL-20446)
3518 $navbarcontent = html_writer::tag('span', get_string('pagepath'),
3519 array('class' => 'accesshide', 'id' => 'navbar-label'));
3520 $navbarcontent .= html_writer::tag('nav',
3521 html_writer::tag('ul', join('', $htmlblocks)),
3522 array('aria-labelledby' => 'navbar-label'));
3523 // XHTML
3524 return $navbarcontent;
3528 * Renders a breadcrumb navigation node object.
3530 * @param breadcrumb_navigation_node $item The navigation node to render.
3531 * @return string HTML fragment
3533 protected function render_breadcrumb_navigation_node(breadcrumb_navigation_node $item) {
3535 if ($item->action instanceof moodle_url) {
3536 $content = $item->get_content();
3537 $title = $item->get_title();
3538 $attributes = array();
3539 $attributes['itemprop'] = 'url';
3540 if ($title !== '') {
3541 $attributes['title'] = $title;
3543 if ($item->hidden) {
3544 $attributes['class'] = 'dimmed_text';
3546 if ($item->is_last()) {
3547 $attributes['aria-current'] = 'page';
3549 $content = html_writer::tag('span', $content, array('itemprop' => 'title'));
3550 $content = html_writer::link($item->action, $content, $attributes);
3552 $attributes = array();
3553 $attributes['itemscope'] = '';
3554 $attributes['itemtype'] = 'http://data-vocabulary.org/Breadcrumb';
3555 $content = html_writer::tag('span', $content, $attributes);
3557 } else {
3558 $content = $this->render_navigation_node($item);
3560 return $content;
3564 * Renders a navigation node object.
3566 * @param navigation_node $item The navigation node to render.
3567 * @return string HTML fragment
3569 protected function render_navigation_node(navigation_node $item) {
3570 $content = $item->get_content();
3571 $title = $item->get_title();
3572 if ($item->icon instanceof renderable && !$item->hideicon) {
3573 $icon = $this->render($item->icon);
3574 $content = $icon.$content; // use CSS for spacing of icons
3576 if ($item->helpbutton !== null) {
3577 $content = trim($item->helpbutton).html_writer::tag('span', $content, array('class'=>'clearhelpbutton', 'tabindex'=>'0'));
3579 if ($content === '') {
3580 return '';
3582 if ($item->action instanceof action_link) {
3583 $link = $item->action;
3584 if ($item->hidden) {
3585 $link->add_class('dimmed');
3587 if (!empty($content)) {
3588 // Providing there is content we will use that for the link content.
3589 $link->text = $content;
3591 $content = $this->render($link);
3592 } else if ($item->action instanceof moodle_url) {
3593 $attributes = array();
3594 if ($title !== '') {
3595 $attributes['title'] = $title;
3597 if ($item->hidden) {
3598 $attributes['class'] = 'dimmed_text';
3600 $content = html_writer::link($item->action, $content, $attributes);
3602 } else if (is_string($item->action) || empty($item->action)) {
3603 $attributes = array('tabindex'=>'0'); //add tab support to span but still maintain character stream sequence.
3604 if ($title !== '') {
3605 $attributes['title'] = $title;
3607 if ($item->hidden) {
3608 $attributes['class'] = 'dimmed_text';
3610 $content = html_writer::tag('span', $content, $attributes);
3612 return $content;
3616 * Accessibility: Right arrow-like character is
3617 * used in the breadcrumb trail, course navigation menu
3618 * (previous/next activity), calendar, and search forum block.
3619 * If the theme does not set characters, appropriate defaults
3620 * are set automatically. Please DO NOT
3621 * use &lt; &gt; &raquo; - these are confusing for blind users.
3623 * @return string
3625 public function rarrow() {
3626 return $this->page->theme->rarrow;
3630 * Accessibility: Left arrow-like character is
3631 * used in the breadcrumb trail, course navigation menu
3632 * (previous/next activity), calendar, and search forum block.
3633 * If the theme does not set characters, appropriate defaults
3634 * are set automatically. Please DO NOT
3635 * use &lt; &gt; &raquo; - these are confusing for blind users.
3637 * @return string
3639 public function larrow() {
3640 return $this->page->theme->larrow;
3644 * Accessibility: Up arrow-like character is used in
3645 * the book heirarchical navigation.
3646 * If the theme does not set characters, appropriate defaults
3647 * are set automatically. Please DO NOT
3648 * use ^ - this is confusing for blind users.
3650 * @return string
3652 public function uarrow() {
3653 return $this->page->theme->uarrow;
3657 * Accessibility: Down arrow-like character.
3658 * If the theme does not set characters, appropriate defaults
3659 * are set automatically.
3661 * @return string
3663 public function darrow() {
3664 return $this->page->theme->darrow;
3668 * Returns the custom menu if one has been set
3670 * A custom menu can be configured by browsing to
3671 * Settings: Administration > Appearance > Themes > Theme settings
3672 * and then configuring the custommenu config setting as described.
3674 * Theme developers: DO NOT OVERRIDE! Please override function
3675 * {@link core_renderer::render_custom_menu()} instead.
3677 * @param string $custommenuitems - custom menuitems set by theme instead of global theme settings
3678 * @return string
3680 public function custom_menu($custommenuitems = '') {
3681 global $CFG;
3682 if (empty($custommenuitems) && !empty($CFG->custommenuitems)) {
3683 $custommenuitems = $CFG->custommenuitems;
3685 if (empty($custommenuitems)) {
3686 return '';
3688 $custommenu = new custom_menu($custommenuitems, current_language());
3689 return $this->render($custommenu);
3693 * Renders a custom menu object (located in outputcomponents.php)
3695 * The custom menu this method produces makes use of the YUI3 menunav widget
3696 * and requires very specific html elements and classes.
3698 * @staticvar int $menucount
3699 * @param custom_menu $menu
3700 * @return string
3702 protected function render_custom_menu(custom_menu $menu) {
3703 static $menucount = 0;
3704 // If the menu has no children return an empty string
3705 if (!$menu->has_children()) {
3706 return '';
3708 // Increment the menu count. This is used for ID's that get worked with
3709 // in JavaScript as is essential
3710 $menucount++;
3711 // Initialise this custom menu (the custom menu object is contained in javascript-static
3712 $jscode = js_writer::function_call_with_Y('M.core_custom_menu.init', array('custom_menu_'.$menucount));
3713 $jscode = "(function(){{$jscode}})";
3714 $this->page->requires->yui_module('node-menunav', $jscode);
3715 // Build the root nodes as required by YUI
3716 $content = html_writer::start_tag('div', array('id'=>'custom_menu_'.$menucount, 'class'=>'yui3-menu yui3-menu-horizontal javascript-disabled custom-menu'));
3717 $content .= html_writer::start_tag('div', array('class'=>'yui3-menu-content'));
3718 $content .= html_writer::start_tag('ul');
3719 // Render each child
3720 foreach ($menu->get_children() as $item) {
3721 $content .= $this->render_custom_menu_item($item);
3723 // Close the open tags
3724 $content .= html_writer::end_tag('ul');
3725 $content .= html_writer::end_tag('div');
3726 $content .= html_writer::end_tag('div');
3727 // Return the custom menu
3728 return $content;
3732 * Renders a custom menu node as part of a submenu
3734 * The custom menu this method produces makes use of the YUI3 menunav widget
3735 * and requires very specific html elements and classes.
3737 * @see core:renderer::render_custom_menu()
3739 * @staticvar int $submenucount
3740 * @param custom_menu_item $menunode
3741 * @return string
3743 protected function render_custom_menu_item(custom_menu_item $menunode) {
3744 // Required to ensure we get unique trackable id's
3745 static $submenucount = 0;
3746 if ($menunode->has_children()) {
3747 // If the child has menus render it as a sub menu
3748 $submenucount++;
3749 $content = html_writer::start_tag('li');
3750 if ($menunode->get_url() !== null) {
3751 $url = $menunode->get_url();
3752 } else {
3753 $url = '#cm_submenu_'.$submenucount;
3755 $content .= html_writer::link($url, $menunode->get_text(), array('class'=>'yui3-menu-label', 'title'=>$menunode->get_title()));
3756 $content .= html_writer::start_tag('div', array('id'=>'cm_submenu_'.$submenucount, 'class'=>'yui3-menu custom_menu_submenu'));
3757 $content .= html_writer::start_tag('div', array('class'=>'yui3-menu-content'));
3758 $content .= html_writer::start_tag('ul');
3759 foreach ($menunode->get_children() as $menunode) {
3760 $content .= $this->render_custom_menu_item($menunode);
3762 $content .= html_writer::end_tag('ul');
3763 $content .= html_writer::end_tag('div');
3764 $content .= html_writer::end_tag('div');
3765 $content .= html_writer::end_tag('li');
3766 } else {
3767 // The node doesn't have children so produce a final menuitem.
3768 // Also, if the node's text matches '####', add a class so we can treat it as a divider.
3769 $content = '';
3770 if (preg_match("/^#+$/", $menunode->get_text())) {
3772 // This is a divider.
3773 $content = html_writer::start_tag('li', array('class' => 'yui3-menuitem divider'));
3774 } else {
3775 $content = html_writer::start_tag(
3776 'li',
3777 array(
3778 'class' => 'yui3-menuitem'
3781 if ($menunode->get_url() !== null) {
3782 $url = $menunode->get_url();
3783 } else {
3784 $url = '#';
3786 $content .= html_writer::link(
3787 $url,
3788 $menunode->get_text(),
3789 array('class' => 'yui3-menuitem-content', 'title' => $menunode->get_title())
3792 $content .= html_writer::end_tag('li');
3794 // Return the sub menu
3795 return $content;
3799 * Renders theme links for switching between default and other themes.
3801 * @return string
3803 protected function theme_switch_links() {
3805 $actualdevice = core_useragent::get_device_type();
3806 $currentdevice = $this->page->devicetypeinuse;
3807 $switched = ($actualdevice != $currentdevice);
3809 if (!$switched && $currentdevice == 'default' && $actualdevice == 'default') {
3810 // The user is using the a default device and hasn't switched so don't shown the switch
3811 // device links.
3812 return '';
3815 if ($switched) {
3816 $linktext = get_string('switchdevicerecommended');
3817 $devicetype = $actualdevice;
3818 } else {
3819 $linktext = get_string('switchdevicedefault');
3820 $devicetype = 'default';
3822 $linkurl = new moodle_url('/theme/switchdevice.php', array('url' => $this->page->url, 'device' => $devicetype, 'sesskey' => sesskey()));
3824 $content = html_writer::start_tag('div', array('id' => 'theme_switch_link'));
3825 $content .= html_writer::link($linkurl, $linktext, array('rel' => 'nofollow'));
3826 $content .= html_writer::end_tag('div');
3828 return $content;
3832 * Renders tabs
3834 * This function replaces print_tabs() used before Moodle 2.5 but with slightly different arguments
3836 * Theme developers: In order to change how tabs are displayed please override functions
3837 * {@link core_renderer::render_tabtree()} and/or {@link core_renderer::render_tabobject()}
3839 * @param array $tabs array of tabs, each of them may have it's own ->subtree
3840 * @param string|null $selected which tab to mark as selected, all parent tabs will
3841 * automatically be marked as activated
3842 * @param array|string|null $inactive list of ids of inactive tabs, regardless of
3843 * their level. Note that you can as weel specify tabobject::$inactive for separate instances
3844 * @return string
3846 public final function tabtree($tabs, $selected = null, $inactive = null) {
3847 return $this->render(new tabtree($tabs, $selected, $inactive));
3851 * Renders tabtree
3853 * @param tabtree $tabtree
3854 * @return string
3856 protected function render_tabtree(tabtree $tabtree) {
3857 if (empty($tabtree->subtree)) {
3858 return '';
3860 $str = '';
3861 $str .= html_writer::start_tag('div', array('class' => 'tabtree'));
3862 $str .= $this->render_tabobject($tabtree);
3863 $str .= html_writer::end_tag('div').
3864 html_writer::tag('div', ' ', array('class' => 'clearer'));
3865 return $str;
3869 * Renders tabobject (part of tabtree)
3871 * This function is called from {@link core_renderer::render_tabtree()}
3872 * and also it calls itself when printing the $tabobject subtree recursively.
3874 * Property $tabobject->level indicates the number of row of tabs.
3876 * @param tabobject $tabobject
3877 * @return string HTML fragment
3879 protected function render_tabobject(tabobject $tabobject) {
3880 $str = '';
3882 // Print name of the current tab.
3883 if ($tabobject instanceof tabtree) {
3884 // No name for tabtree root.
3885 } else if ($tabobject->inactive || $tabobject->activated || ($tabobject->selected && !$tabobject->linkedwhenselected)) {
3886 // Tab name without a link. The <a> tag is used for styling.
3887 $str .= html_writer::tag('a', html_writer::span($tabobject->text), array('class' => 'nolink moodle-has-zindex'));
3888 } else {
3889 // Tab name with a link.
3890 if (!($tabobject->link instanceof moodle_url)) {
3891 // backward compartibility when link was passed as quoted string
3892 $str .= "<a href=\"$tabobject->link\" title=\"$tabobject->title\"><span>$tabobject->text</span></a>";
3893 } else {
3894 $str .= html_writer::link($tabobject->link, html_writer::span($tabobject->text), array('title' => $tabobject->title));
3898 if (empty($tabobject->subtree)) {
3899 if ($tabobject->selected) {
3900 $str .= html_writer::tag('div', '&nbsp;', array('class' => 'tabrow'. ($tabobject->level + 1). ' empty'));
3902 return $str;
3905 // Print subtree.
3906 if ($tabobject->level == 0 || $tabobject->selected || $tabobject->activated) {
3907 $str .= html_writer::start_tag('ul', array('class' => 'tabrow'. $tabobject->level));
3908 $cnt = 0;
3909 foreach ($tabobject->subtree as $tab) {
3910 $liclass = '';
3911 if (!$cnt) {
3912 $liclass .= ' first';
3914 if ($cnt == count($tabobject->subtree) - 1) {
3915 $liclass .= ' last';
3917 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3918 $liclass .= ' onerow';
3921 if ($tab->selected) {
3922 $liclass .= ' here selected';
3923 } else if ($tab->activated) {
3924 $liclass .= ' here active';
3927 // This will recursively call function render_tabobject() for each item in subtree.
3928 $str .= html_writer::tag('li', $this->render($tab), array('class' => trim($liclass)));
3929 $cnt++;
3931 $str .= html_writer::end_tag('ul');
3934 return $str;
3938 * Get the HTML for blocks in the given region.
3940 * @since Moodle 2.5.1 2.6
3941 * @param string $region The region to get HTML for.
3942 * @return string HTML.
3944 public function blocks($region, $classes = array(), $tag = 'aside') {
3945 $displayregion = $this->page->apply_theme_region_manipulations($region);
3946 $classes = (array)$classes;
3947 $classes[] = 'block-region';
3948 $attributes = array(
3949 'id' => 'block-region-'.preg_replace('#[^a-zA-Z0-9_\-]+#', '-', $displayregion),
3950 'class' => join(' ', $classes),
3951 'data-blockregion' => $displayregion,
3952 'data-droptarget' => '1'
3954 if ($this->page->blocks->region_has_content($displayregion, $this)) {
3955 $content = $this->blocks_for_region($displayregion);
3956 } else {
3957 $content = '';
3959 return html_writer::tag($tag, $content, $attributes);
3963 * Renders a custom block region.
3965 * Use this method if you want to add an additional block region to the content of the page.
3966 * Please note this should only be used in special situations.
3967 * We want to leave the theme is control where ever possible!
3969 * This method must use the same method that the theme uses within its layout file.
3970 * As such it asks the theme what method it is using.
3971 * It can be one of two values, blocks or blocks_for_region (deprecated).
3973 * @param string $regionname The name of the custom region to add.
3974 * @return string HTML for the block region.
3976 public function custom_block_region($regionname) {
3977 if ($this->page->theme->get_block_render_method() === 'blocks') {
3978 return $this->blocks($regionname);
3979 } else {
3980 return $this->blocks_for_region($regionname);
3985 * Returns the CSS classes to apply to the body tag.
3987 * @since Moodle 2.5.1 2.6
3988 * @param array $additionalclasses Any additional classes to apply.
3989 * @return string
3991 public function body_css_classes(array $additionalclasses = array()) {
3992 // Add a class for each block region on the page.
3993 // We use the block manager here because the theme object makes get_string calls.
3994 $usedregions = array();
3995 foreach ($this->page->blocks->get_regions() as $region) {
3996 $additionalclasses[] = 'has-region-'.$region;
3997 if ($this->page->blocks->region_has_content($region, $this)) {
3998 $additionalclasses[] = 'used-region-'.$region;
3999 $usedregions[] = $region;
4000 } else {
4001 $additionalclasses[] = 'empty-region-'.$region;
4003 if ($this->page->blocks->region_completely_docked($region, $this)) {
4004 $additionalclasses[] = 'docked-region-'.$region;
4007 if (!$usedregions) {
4008 // No regions means there is only content, add 'content-only' class.
4009 $additionalclasses[] = 'content-only';
4010 } else if (count($usedregions) === 1) {
4011 // Add the -only class for the only used region.
4012 $region = array_shift($usedregions);
4013 $additionalclasses[] = $region . '-only';
4015 foreach ($this->page->layout_options as $option => $value) {
4016 if ($value) {
4017 $additionalclasses[] = 'layout-option-'.$option;
4020 $css = $this->page->bodyclasses .' '. join(' ', $additionalclasses);
4021 return $css;
4025 * The ID attribute to apply to the body tag.
4027 * @since Moodle 2.5.1 2.6
4028 * @return string
4030 public function body_id() {
4031 return $this->page->bodyid;
4035 * Returns HTML attributes to use within the body tag. This includes an ID and classes.
4037 * @since Moodle 2.5.1 2.6
4038 * @param string|array $additionalclasses Any additional classes to give the body tag,
4039 * @return string
4041 public function body_attributes($additionalclasses = array()) {
4042 if (!is_array($additionalclasses)) {
4043 $additionalclasses = explode(' ', $additionalclasses);
4045 return ' id="'. $this->body_id().'" class="'.$this->body_css_classes($additionalclasses).'"';
4049 * Gets HTML for the page heading.
4051 * @since Moodle 2.5.1 2.6
4052 * @param string $tag The tag to encase the heading in. h1 by default.
4053 * @return string HTML.
4055 public function page_heading($tag = 'h1') {
4056 return html_writer::tag($tag, $this->page->heading);
4060 * Gets the HTML for the page heading button.
4062 * @since Moodle 2.5.1 2.6
4063 * @return string HTML.
4065 public function page_heading_button() {
4066 return $this->page->button;
4070 * Returns the Moodle docs link to use for this page.
4072 * @since Moodle 2.5.1 2.6
4073 * @param string $text
4074 * @return string
4076 public function page_doc_link($text = null) {
4077 if ($text === null) {
4078 $text = get_string('moodledocslink');
4080 $path = page_get_doc_link_path($this->page);
4081 if (!$path) {
4082 return '';
4084 return $this->doc_link($path, $text);
4088 * Returns the page heading menu.
4090 * @since Moodle 2.5.1 2.6
4091 * @return string HTML.
4093 public function page_heading_menu() {
4094 return $this->page->headingmenu;
4098 * Returns the title to use on the page.
4100 * @since Moodle 2.5.1 2.6
4101 * @return string
4103 public function page_title() {
4104 return $this->page->title;
4108 * Returns the URL for the favicon.
4110 * @since Moodle 2.5.1 2.6
4111 * @return string The favicon URL
4113 public function favicon() {
4114 return $this->image_url('favicon', 'theme');
4118 * Renders preferences groups.
4120 * @param preferences_groups $renderable The renderable
4121 * @return string The output.
4123 public function render_preferences_groups(preferences_groups $renderable) {
4124 $html = '';
4125 $html .= html_writer::start_div('row-fluid');
4126 $html .= html_writer::start_tag('div', array('class' => 'span12 preferences-groups'));
4127 $i = 0;
4128 $open = false;
4129 foreach ($renderable->groups as $group) {
4130 if ($i == 0 || $i % 3 == 0) {
4131 if ($open) {
4132 $html .= html_writer::end_tag('div');
4134 $html .= html_writer::start_tag('div', array('class' => 'row-fluid'));
4135 $open = true;
4137 $html .= $this->render($group);
4138 $i++;
4141 $html .= html_writer::end_tag('div');
4143 $html .= html_writer::end_tag('ul');
4144 $html .= html_writer::end_tag('div');
4145 $html .= html_writer::end_div();
4146 return $html;
4150 * Renders preferences group.
4152 * @param preferences_group $renderable The renderable
4153 * @return string The output.
4155 public function render_preferences_group(preferences_group $renderable) {
4156 $html = '';
4157 $html .= html_writer::start_tag('div', array('class' => 'span4 preferences-group'));
4158 $html .= $this->heading($renderable->title, 3);
4159 $html .= html_writer::start_tag('ul');
4160 foreach ($renderable->nodes as $node) {
4161 if ($node->has_children()) {
4162 debugging('Preferences nodes do not support children', DEBUG_DEVELOPER);
4164 $html .= html_writer::tag('li', $this->render($node));
4166 $html .= html_writer::end_tag('ul');
4167 $html .= html_writer::end_tag('div');
4168 return $html;
4171 public function context_header($headerinfo = null, $headinglevel = 1) {
4172 global $DB, $USER, $CFG;
4173 require_once($CFG->dirroot . '/user/lib.php');
4174 $context = $this->page->context;
4175 $heading = null;
4176 $imagedata = null;
4177 $subheader = null;
4178 $userbuttons = null;
4179 // Make sure to use the heading if it has been set.
4180 if (isset($headerinfo['heading'])) {
4181 $heading = $headerinfo['heading'];
4183 // The user context currently has images and buttons. Other contexts may follow.
4184 if (isset($headerinfo['user']) || $context->contextlevel == CONTEXT_USER) {
4185 if (isset($headerinfo['user'])) {
4186 $user = $headerinfo['user'];
4187 } else {
4188 // Look up the user information if it is not supplied.
4189 $user = $DB->get_record('user', array('id' => $context->instanceid));
4192 // If the user context is set, then use that for capability checks.
4193 if (isset($headerinfo['usercontext'])) {
4194 $context = $headerinfo['usercontext'];
4197 // Only provide user information if the user is the current user, or a user which the current user can view.
4198 // When checking user_can_view_profile(), either:
4199 // If the page context is course, check the course context (from the page object) or;
4200 // If page context is NOT course, then check across all courses.
4201 $course = ($this->page->context->contextlevel == CONTEXT_COURSE) ? $this->page->course : null;
4203 if (user_can_view_profile($user, $course)) {
4204 // Use the user's full name if the heading isn't set.
4205 if (!isset($heading)) {
4206 $heading = fullname($user);
4209 $imagedata = $this->user_picture($user, array('size' => 100));
4211 // Check to see if we should be displaying a message button.
4212 if (!empty($CFG->messaging) && $USER->id != $user->id && has_capability('moodle/site:sendmessage', $context)) {
4213 $iscontact = !empty(message_get_contact($user->id));
4214 $contacttitle = $iscontact ? 'removefromyourcontacts' : 'addtoyourcontacts';
4215 $contacturlaction = $iscontact ? 'removecontact' : 'addcontact';
4216 $contactimage = $iscontact ? 'removecontact' : 'addcontact';
4217 $userbuttons = array(
4218 'messages' => array(
4219 'buttontype' => 'message',
4220 'title' => get_string('message', 'message'),
4221 'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
4222 'image' => 'message',
4223 'linkattributes' => array('role' => 'button'),
4224 'page' => $this->page
4226 'togglecontact' => array(
4227 'buttontype' => 'togglecontact',
4228 'title' => get_string($contacttitle, 'message'),
4229 'url' => new moodle_url('/message/index.php', array(
4230 'user1' => $USER->id,
4231 'user2' => $user->id,
4232 $contacturlaction => $user->id,
4233 'sesskey' => sesskey())
4235 'image' => $contactimage,
4236 'linkattributes' => \core_message\helper::togglecontact_link_params($user, $iscontact),
4237 'page' => $this->page
4241 $this->page->requires->string_for_js('changesmadereallygoaway', 'moodle');
4243 } else {
4244 $heading = null;
4248 $contextheader = new context_header($heading, $headinglevel, $imagedata, $userbuttons);
4249 return $this->render_context_header($contextheader);
4253 * Renders the skip links for the page.
4255 * @param array $links List of skip links.
4256 * @return string HTML for the skip links.
4258 public function render_skip_links($links) {
4259 $context = [ 'links' => []];
4261 foreach ($links as $url => $text) {
4262 $context['links'][] = [ 'url' => $url, 'text' => $text];
4265 return $this->render_from_template('core/skip_links', $context);
4269 * Renders the header bar.
4271 * @param context_header $contextheader Header bar object.
4272 * @return string HTML for the header bar.
4274 protected function render_context_header(context_header $contextheader) {
4276 // All the html stuff goes here.
4277 $html = html_writer::start_div('page-context-header');
4279 // Image data.
4280 if (isset($contextheader->imagedata)) {
4281 // Header specific image.
4282 $html .= html_writer::div($contextheader->imagedata, 'page-header-image');
4285 // Headings.
4286 if (!isset($contextheader->heading)) {
4287 $headings = $this->heading($this->page->heading, $contextheader->headinglevel);
4288 } else {
4289 $headings = $this->heading($contextheader->heading, $contextheader->headinglevel);
4292 $html .= html_writer::tag('div', $headings, array('class' => 'page-header-headings'));
4294 // Buttons.
4295 if (isset($contextheader->additionalbuttons)) {
4296 $html .= html_writer::start_div('btn-group header-button-group');
4297 foreach ($contextheader->additionalbuttons as $button) {
4298 if (!isset($button->page)) {
4299 // Include js for messaging.
4300 if ($button['buttontype'] === 'togglecontact') {
4301 \core_message\helper::togglecontact_requirejs();
4303 $image = $this->pix_icon($button['formattedimage'], $button['title'], 'moodle', array(
4304 'class' => 'iconsmall',
4305 'role' => 'presentation'
4307 $image .= html_writer::span($button['title'], 'header-button-title');
4308 } else {
4309 $image = html_writer::empty_tag('img', array(
4310 'src' => $button['formattedimage'],
4311 'role' => 'presentation'
4314 $html .= html_writer::link($button['url'], html_writer::tag('span', $image), $button['linkattributes']);
4316 $html .= html_writer::end_div();
4318 $html .= html_writer::end_div();
4320 return $html;
4324 * Wrapper for header elements.
4326 * @return string HTML to display the main header.
4328 public function full_header() {
4329 $html = html_writer::start_tag('header', array('id' => 'page-header', 'class' => 'clearfix'));
4330 $html .= $this->context_header();
4331 $html .= html_writer::start_div('clearfix', array('id' => 'page-navbar'));
4332 $html .= html_writer::tag('div', $this->navbar(), array('class' => 'breadcrumb-nav'));
4333 $html .= html_writer::div($this->page_heading_button(), 'breadcrumb-button');
4334 $html .= html_writer::end_div();
4335 $html .= html_writer::tag('div', $this->course_header(), array('id' => 'course-header'));
4336 $html .= html_writer::end_tag('header');
4337 return $html;
4341 * Displays the list of tags associated with an entry
4343 * @param array $tags list of instances of core_tag or stdClass
4344 * @param string $label label to display in front, by default 'Tags' (get_string('tags')), set to null
4345 * to use default, set to '' (empty string) to omit the label completely
4346 * @param string $classes additional classes for the enclosing div element
4347 * @param int $limit limit the number of tags to display, if size of $tags is more than this limit the "more" link
4348 * will be appended to the end, JS will toggle the rest of the tags
4349 * @param context $pagecontext specify if needed to overwrite the current page context for the view tag link
4350 * @return string
4352 public function tag_list($tags, $label = null, $classes = '', $limit = 10, $pagecontext = null) {
4353 $list = new \core_tag\output\taglist($tags, $label, $classes, $limit, $pagecontext);
4354 return $this->render_from_template('core_tag/taglist', $list->export_for_template($this));
4358 * Renders element for inline editing of any value
4360 * @param \core\output\inplace_editable $element
4361 * @return string
4363 public function render_inplace_editable(\core\output\inplace_editable $element) {
4364 return $this->render_from_template('core/inplace_editable', $element->export_for_template($this));
4368 * Renders a bar chart.
4370 * @param \core\chart_bar $chart The chart.
4371 * @return string.
4373 public function render_chart_bar(\core\chart_bar $chart) {
4374 return $this->render_chart($chart);
4378 * Renders a line chart.
4380 * @param \core\chart_line $chart The chart.
4381 * @return string.
4383 public function render_chart_line(\core\chart_line $chart) {
4384 return $this->render_chart($chart);
4388 * Renders a pie chart.
4390 * @param \core\chart_pie $chart The chart.
4391 * @return string.
4393 public function render_chart_pie(\core\chart_pie $chart) {
4394 return $this->render_chart($chart);
4398 * Renders a chart.
4400 * @param \core\chart_base $chart The chart.
4401 * @param bool $withtable Whether to include a data table with the chart.
4402 * @return string.
4404 public function render_chart(\core\chart_base $chart, $withtable = true) {
4405 $chartdata = json_encode($chart);
4406 return $this->render_from_template('core/chart', (object) [
4407 'chartdata' => $chartdata,
4408 'withtable' => $withtable
4413 * Renders the login form.
4415 * @param \core_auth\output\login $form The renderable.
4416 * @return string
4418 public function render_login(\core_auth\output\login $form) {
4419 $context = $form->export_for_template($this);
4421 // Override because rendering is not supported in template yet.
4422 $context->cookieshelpiconformatted = $this->help_icon('cookiesenabled');
4423 $context->errorformatted = $this->error_text($context->error);
4425 return $this->render_from_template('core/loginform', $context);
4429 * Renders an mform element from a template.
4431 * @param HTML_QuickForm_element $element element
4432 * @param bool $required if input is required field
4433 * @param bool $advanced if input is an advanced field
4434 * @param string $error error message to display
4435 * @param bool $ingroup True if this element is rendered as part of a group
4436 * @return mixed string|bool
4438 public function mform_element($element, $required, $advanced, $error, $ingroup) {
4439 $templatename = 'core_form/element-' . $element->getType();
4440 if ($ingroup) {
4441 $templatename .= "-inline";
4443 try {
4444 // We call this to generate a file not found exception if there is no template.
4445 // We don't want to call export_for_template if there is no template.
4446 core\output\mustache_template_finder::get_template_filepath($templatename);
4448 if ($element instanceof templatable) {
4449 $elementcontext = $element->export_for_template($this);
4451 $helpbutton = '';
4452 if (method_exists($element, 'getHelpButton')) {
4453 $helpbutton = $element->getHelpButton();
4455 $label = $element->getLabel();
4456 $text = '';
4457 if (method_exists($element, 'getText')) {
4458 // There currently exists code that adds a form element with an empty label.
4459 // If this is the case then set the label to the description.
4460 if (empty($label)) {
4461 $label = $element->getText();
4462 } else {
4463 $text = $element->getText();
4467 // Generate the form element wrapper ids and names to pass to the template.
4468 // This differs between group and non-group elements.
4469 if ($element->getType() === 'group') {
4470 // Group element.
4471 // The id will be something like 'fgroup_id_NAME'. E.g. fgroup_id_mygroup.
4472 $elementcontext['wrapperid'] = $elementcontext['id'];
4474 // Ensure group elements pass through the group name as the element name so the id_error_{{element.name}} is
4475 // properly set in the template.
4476 $elementcontext['name'] = $elementcontext['groupname'];
4477 } else {
4478 // Non grouped element.
4479 // Creates an id like 'fitem_id_NAME'. E.g. fitem_id_mytextelement.
4480 $elementcontext['wrapperid'] = 'fitem_' . $elementcontext['id'];
4483 $context = array(
4484 'element' => $elementcontext,
4485 'label' => $label,
4486 'text' => $text,
4487 'required' => $required,
4488 'advanced' => $advanced,
4489 'helpbutton' => $helpbutton,
4490 'error' => $error
4492 return $this->render_from_template($templatename, $context);
4494 } catch (Exception $e) {
4495 // No template for this element.
4496 return false;
4501 * Render the login signup form into a nice template for the theme.
4503 * @param mform $form
4504 * @return string
4506 public function render_login_signup_form($form) {
4507 $context = $form->export_for_template($this);
4509 return $this->render_from_template('core/signup_form_layout', $context);
4513 * Render the verify age and location page into a nice template for the theme.
4515 * @param \core_auth\output\verify_age_location_page $page The renderable
4516 * @return string
4518 protected function render_verify_age_location_page($page) {
4519 $context = $page->export_for_template($this);
4521 return $this->render_from_template('core/auth_verify_age_location_page', $context);
4525 * Render the digital minor contact information page into a nice template for the theme.
4527 * @param \core_auth\output\digital_minor_page $page The renderable
4528 * @return string
4530 protected function render_digital_minor_page($page) {
4531 $context = $page->export_for_template($this);
4533 return $this->render_from_template('core/auth_digital_minor_page', $context);
4537 * Renders a progress bar.
4539 * Do not use $OUTPUT->render($bar), instead use progress_bar::create().
4541 * @param progress_bar $bar The bar.
4542 * @return string HTML fragment
4544 public function render_progress_bar(progress_bar $bar) {
4545 global $PAGE;
4546 $data = $bar->export_for_template($this);
4547 return $this->render_from_template('core/progress_bar', $data);
4552 * A renderer that generates output for command-line scripts.
4554 * The implementation of this renderer is probably incomplete.
4556 * @copyright 2009 Tim Hunt
4557 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4558 * @since Moodle 2.0
4559 * @package core
4560 * @category output
4562 class core_renderer_cli extends core_renderer {
4565 * Returns the page header.
4567 * @return string HTML fragment
4569 public function header() {
4570 return $this->page->heading . "\n";
4574 * Returns a template fragment representing a Heading.
4576 * @param string $text The text of the heading
4577 * @param int $level The level of importance of the heading
4578 * @param string $classes A space-separated list of CSS classes
4579 * @param string $id An optional ID
4580 * @return string A template fragment for a heading
4582 public function heading($text, $level = 2, $classes = 'main', $id = null) {
4583 $text .= "\n";
4584 switch ($level) {
4585 case 1:
4586 return '=>' . $text;
4587 case 2:
4588 return '-->' . $text;
4589 default:
4590 return $text;
4595 * Returns a template fragment representing a fatal error.
4597 * @param string $message The message to output
4598 * @param string $moreinfourl URL where more info can be found about the error
4599 * @param string $link Link for the Continue button
4600 * @param array $backtrace The execution backtrace
4601 * @param string $debuginfo Debugging information
4602 * @return string A template fragment for a fatal error
4604 public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null, $errorcode = "") {
4605 global $CFG;
4607 $output = "!!! $message !!!\n";
4609 if ($CFG->debugdeveloper) {
4610 if (!empty($debuginfo)) {
4611 $output .= $this->notification($debuginfo, 'notifytiny');
4613 if (!empty($backtrace)) {
4614 $output .= $this->notification('Stack trace: ' . format_backtrace($backtrace, true), 'notifytiny');
4618 return $output;
4622 * Returns a template fragment representing a notification.
4624 * @param string $message The message to print out.
4625 * @param string $type The type of notification. See constants on \core\output\notification.
4626 * @return string A template fragment for a notification
4628 public function notification($message, $type = null) {
4629 $message = clean_text($message);
4630 if ($type === 'notifysuccess' || $type === 'success') {
4631 return "++ $message ++\n";
4633 return "!! $message !!\n";
4637 * There is no footer for a cli request, however we must override the
4638 * footer method to prevent the default footer.
4640 public function footer() {}
4643 * Render a notification (that is, a status message about something that has
4644 * just happened).
4646 * @param \core\output\notification $notification the notification to print out
4647 * @return string plain text output
4649 public function render_notification(\core\output\notification $notification) {
4650 return $this->notification($notification->get_message(), $notification->get_message_type());
4656 * A renderer that generates output for ajax scripts.
4658 * This renderer prevents accidental sends back only json
4659 * encoded error messages, all other output is ignored.
4661 * @copyright 2010 Petr Skoda
4662 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4663 * @since Moodle 2.0
4664 * @package core
4665 * @category output
4667 class core_renderer_ajax extends core_renderer {
4670 * Returns a template fragment representing a fatal error.
4672 * @param string $message The message to output
4673 * @param string $moreinfourl URL where more info can be found about the error
4674 * @param string $link Link for the Continue button
4675 * @param array $backtrace The execution backtrace
4676 * @param string $debuginfo Debugging information
4677 * @return string A template fragment for a fatal error
4679 public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null, $errorcode = "") {
4680 global $CFG;
4682 $this->page->set_context(null); // ugly hack - make sure page context is set to something, we do not want bogus warnings here
4684 $e = new stdClass();
4685 $e->error = $message;
4686 $e->errorcode = $errorcode;
4687 $e->stacktrace = NULL;
4688 $e->debuginfo = NULL;
4689 $e->reproductionlink = NULL;
4690 if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
4691 $link = (string) $link;
4692 if ($link) {
4693 $e->reproductionlink = $link;
4695 if (!empty($debuginfo)) {
4696 $e->debuginfo = $debuginfo;
4698 if (!empty($backtrace)) {
4699 $e->stacktrace = format_backtrace($backtrace, true);
4702 $this->header();
4703 return json_encode($e);
4707 * Used to display a notification.
4708 * For the AJAX notifications are discarded.
4710 * @param string $message The message to print out.
4711 * @param string $type The type of notification. See constants on \core\output\notification.
4713 public function notification($message, $type = null) {}
4716 * Used to display a redirection message.
4717 * AJAX redirections should not occur and as such redirection messages
4718 * are discarded.
4720 * @param moodle_url|string $encodedurl
4721 * @param string $message
4722 * @param int $delay
4723 * @param bool $debugdisableredirect
4724 * @param string $messagetype The type of notification to show the message in.
4725 * See constants on \core\output\notification.
4727 public function redirect_message($encodedurl, $message, $delay, $debugdisableredirect,
4728 $messagetype = \core\output\notification::NOTIFY_INFO) {}
4731 * Prepares the start of an AJAX output.
4733 public function header() {
4734 // unfortunately YUI iframe upload does not support application/json
4735 if (!empty($_FILES)) {
4736 @header('Content-type: text/plain; charset=utf-8');
4737 if (!core_useragent::supports_json_contenttype()) {
4738 @header('X-Content-Type-Options: nosniff');
4740 } else if (!core_useragent::supports_json_contenttype()) {
4741 @header('Content-type: text/plain; charset=utf-8');
4742 @header('X-Content-Type-Options: nosniff');
4743 } else {
4744 @header('Content-type: application/json; charset=utf-8');
4747 // Headers to make it not cacheable and json
4748 @header('Cache-Control: no-store, no-cache, must-revalidate');
4749 @header('Cache-Control: post-check=0, pre-check=0', false);
4750 @header('Pragma: no-cache');
4751 @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
4752 @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
4753 @header('Accept-Ranges: none');
4757 * There is no footer for an AJAX request, however we must override the
4758 * footer method to prevent the default footer.
4760 public function footer() {}
4763 * No need for headers in an AJAX request... this should never happen.
4764 * @param string $text
4765 * @param int $level
4766 * @param string $classes
4767 * @param string $id
4769 public function heading($text, $level = 2, $classes = 'main', $id = null) {}
4774 * Renderer for media files.
4776 * Used in file resources, media filter, and any other places that need to
4777 * output embedded media.
4779 * @deprecated since Moodle 3.2
4780 * @copyright 2011 The Open University
4781 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4783 class core_media_renderer extends plugin_renderer_base {
4784 /** @var array Array of available 'player' objects */
4785 private $players;
4786 /** @var string Regex pattern for links which may contain embeddable content */
4787 private $embeddablemarkers;
4790 * Constructor
4792 * This is needed in the constructor (not later) so that you can use the
4793 * constants and static functions that are defined in core_media class
4794 * before you call renderer functions.
4796 public function __construct() {
4797 debugging('Class core_media_renderer is deprecated, please use core_media_manager::instance()', DEBUG_DEVELOPER);
4801 * Renders a media file (audio or video) using suitable embedded player.
4803 * See embed_alternatives function for full description of parameters.
4804 * This function calls through to that one.
4806 * When using this function you can also specify width and height in the
4807 * URL by including ?d=100x100 at the end. If specified in the URL, this
4808 * will override the $width and $height parameters.
4810 * @param moodle_url $url Full URL of media file
4811 * @param string $name Optional user-readable name to display in download link
4812 * @param int $width Width in pixels (optional)
4813 * @param int $height Height in pixels (optional)
4814 * @param array $options Array of key/value pairs
4815 * @return string HTML content of embed
4817 public function embed_url(moodle_url $url, $name = '', $width = 0, $height = 0,
4818 $options = array()) {
4819 return core_media_manager::instance()->embed_url($url, $name, $width, $height, $options);
4823 * Renders media files (audio or video) using suitable embedded player.
4824 * The list of URLs should be alternative versions of the same content in
4825 * multiple formats. If there is only one format it should have a single
4826 * entry.
4828 * If the media files are not in a supported format, this will give students
4829 * a download link to each format. The download link uses the filename
4830 * unless you supply the optional name parameter.
4832 * Width and height are optional. If specified, these are suggested sizes
4833 * and should be the exact values supplied by the user, if they come from
4834 * user input. These will be treated as relating to the size of the video
4835 * content, not including any player control bar.
4837 * For audio files, height will be ignored. For video files, a few formats
4838 * work if you specify only width, but in general if you specify width
4839 * you must specify height as well.
4841 * The $options array is passed through to the core_media_player classes
4842 * that render the object tag. The keys can contain values from
4843 * core_media::OPTION_xx.
4845 * @param array $alternatives Array of moodle_url to media files
4846 * @param string $name Optional user-readable name to display in download link
4847 * @param int $width Width in pixels (optional)
4848 * @param int $height Height in pixels (optional)
4849 * @param array $options Array of key/value pairs
4850 * @return string HTML content of embed
4852 public function embed_alternatives($alternatives, $name = '', $width = 0, $height = 0,
4853 $options = array()) {
4854 return core_media_manager::instance()->embed_alternatives($alternatives, $name, $width, $height, $options);
4858 * Checks whether a file can be embedded. If this returns true you will get
4859 * an embedded player; if this returns false, you will just get a download
4860 * link.
4862 * This is a wrapper for can_embed_urls.
4864 * @param moodle_url $url URL of media file
4865 * @param array $options Options (same as when embedding)
4866 * @return bool True if file can be embedded
4868 public function can_embed_url(moodle_url $url, $options = array()) {
4869 return core_media_manager::instance()->can_embed_url($url, $options);
4873 * Checks whether a file can be embedded. If this returns true you will get
4874 * an embedded player; if this returns false, you will just get a download
4875 * link.
4877 * @param array $urls URL of media file and any alternatives (moodle_url)
4878 * @param array $options Options (same as when embedding)
4879 * @return bool True if file can be embedded
4881 public function can_embed_urls(array $urls, $options = array()) {
4882 return core_media_manager::instance()->can_embed_urls($urls, $options);
4886 * Obtains a list of markers that can be used in a regular expression when
4887 * searching for URLs that can be embedded by any player type.
4889 * This string is used to improve peformance of regex matching by ensuring
4890 * that the (presumably C) regex code can do a quick keyword check on the
4891 * URL part of a link to see if it matches one of these, rather than having
4892 * to go into PHP code for every single link to see if it can be embedded.
4894 * @return string String suitable for use in regex such as '(\.mp4|\.flv)'
4896 public function get_embeddable_markers() {
4897 return core_media_manager::instance()->get_embeddable_markers();
4902 * The maintenance renderer.
4904 * The purpose of this renderer is to block out the core renderer methods that are not usable when the site
4905 * is running a maintenance related task.
4906 * It must always extend the core_renderer as we switch from the core_renderer to this renderer in a couple of places.
4908 * @since Moodle 2.6
4909 * @package core
4910 * @category output
4911 * @copyright 2013 Sam Hemelryk
4912 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4914 class core_renderer_maintenance extends core_renderer {
4917 * Initialises the renderer instance.
4918 * @param moodle_page $page
4919 * @param string $target
4920 * @throws coding_exception
4922 public function __construct(moodle_page $page, $target) {
4923 if ($target !== RENDERER_TARGET_MAINTENANCE || $page->pagelayout !== 'maintenance') {
4924 throw new coding_exception('Invalid request for the maintenance renderer.');
4926 parent::__construct($page, $target);
4930 * Does nothing. The maintenance renderer cannot produce blocks.
4932 * @param block_contents $bc
4933 * @param string $region
4934 * @return string
4936 public function block(block_contents $bc, $region) {
4937 // Computer says no blocks.
4938 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
4939 return '';
4943 * Does nothing. The maintenance renderer cannot produce blocks.
4945 * @param string $region
4946 * @param array $classes
4947 * @param string $tag
4948 * @return string
4950 public function blocks($region, $classes = array(), $tag = 'aside') {
4951 // Computer says no blocks.
4952 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
4953 return '';
4957 * Does nothing. The maintenance renderer cannot produce blocks.
4959 * @param string $region
4960 * @return string
4962 public function blocks_for_region($region) {
4963 // Computer says no blocks for region.
4964 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
4965 return '';
4969 * Does nothing. The maintenance renderer cannot produce a course content header.
4971 * @param bool $onlyifnotcalledbefore
4972 * @return string
4974 public function course_content_header($onlyifnotcalledbefore = false) {
4975 // Computer says no course content header.
4976 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
4977 return '';
4981 * Does nothing. The maintenance renderer cannot produce a course content footer.
4983 * @param bool $onlyifnotcalledbefore
4984 * @return string
4986 public function course_content_footer($onlyifnotcalledbefore = false) {
4987 // Computer says no course content footer.
4988 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
4989 return '';
4993 * Does nothing. The maintenance renderer cannot produce a course header.
4995 * @return string
4997 public function course_header() {
4998 // Computer says no course header.
4999 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5000 return '';
5004 * Does nothing. The maintenance renderer cannot produce a course footer.
5006 * @return string
5008 public function course_footer() {
5009 // Computer says no course footer.
5010 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5011 return '';
5015 * Does nothing. The maintenance renderer cannot produce a custom menu.
5017 * @param string $custommenuitems
5018 * @return string
5020 public function custom_menu($custommenuitems = '') {
5021 // Computer says no custom menu.
5022 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5023 return '';
5027 * Does nothing. The maintenance renderer cannot produce a file picker.
5029 * @param array $options
5030 * @return string
5032 public function file_picker($options) {
5033 // Computer says no file picker.
5034 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5035 return '';
5039 * Does nothing. The maintenance renderer cannot produce and HTML file tree.
5041 * @param array $dir
5042 * @return string
5044 public function htmllize_file_tree($dir) {
5045 // Hell no we don't want no htmllized file tree.
5046 // Also why on earth is this function on the core renderer???
5047 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5048 return '';
5053 * Overridden confirm message for upgrades.
5055 * @param string $message The question to ask the user
5056 * @param single_button|moodle_url|string $continue The single_button component representing the Continue answer.
5057 * @param single_button|moodle_url|string $cancel The single_button component representing the Cancel answer.
5058 * @return string HTML fragment
5060 public function confirm($message, $continue, $cancel) {
5061 // We need plain styling of confirm boxes on upgrade because we don't know which stylesheet we have (it could be
5062 // from any previous version of Moodle).
5063 if ($continue instanceof single_button) {
5064 $continue->primary = true;
5065 } else if (is_string($continue)) {
5066 $continue = new single_button(new moodle_url($continue), get_string('continue'), 'post', true);
5067 } else if ($continue instanceof moodle_url) {
5068 $continue = new single_button($continue, get_string('continue'), 'post', true);
5069 } else {
5070 throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL' .
5071 ' (string/moodle_url) or a single_button instance.');
5074 if ($cancel instanceof single_button) {
5075 $output = '';
5076 } else if (is_string($cancel)) {
5077 $cancel = new single_button(new moodle_url($cancel), get_string('cancel'), 'get');
5078 } else if ($cancel instanceof moodle_url) {
5079 $cancel = new single_button($cancel, get_string('cancel'), 'get');
5080 } else {
5081 throw new coding_exception('The cancel param to $OUTPUT->confirm() must be either a URL' .
5082 ' (string/moodle_url) or a single_button instance.');
5085 $output = $this->box_start('generalbox', 'notice');
5086 $output .= html_writer::tag('h4', get_string('confirm'));
5087 $output .= html_writer::tag('p', $message);
5088 $output .= html_writer::tag('div', $this->render($continue) . $this->render($cancel), array('class' => 'buttons'));
5089 $output .= $this->box_end();
5090 return $output;
5094 * Does nothing. The maintenance renderer does not support JS.
5096 * @param block_contents $bc
5098 public function init_block_hider_js(block_contents $bc) {
5099 // Computer says no JavaScript.
5100 // Do nothing, ridiculous method.
5104 * Does nothing. The maintenance renderer cannot produce language menus.
5106 * @return string
5108 public function lang_menu() {
5109 // Computer says no lang menu.
5110 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5111 return '';
5115 * Does nothing. The maintenance renderer has no need for login information.
5117 * @param null $withlinks
5118 * @return string
5120 public function login_info($withlinks = null) {
5121 // Computer says no login info.
5122 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5123 return '';
5127 * Does nothing. The maintenance renderer cannot produce user pictures.
5129 * @param stdClass $user
5130 * @param array $options
5131 * @return string
5133 public function user_picture(stdClass $user, array $options = null) {
5134 // Computer says no user pictures.
5135 // debugging('Please do not use $OUTPUT->'.__FUNCTION__.'() when performing maintenance tasks.', DEBUG_DEVELOPER);
5136 return '';