MDL-20785 removing all old themes from CVS because the current mix of new and old...
[moodle.git] / lib / outputlib.php
CommitLineData
571fa828 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
78946b9b
PS
18/**
19 * Functions for generating the HTML that Moodle should output.
20 *
21 * Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
22 * for an overview.
23 *
24 * @package moodlecore
25 * @copyright 2009 Tim Hunt
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28
f8065dd2 29/**
30 * This constant is used for html attributes which need to have an empty
31 * value and still be output by the renderers (e.g. alt="");
32 *
33 * @constant @EMPTY@
34 */
35define('HTML_ATTR_EMPTY', '@EMPTY@');
571fa828 36
d9c8f425 37require_once($CFG->libdir.'/outputcomponents.php');
38require_once($CFG->libdir.'/outputactions.php');
39require_once($CFG->libdir.'/outputfactories.php');
d9c8f425 40require_once($CFG->libdir.'/outputrenderers.php');
41
571fa828 42/**
78946b9b
PS
43 * Invalidate all server and client side caches.
44 * @return void
45 */
46function theme_reset_all_caches() {
47 global $CFG;
48 require_once("$CFG->libdir/filelib.php");
49
50 set_config('themerev', empty($CFG->themerev) ? 1 : $CFG->themerev+1);
51 fulldelete("$CFG->dataroot/cache/theme");
52}
53
54/**
55 * Enable or disable theme designer mode.
56 * @param bool $state
57 * @return void
58 */
59function theme_set_designer_mod($state) {
60 theme_reset_all_caches();
61 set_config('themedesignermode', (int)!empty($state));
62}
63
64/**
65 * Returns current theme revision number.
66 * @return int
571fa828 67 */
78946b9b
PS
68function theme_get_revision() {
69 global $CFG;
70
71 if (empty($CFG->themedesignermode)) {
72 if (empty($CFG->themerev)) {
73 return -1;
74 } else {
75 return $CFG->themerev;
76 }
77
78 } else {
79 return -1;
80 }
81}
82
571fa828 83
571fa828 84/**
fdeb7fa1 85 * This class represents the configuration variables of a Moodle theme.
86 *
87 * All the variables with access: public below (with a few exceptions that are marked)
88 * are the properties you can set in your theme's config.php file.
89 *
90 * There are also some methods and protected variables that are part of the inner
91 * workings of Moodle's themes system. If you are just editing a theme's config.php
fa1afe32 92 * file, you can just ignore those, and the following information for developers.
ebebf55c 93 *
94 * Normally, to create an instance of this class, you should use the
95 * {@link theme_config::load()} factory method to load a themes config.php file.
fa1afe32 96 * However, normally you don't need to bother, because moodle_page (that is, $PAGE)
fdeb7fa1 97 * will create one for you, accessible as $PAGE->theme.
571fa828 98 *
99 * @copyright 2009 Tim Hunt
100 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
101 * @since Moodle 2.0
102 */
ebebf55c 103class theme_config {
104 /**
78946b9b
PS
105 * You can base your theme on other themes by linking to the other theme as
106 * parents. This lets you use the CSS and layouts from the other themes
107 * (see {@link $layouts}).
fdeb7fa1 108 * That makes it easy to create a new theme that is similar to another one
109 * but with a few changes. In this theme's CSS you only need to override
110 * those rules you want to change.
fdeb7fa1 111 *
78946b9b 112 * @var array
fdeb7fa1 113 */
78946b9b 114 public $parents;
571fa828 115
fdeb7fa1 116 /**
78946b9b
PS
117 * The names of all the stylesheets from this theme that you would
118 * like included, in order. Give the names of the files without .css.
fdeb7fa1 119 *
78946b9b 120 * @var array
fdeb7fa1 121 */
78946b9b 122 public $sheets = array();
571fa828 123
fdeb7fa1 124 /**
2e7dbbd7 125 * The names of all the stylesheets from parents that should be excluded.
78946b9b
PS
126 * true value may be used to specify all parents or all themes from one parent.
127 * If no value specified value from parent theme used.
fdeb7fa1 128 *
78946b9b 129 * @var array or arrays, true means all, null means use value from parent
fdeb7fa1 130 */
78946b9b 131 public $parents_exclude_sheets = null;
571fa828 132
fdeb7fa1 133 /**
78946b9b
PS
134 * List of plugin sheets to be excluded.
135 * If no value specified value from parent theme used.
136 *
137 * @var array of full plugin names, null means use value from parent
fdeb7fa1 138 */
78946b9b 139 public $plugins_exclude_sheets = null;
571fa828 140
fdeb7fa1 141 /**
78946b9b
PS
142 * List of style sheets that are included in the text editor bodies.
143 * Sheets from parent themes are used automatically and can not be excluded.
fdeb7fa1 144 *
78946b9b 145 * @var array
fdeb7fa1 146 */
78946b9b 147 public $editor_sheets = array();
571fa828 148
38aafea2
PS
149 /**
150 * The names of all the javascript files this theme that you would
04c01408 151 * like included from head, in order. Give the names of the files without .js.
38aafea2
PS
152 *
153 * @var array
154 */
155 public $javascripts = array();
156
04c01408
PS
157 /**
158 * The names of all the javascript files this theme that you would
159 * like included from footer, in order. Give the names of the files without .js.
160 *
161 * @var array
162 */
163 public $javascripts_footer = array();
164
38aafea2 165 /**
b2ae9661 166 * The names of all the javascript files from parents that should be excluded.
38aafea2
PS
167 * true value may be used to specify all parents or all themes from one parent.
168 * If no value specified value from parent theme used.
169 *
170 * @var array or arrays, true means all, null means use value from parent
171 */
172 public $parents_exclude_javascripts = null;
173
fdeb7fa1 174 /**
78946b9b 175 * Which file to use for each page layout.
fdeb7fa1 176 *
78946b9b
PS
177 * This is an array of arrays. The keys of the outer array are the different layouts.
178 * Pages in Moodle are using several different layouts like 'normal', 'course', 'home',
179 * 'popup', 'form', .... The most reliable way to get a complete list is to look at
180 * {@link http://cvs.moodle.org/moodle/theme/base/config.php?view=markup the base theme config.php file}.
d4a03c00 181 * That file also has a good example of how to set this setting.
fdeb7fa1 182 *
78946b9b 183 * For each layout, the value in the outer array is an array that describes
d4a03c00 184 * how you want that type of page to look. For example
185 * <pre>
186 * $THEME->layouts = array(
39df78bf 187 * // Most pages - if we encounter an unknown or a missing page type, this one is used.
191b267b 188 * 'standard' => array(
78946b9b
PS
189 * 'theme' = 'mytheme',
190 * 'file' => 'normal.php',
d4a03c00 191 * 'regions' => array('side-pre', 'side-post'),
192 * 'defaultregion' => 'side-post'
193 * ),
194 * // The site home page.
195 * 'home' => array(
78946b9b
PS
196 * 'theme' = 'mytheme',
197 * 'file' => 'home.php',
d4a03c00 198 * 'regions' => array('side-pre', 'side-post'),
199 * 'defaultregion' => 'side-post'
200 * ),
201 * // ...
202 * );
203 * </pre>
fdeb7fa1 204 *
78946b9b
PS
205 * 'theme' name of the theme where is the layout located
206 * 'file' is the layout file to use for this type of page.
207 * layout files are stored in layout subfolder
d4a03c00 208 * 'regions' This lists the regions on the page where blocks may appear. For
209 * each region you list here, your layout file must include a call to
210 * <pre>
211 * echo $OUTPUT->blocks_for_region($regionname);
212 * </pre>
213 * or equivalent so that the blocks are actually visible.
fdeb7fa1 214 *
d4a03c00 215 * 'defaultregion' If the list of regions is non-empty, then you must pick
216 * one of the one of them as 'default'. This has two meanings. First, this is
217 * where new blocks are added. Second, if there are any blocks associated with
fa1afe32 218 * the page, but in non-existent regions, they appear here. (Imaging, for example,
d4a03c00 219 * that someone added blocks using a different theme that used different region
220 * names, and then switched to this theme.)
fdeb7fa1 221 *
222 * @var array
223 */
d4a03c00 224 public $layouts = array();
571fa828 225
fdeb7fa1 226 /**
227 * With this you can control the colours of the big MP3 player
228 * that is used for MP3 resources.
229 *
230 * @var string
231 */
ebebf55c 232 public $resource_mp3player_colors = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes';
571fa828 233
fdeb7fa1 234 /**
78946b9b
PS
235 * With this you can control the colours of the small MP3 player
236 * that is used elsewhere.
237 *
fdeb7fa1 238 * @var string
239 */
ebebf55c 240 public $filter_mediaplugin_colors = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&waitForPlay=yes';
241
fdeb7fa1 242 /**
243 * Name of the renderer factory class to use.
244 *
245 * This is an advanced feature. Moodle output is generated by 'renderers',
246 * you can customise the HTML that is output by writing custom renderers,
247 * and then you need to specify 'renderer factory' so that Moodle can find
248 * your renderers.
249 *
250 * There are some renderer factories supplied with Moodle. Please follow these
251 * links to see what they do.
252 * <ul>
253 * <li>{@link standard_renderer_factory} - the default.</li>
254 * <li>{@link theme_overridden_renderer_factory} - use this if you want to write
78946b9b 255 * your own custom renderers in a lib.php file in this theme (or the parent theme).</li>
fdeb7fa1 256 * </ul>
257 *
258 * @var string name of a class implementing the {@link renderer_factory} interface.
259 */
ebebf55c 260 public $rendererfactory = 'standard_renderer_factory';
ebebf55c 261
fdeb7fa1 262 /**
78946b9b 263 * Function to do custom CSS post-processing.
fdeb7fa1 264 *
78946b9b
PS
265 * This is an advanced feature. If you want to do custom post-processing on the
266 * CSS before it is output (for example, to replace certain variable names
267 * with particular values) you can give the name of a function here.
fdeb7fa1 268 *
78946b9b 269 * @var string the name of a function.
fdeb7fa1 270 */
78946b9b 271 public $csspostprocess = null;
571fa828 272
273 /**
78946b9b
PS
274 * Accessibility: Right arrow-like character is
275 * used in the breadcrumb trail, course navigation menu
276 * (previous/next activity), calendar, and search forum block.
277 * If the theme does not set characters, appropriate defaults
278 * are set automatically. Please DO NOT
279 * use &lt; &gt; &raquo; - these are confusing for blind users.
fdeb7fa1 280 *
78946b9b
PS
281 * @var string
282 */
283 public $rarrow = null;
284
285 /**
286 * Accessibility: Right arrow-like character is
287 * used in the breadcrumb trail, course navigation menu
288 * (previous/next activity), calendar, and search forum block.
289 * If the theme does not set characters, appropriate defaults
290 * are set automatically. Please DO NOT
291 * use &lt; &gt; &raquo; - these are confusing for blind users.
ebebf55c 292 *
78946b9b 293 * @var string
571fa828 294 */
78946b9b
PS
295 public $larrow = null;
296
297
298 //==Following properties are not configurable from theme config.php==
571fa828 299
fdeb7fa1 300 /**
78946b9b
PS
301 * The name of this theme. Set automatically when this theme is
302 * loaded. This can not be set in theme config.php
303 * @var string
fdeb7fa1 304 */
78946b9b 305 public $name;
fdeb7fa1 306
307 /**
78946b9b
PS
308 * the folder where this themes files are stored. This is set
309 * automatically. This can not be set in theme config.php
310 * @var string
fdeb7fa1 311 */
78946b9b 312 public $dir;
fdeb7fa1 313
314 /**
78946b9b
PS
315 * Theme settings stored in config_plugins table.
316 * This can not be set in theme config.php
317 * @var object
318 */
319 public $setting = null;
320
321 /**
322 * Instance of the renderer_factory implementation
fdeb7fa1 323 * we are using. Implementation detail.
78946b9b 324 * @var renderer_factory
fdeb7fa1 325 */
326 protected $rf = null;
327
328 /**
78946b9b
PS
329 * List of parent config objects.
330 * @var array list of parent configs
331 **/
332 protected $parent_configs = array();
fdeb7fa1 333
571fa828 334 /**
ebebf55c 335 * Load the config.php file for a particular theme, and return an instance
336 * of this class. (That is, this is a factory method.)
337 *
338 * @param string $themename the name of the theme.
339 * @return theme_config an instance of this class.
571fa828 340 */
ebebf55c 341 public static function load($themename) {
342 global $CFG;
571fa828 343
78946b9b
PS
344 // load theme settings from db
345 try {
346 $settings = get_config('theme_'.$themename);
347 } catch (dml_exception $e) {
da0c0e25 348 // most probably moodle tables not created yet
78946b9b
PS
349 $settings = new object();
350 }
ebebf55c 351
78946b9b
PS
352 if ($config = theme_config::find_theme_config($themename, $settings)) {
353 return new theme_config($config);
354 } else {
355 // bad luck, the requested theme has some problems - admin see details in theme config
da0c0e25 356 return new theme_config(theme_config::find_theme_config('standard', $settings)); // TODO: use some other default MDL-21149
78946b9b
PS
357 }
358 }
ebebf55c 359
78946b9b
PS
360 /**
361 * Theme diagnostic code. It is very problematic to send debug output
362 * to the actual CSS file, instead this functions is supposed to
ae5b6801 363 * diagnose given theme and highlights all potential problems.
78946b9b
PS
364 * This information should be available from the theme selection page
365 * or some other debug page for theme designers.
366 *
367 * @param string $themename
368 * @return array description of problems
369 */
370 public static function diagnose($themename) {
5ef719e7 371 //TODO: MDL-21108
78946b9b
PS
372 return array();
373 }
374
375 /**
376 * Private constructor, can be called only from the factory method.
377 * @param stdClass $config
378 */
379 private function __construct($config) {
380 global $CFG; //needed for included lib.php files
381
382 $this->settings = $config->settings;
383 $this->name = $config->name;
384 $this->dir = $config->dir;
385
386 if ($this->name != 'base') {
387 $baseconfig = theme_config::find_theme_config('base', $this->settings);
388 } else {
389 $baseconfig = $config;
571fa828 390 }
ebebf55c 391
e68c5f36 392 $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts',
38aafea2 393 'parents_exclude_javascripts', 'layouts', 'resource_mp3player_colors',
78946b9b 394 'filter_mediaplugin_colors', 'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow');
ebebf55c 395
78946b9b
PS
396 foreach ($config as $key=>$value) {
397 if (in_array($key, $configurable)) {
398 $this->$key = $value;
399 }
400 }
401
402 // verify all parents and load configs and renderers
403 foreach ($this->parents as $parent) {
404 if ($parent == 'base') {
405 $parent_config = $baseconfig;
406 } else if (!$parent_config = theme_config::find_theme_config($parent, $this->settings)) {
407 // this is not good - better exclude faulty parents
408 continue;
409 }
410 $libfile = $parent_config->dir.'/lib.php';
411 if (is_readable($libfile)) {
412 // theme may store various function here
413 include_once($libfile);
414 }
415 $renderersfile = $parent_config->dir.'/renderers.php';
416 if (is_readable($renderersfile)) {
417 // may contain core and plugin renderers and renderer factory
418 include_once($renderersfile);
419 }
420 $this->parent_configs[$parent] = $parent_config;
421 $rendererfile = $parent_config->dir.'/renderers.php';
422 if (is_readable($rendererfile)) {
423 // may contain core and plugin renderers and renderer factory
424 include_once($rendererfile);
425 }
426 }
427 $libfile = $this->dir.'/lib.php';
428 if (is_readable($libfile)) {
429 // theme may store various function here
430 include_once($libfile);
431 }
432 $rendererfile = $this->dir.'/renderers.php';
433 if (is_readable($rendererfile)) {
434 // may contain core and plugin renderers and renderer factory
435 include_once($rendererfile);
436 }
437
438 // cascade all layouts properly
439 foreach ($baseconfig->layouts as $layout=>$value) {
440 if (!isset($this->layouts[$layout])) {
441 foreach ($this->parent_configs as $parent_config) {
442 if (isset($parent_config->layouts[$layout])) {
443 $this->layouts[$layout] = $parent_config->layouts[$layout];
444 continue 2;
445 }
446 }
447 $this->layouts[$layout] = $value;
448 }
449 }
450
451 //fix arrows if needed
452 $this->check_theme_arrows();
571fa828 453 }
454
78946b9b
PS
455 /*
456 * Checks if arrows $THEME->rarrow, $THEME->larrow have been set (theme/-/config.php).
457 * If not it applies sensible defaults.
458 *
459 * Accessibility: right and left arrow Unicode characters for breadcrumb, calendar,
460 * search forum block, etc. Important: these are 'silent' in a screen-reader
461 * (unlike &gt; &raquo;), and must be accompanied by text.
34a2777c 462 */
78946b9b
PS
463 private function check_theme_arrows() {
464 if (!isset($this->rarrow) and !isset($this->larrow)) {
465 // Default, looks good in Win XP/IE 6, Win/Firefox 1.5, Win/Netscape 8...
466 // Also OK in Win 9x/2K/IE 5.x
467 $this->rarrow = '&#x25BA;';
468 $this->larrow = '&#x25C4;';
469 if (empty($_SERVER['HTTP_USER_AGENT'])) {
470 $uagent = '';
ebebf55c 471 } else {
78946b9b
PS
472 $uagent = $_SERVER['HTTP_USER_AGENT'];
473 }
474 if (false !== strpos($uagent, 'Opera')
475 || false !== strpos($uagent, 'Mac')) {
476 // Looks good in Win XP/Mac/Opera 8/9, Mac/Firefox 2, Camino, Safari.
477 // Not broken in Mac/IE 5, Mac/Netscape 7 (?).
478 $this->rarrow = '&#x25B6;';
479 $this->larrow = '&#x25C0;';
480 }
481 elseif (false !== strpos($uagent, 'Konqueror')) {
482 $this->rarrow = '&rarr;';
483 $this->larrow = '&larr;';
484 }
485 elseif (isset($_SERVER['HTTP_ACCEPT_CHARSET'])
486 && false === stripos($_SERVER['HTTP_ACCEPT_CHARSET'], 'utf-8')) {
487 // (Win/IE 5 doesn't set ACCEPT_CHARSET, but handles Unicode.)
488 // To be safe, non-Unicode browsers!
489 $this->rarrow = '&gt;';
490 $this->larrow = '&lt;';
491 }
492
493 /// RTL support - in RTL languages, swap r and l arrows
494 if (right_to_left()) {
495 $t = $this->rarrow;
496 $this->rarrow = $this->larrow;
497 $this->larrow = $t;
ebebf55c 498 }
ebebf55c 499 }
78946b9b 500 }
ebebf55c 501
78946b9b
PS
502 /**
503 * Returns output renderer prefixes, these are used when looking
504 * for the overriden renderers in themes.
505 * @return array
506 */
507 public function renderer_prefixes() {
508 global $CFG; // just in case the included files need it
509
596af93a 510 $prefixes = array('theme_'.$this->name);
78946b9b
PS
511
512 foreach ($this->parent_configs as $parent) {
513 $prefixes[] = 'theme_'.$parent->name;
514 }
515
516 return $prefixes;
34a2777c 517 }
518
571fa828 519 /**
78946b9b
PS
520 * Returns the stylesheet URL of this editor content
521 * @param bool $encoded false means use & and true use &amp; in URLs
522 * @return string
571fa828 523 */
78946b9b
PS
524 public function editor_css_url($encoded=true) {
525 global $CFG;
526
527 $rev = theme_get_revision();
528
529 if ($rev > -1) {
530 $params = array('theme'=>$this->name,'rev'=>$rev, 'type'=>'editor');
531 return new moodle_url($CFG->httpswwwroot.'/theme/styles.php', $params);
532 } else {
533 $params = array('theme'=>$this->name, 'type'=>'editor');
534 return new moodle_url($CFG->httpswwwroot.'/theme/styles_debug.php', $params);
571fa828 535 }
571fa828 536 }
537
538 /**
78946b9b
PS
539 * Returns the content of the CSS to be used in editor content
540 * @return string
571fa828 541 */
78946b9b
PS
542 public function editor_css_content() {
543 global $CFG;
544
545 $css = '';
546
547 // first editor plugins
548 $plugins = get_plugin_list('editor');
549 foreach ($plugins as $plugin=>$fulldir) {
550 $sheetfile = "$fulldir/editor_styles.css";
551 if (is_readable($sheetfile)) {
552 $css .= "/*** Editor $plugin content CSS ***/\n\n" . file_get_contents($sheetfile) . "\n\n";
553 }
554 }
555 // then parent themes
556 foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
557 if (empty($parent_config->editor_sheets)) {
558 continue;
559 }
560 foreach ($parent_config->editor_sheets as $sheet) {
561 $sheetfile = "$parent_config->dir/$sheet.css";
562 if (is_readable($sheetfile)) {
563 $css .= "/*** Parent theme $parent/$sheet ***/\n\n" . file_get_contents($sheetfile) . "\n\n";
564 }
565 }
566 }
567 // finally this theme
568 if (!empty($this->editor_sheets)) {
569 foreach ($this->editor_sheets as $sheet) {
570 $sheetfile = "$this->dir/$sheet.css";
571 if (is_readable($sheetfile)) {
572 $css .= "/*** Theme $sheet ***/\n\n" . file_get_contents($sheetfile) . "\n\n";
573 }
574 }
575 }
576
577 return $this->post_process($css);
571fa828 578 }
579
580 /**
78946b9b
PS
581 * Get the stylesheet URL of this theme
582 * @param bool $encoded false means use & and true use &amp; in URLs
38aafea2 583 * @return array of moodle_url
571fa828 584 */
efaa4c08 585 public function css_urls(moodle_page $page) {
78946b9b
PS
586 global $CFG;
587
588 $rev = theme_get_revision();
589
efaa4c08 590 $urls = array();
efaa4c08 591
78946b9b
PS
592 if ($rev > -1) {
593 $params = array('theme'=>$this->name,'rev'=>$rev);
594 if (check_browser_version('MSIE', 5) and !check_browser_version('MSIE', 8)) {
595 $params['type'] = 'ie';
596 }
efaa4c08 597 $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles.php', $params);
78946b9b
PS
598
599 } else {
7829cf79
PS
600 // find out the current CSS and cache it now for 5 seconds
601 // the point is to construct the CSS only once and pass it through the
602 // dataroot to the script that actually serves the sheets
d6b64d15
PS
603 if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
604 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
605 }
7829cf79
PS
606 $candidatesheet = "$CFG->dataroot/cache/theme/$this->name/designer.ser";
607 if (!file_exists($candidatesheet)) {
608 $css = $this->css_content();
609 check_dir_exists(dirname($candidatesheet), true, true);
610 file_put_contents($candidatesheet, serialize($css));
611
d6b64d15 612 } else if (filemtime($candidatesheet) > time() - THEME_DESIGNER_CACHE_LIFETIME) {
7829cf79
PS
613 if ($css = file_get_contents($candidatesheet)) {
614 $css = unserialize($css);
615 } else {
616 unlink($candidatesheet);
617 $css = $this->css_content();
618 }
619
620 } else {
621 unlink($candidatesheet);
622 $css = $this->css_content();
623 file_put_contents($candidatesheet, serialize($css));
624 }
625
c724f835 626 $baseurl = $CFG->httpswwwroot.'/theme/styles_debug.php';
78946b9b 627 foreach ($css['plugins'] as $plugin=>$unused) {
c724f835 628 $urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin));
78946b9b
PS
629 }
630 foreach ($css['parents'] as $parent=>$sheets) {
631 foreach ($sheets as $sheet=>$unused2) {
c71c725e 632 $urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'parent', 'subtype'=>$parent, 'sheet'=>$sheet));
78946b9b
PS
633 }
634 }
635 foreach ($css['theme'] as $sheet=>$unused) {
c724f835 636 $urls[] = new moodle_url($baseurl, array('sheet'=>$sheet, 'theme'=>$this->name, 'type'=>'theme')); // sheet first in order to make long urls easier to read
78946b9b 637 }
78946b9b 638 }
efaa4c08
PS
639
640 return $urls;
571fa828 641 }
34a2777c 642
ebebf55c 643 /**
78946b9b
PS
644 * Returns the content of the one huge CSS merged from all style sheets.
645 * @return string
ebebf55c 646 */
78946b9b 647 public function css_content() {
34a2777c 648 global $CFG;
649
c724f835 650 $css = array('plugins'=>array(), 'parents'=>array(), 'theme'=>array());
78946b9b 651
8c96c3cb 652 // get all plugin sheets
78946b9b
PS
653 $excludes = null;
654 if (is_array($this->plugins_exclude_sheets) or $this->plugins_exclude_sheets === true) {
655 $excludes = $this->plugins_exclude_sheets;
656 } else {
657 foreach ($this->parent_configs as $parent_config) { // the immediate parent first, base last
658 if (!isset($parent_config->plugins_exclude_sheets)) {
659 continue;
660 }
661 if (is_array($parent_config->plugins_exclude_sheets) or $parent_config->plugins_exclude_sheets === true) {
662 $excludes = $parent_config->plugins_exclude_sheets;
663 break;
664 }
665 }
ebebf55c 666 }
78946b9b
PS
667 if ($excludes !== true) {
668 foreach (get_plugin_types() as $type=>$unused) {
669 if ($type === 'theme') {
670 continue;
671 }
672 if (!empty($excludes[$type]) and $excludes[$type] === true) {
673 continue;
674 }
675 $plugins = get_plugin_list($type);
676 foreach ($plugins as $plugin=>$fulldir) {
677 if (!empty($excludes[$type]) and is_array($excludes[$type])
678 and in_array($plugin, $excludes[$type])) {
679 continue;
680 }
681 $sheetfile = "$fulldir/styles.css";
682 if (is_readable($sheetfile)) {
683 $css['plugins'][$type.'_'.$plugin] = $this->post_process("/*** Standard plugin $type/$plugin ***/\n\n" . file_get_contents($sheetfile));
684 }
685 }
686 }
34a2777c 687 }
688
78946b9b
PS
689 // find out wanted parent sheets
690 $excludes = null;
691 if (is_array($this->parents_exclude_sheets) or $this->parents_exclude_sheets === true) {
692 $excludes = $this->parents_exclude_sheets;
693 } else {
694 foreach ($this->parent_configs as $parent_config) { // the immediate parent first, base last
695 if (!isset($parent_config->parents_exclude_sheets)) {
696 continue;
697 }
698 if (is_array($parent_config->parents_exclude_sheets) or $parent_config->parents_exclude_sheets === true) {
699 $excludes = $parent_config->parents_exclude_sheets;
700 break;
701 }
702 }
703 }
704 if ($excludes !== true) {
705 foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
706 $parent = $parent_config->name;
707 if (empty($parent_config->sheets)) {
708 continue;
709 }
710 if (!empty($excludes[$parent]) and $excludes[$parent] === true) {
711 continue;
712 }
713 foreach ($parent_config->sheets as $sheet) {
714 if (!empty($excludes[$parent]) and is_array($excludes[$parent])
715 and in_array($sheet, $excludes[$parent])) {
716 continue;
717 }
718 $sheetfile = "$parent_config->dir/style/$sheet.css";
719 if (is_readable($sheetfile)) {
358c13cb 720 $css['parents'][$parent][$sheet] = $this->post_process("/*** Parent theme $parent/style/$sheet.css ***/\n\n" . file_get_contents($sheetfile));
78946b9b
PS
721 }
722 }
723 }
724 }
34a2777c 725
78946b9b
PS
726 // current theme sheets
727 if (is_array($this->sheets)) {
728 foreach ($this->sheets as $sheet) {
729 $sheetfile = "$this->dir/style/$sheet.css";
730 if (is_readable($sheetfile)) {
358c13cb 731 $css['theme'][$sheet] = $this->post_process("/*** This theme $this->name/style/$sheet ***/\n\n" . file_get_contents($sheetfile));
78946b9b 732 }
ebebf55c 733 }
78946b9b
PS
734 }
735
736 return $css;
737 }
34a2777c 738
e68c5f36
PS
739
740 /**
741 * Get the javascript URL of this theme
04c01408 742 * @param bool $footer true measn footer url, false means head
e68c5f36
PS
743 * @return moodle_url
744 */
04c01408 745 public function javascript_url($footer=false) {
e68c5f36
PS
746 global $CFG;
747
748 $rev = theme_get_revision();
749
750 $params = array('theme'=>$this->name,'rev'=>$rev);
04c01408
PS
751 if ($footer) {
752 $params['type'] = 'footer';
753 }
e68c5f36
PS
754 return new moodle_url($CFG->httpswwwroot.'/theme/javascripts.php', $params);
755 }
756
757 /**
758 * Returns the content of the one huge javascript file merged from all theme javascript files.
04c01408 759 * @param bool $footer true measn footer url, false means head
e68c5f36
PS
760 * @return string
761 */
04c01408
PS
762 public function javascript_content($footer=false) {
763 $type = $footer ? 'javascripts_footer' : 'javascripts';
764
358c13cb
PS
765 $js = array();
766 // find out wanted parent javascripts
767 $excludes = null;
768 if (is_array($this->parents_exclude_javascripts) or $this->parents_exclude_javascripts === true) {
769 $excludes = $this->parents_exclude_javascripts;
770 } else {
771 foreach ($this->parent_configs as $parent_config) { // the immediate parent first, base last
772 if (!isset($parent_config->parents_exclude_javascripts)) {
773 continue;
774 }
775 if (is_array($parent_config->parents_exclude_javascripts) or $parent_config->parents_exclude_javascripts === true) {
776 $excludes = $parent_config->parents_exclude_javascripts;
777 break;
778 }
779 }
780 }
781 if ($excludes !== true) {
782 foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
783 $parent = $parent_config->name;
04c01408 784 if (empty($parent_config->$type)) {
358c13cb
PS
785 continue;
786 }
787 if (!empty($excludes[$parent]) and $excludes[$parent] === true) {
788 continue;
789 }
04c01408 790 foreach ($parent_config->$type as $javascript) {
358c13cb
PS
791 if (!empty($excludes[$parent]) and is_array($excludes[$parent])
792 and in_array($javascript, $excludes[$parent])) {
793 continue;
794 }
795 $javascriptfile = "$parent_config->dir/javascript/$javascript.js";
796 if (is_readable($javascriptfile)) {
797 $js[] = "/*** Parent theme $parent/javascript/$javascript.js ***/\n\n" . file_get_contents($javascriptfile);
798 }
799 }
800 }
801 }
802
803 // current theme javascripts
04c01408
PS
804 if (is_array($this->$type)) {
805 foreach ($this->$type as $javascript) {
358c13cb
PS
806 $javascriptfile = "$this->dir/javascript/$javascript.js";
807 if (is_readable($javascriptfile)) {
808 $js[] = "/*** This theme $this->name/javascript/$javascript.js ***/\n\n" . file_get_contents($javascriptfile);
809 }
810 }
811 }
812
813 return implode("\n\n", $js);
e68c5f36
PS
814 }
815
78946b9b 816 protected function post_process($css) {
df06c1c4
PS
817 global $CFG;
818
78946b9b
PS
819 // now resolve all image locations
820 if (preg_match_all('/\[\[pix:([a-z_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) {
821 $replaced = array();
822 foreach ($matches as $match) {
823 if (isset($replaced[$match[0]])) {
824 continue;
825 }
826 $replaced[$match[0]] = true;
827 $imagename = $match[2];
828 $component = rtrim($match[1], '|');
df06c1c4
PS
829 $imageurl = $this->pix_url($imagename, $component)->out_raw();
830 // we do not need full url because the image.php is always in the same dir
831 $imageurl = str_replace("$CFG->httpswwwroot/theme/", '', $imageurl);
832 $css = str_replace($match[0], $imageurl, $css);
ebebf55c 833 }
34a2777c 834 }
17a6649b 835
78946b9b
PS
836 // now resolve all theme settings or do any other postprocessing
837 $csspostprocess = $this->csspostprocess;
838 if (function_exists($csspostprocess)) {
839 $css = $csspostprocess($css, $this);
fdeb7fa1 840 }
841
78946b9b 842 return $css;
ebebf55c 843 }
17a6649b 844
ebebf55c 845 /**
78946b9b
PS
846 * Return the URL for an image
847 *
848 * @param string $imagename the name of the icon.
849 * @param string $component, specification of one plugin like in get_string()
850 * @return moodle_url
fdeb7fa1 851 */
c39e5ba2 852 public function pix_url($imagename, $component) {
fdeb7fa1 853 global $CFG;
78946b9b
PS
854
855 $params = array('theme'=>$this->name, 'image'=>$imagename);
856
857 $rev = theme_get_revision();
858 if ($rev != -1) {
859 $params['rev'] = $rev;
860 }
861 if (!empty($component) and $component !== 'moodle'and $component !== 'core') {
862 $params['component'] = $component;
fdeb7fa1 863 }
78946b9b
PS
864
865 return new moodle_url("$CFG->httpswwwroot/theme/image.php", $params);
fdeb7fa1 866 }
867
868 /**
78946b9b
PS
869 * Resolves the real image location.
870 * @param string $image name of image, may contain relative path
871 * @param string $component
872 * @return string full file path
fdeb7fa1 873 */
78946b9b
PS
874 public function resolve_image_location($image, $component) {
875 global $CFG;
876
877 if ($component === 'moodle' or $component === 'core' or empty($component)) {
878 if ($imagefile = $this->image_exists("$this->dir/pix_core/$image")) {
879 return $imagefile;
880 }
881 foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
882 if ($imagefile = $this->image_exists("$parent_config->dir/pix_core/$image")) {
883 return $imagefile;
884 }
885 }
886 if ($imagefile = $this->image_exists("$CFG->dirroot/pix/$image")) {
887 return $imagefile;
888 }
889 return null;
890
891 } else if ($component === 'theme') { //exception
892 if ($image === 'favicon') {
893 return "$this->dir/pix/favicon.ico";
894 }
895 if ($imagefile = $this->image_exists("$this->dir/pix/$image")) {
896 return $imagefile;
897 }
898 foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
899 if ($imagefile = $this->image_exists("$parent_config->dir/pix/$image")) {
900 return $imagefile;
901 }
902 }
903 return null;
904
78946b9b
PS
905 } else {
906 if (strpos($component, '_') === false) {
907 $component = 'mod_'.$component;
908 }
909 list($type, $plugin) = explode('_', $component, 2);
910
911 if ($imagefile = $this->image_exists("$this->dir/pix_plugins/$type/$plugin/$image")) {
912 return $imagefile;
913 }
914 foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
915 if ($imagefile = $this->image_exists("$parent_config->dir/pix_plugins/$type/$plugin/$image")) {
916 return $imagefile;
917 }
918 }
919 $dir = get_plugin_directory($type, $plugin);
920 if ($imagefile = $this->image_exists("$dir/pix/$image")) {
921 return $imagefile;
922 }
923 return null;
fdeb7fa1 924 }
fdeb7fa1 925 }
926
d4a03c00 927 /**
78946b9b
PS
928 * Checks if file with any image extension exists.
929 * @param string $filepath
930 * @return string image name with extension
d4a03c00 931 */
78946b9b
PS
932 private static function image_exists($filepath) {
933 if (file_exists("$filepath.gif")) {
934 return "$filepath.gif";
935 } else if (file_exists("$filepath.png")) {
936 return "$filepath.png";
937 } else if (file_exists("$filepath.jpg")) {
938 return "$filepath.jpg";
939 } else if (file_exists("$filepath.jpeg")) {
940 return "$filepath.jpeg";
d4a03c00 941 } else {
78946b9b 942 return false;
d4a03c00 943 }
944 }
945
fdeb7fa1 946 /**
78946b9b
PS
947 * Loads the theme config from config.php file.
948 * @param string $themename
949 * @param object $settings from config_plugins table
950 * @return object
fdeb7fa1 951 */
78946b9b
PS
952 private static function find_theme_config($themename, $settings) {
953 // We have to use the variable name $THEME (upper case) because that
954 // is what is used in theme config.php files.
fdeb7fa1 955
78946b9b
PS
956 if (!$dir = theme_config::find_theme_location($themename)) {
957 return null;
fdeb7fa1 958 }
2f67a9b3 959
78946b9b
PS
960 $THEME = new object();
961 $THEME->name = $themename;
962 $THEME->dir = $dir;
963 $THEME->settings = $settings;
964
965 global $CFG; // just in case somebody tries to use $CFG in theme config
966 include("$THEME->dir/config.php");
967
968 // verify the theme configuration is OK
969 if (!is_array($THEME->parents)) {
970 // parents option is mandatory now
971 return null;
fdeb7fa1 972 }
973
78946b9b 974 return $THEME;
fdeb7fa1 975 }
976
d4a03c00 977 /**
78946b9b
PS
978 * Finds the theme location and verifies the theme has all needed files
979 * and is not obsoleted.
980 * @param string $themename
981 * @return string full dir path or null if not found
d4a03c00 982 */
78946b9b
PS
983 private static function find_theme_location($themename) {
984 global $CFG;
985
986 if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
987 $dir = "$CFG->dirroot/theme/$themename";
d4a03c00 988
7d875874 989 } else {
78946b9b 990 return null;
d4a03c00 991 }
78946b9b
PS
992
993 if (file_exists("$dir/styles.php")) {
994 //legacy theme - needs to be upgraded - upgrade info is displayed on the admin settings page
995 return null;
996 }
2f67a9b3 997
78946b9b 998 return $dir;
d4a03c00 999 }
1000
1d13c75c 1001 /**
78946b9b 1002 * Get the renderer for a part of Moodle for this theme.
78946b9b 1003 * @param moodle_page $page the page we are rendering
56cbc53b 1004 * @param string $module the name of part of moodle. E.g. 'core', 'quiz', 'qtype_multichoice'.
78946b9b 1005 * @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
c927e35c 1006 * @param string $target one of rendering target constants
78946b9b 1007 * @return renderer_base the requested renderer.
1d13c75c 1008 */
c927e35c 1009 public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) {
78946b9b 1010 if (is_null($this->rf)) {
c927e35c 1011 $classname = $this->rendererfactory;
78946b9b 1012 $this->rf = new $classname($this);
1d13c75c 1013 }
78946b9b 1014
c927e35c 1015 return $this->rf->get_renderer($page, $component, $subtype, $target);
1d13c75c 1016 }
1017
fdeb7fa1 1018 /**
78946b9b
PS
1019 * Get the information from {@link $layouts} for this type of page.
1020 * @param string $pagelayout the the page layout name.
1021 * @return array the appropriate part of {@link $layouts}.
fdeb7fa1 1022 */
78946b9b
PS
1023 protected function layout_info_for_page($pagelayout) {
1024 if (array_key_exists($pagelayout, $this->layouts)) {
1025 return $this->layouts[$pagelayout];
1026 } else {
191b267b
PS
1027 debugging('Invalid page layout specified: ' . $pagelayout);
1028 return $this->layouts['standard'];
fdeb7fa1 1029 }
1030 }
1031
1032 /**
78946b9b
PS
1033 * Given the settings of this theme, and the page pagelayout, return the
1034 * full path of the page layout file to use.
1035 *
1036 * Used by {@link core_renderer::header()}.
1037 *
1038 * @param string $pagelayout the the page layout name.
1039 * @return string Full path to the lyout file to use
ebebf55c 1040 */
78946b9b 1041 public function layout_file($pagelayout) {
ebebf55c 1042 global $CFG;
fdeb7fa1 1043
78946b9b
PS
1044 $layoutinfo = $this->layout_info_for_page($pagelayout);
1045 $layoutfile = $layoutinfo['file'];
1046 $theme = $layoutinfo['theme'];
fdeb7fa1 1047
78946b9b
PS
1048 if ($dir = $this->find_theme_location($theme)) {
1049 $path = "$dir/layout/$layoutfile";
fdeb7fa1 1050
78946b9b
PS
1051 // Check the template exists, return general base theme template if not.
1052 if (is_readable($path)) {
1053 return $path;
1054 }
34a2777c 1055 }
1056
191b267b 1057 debugging('Can not find layout file for: ' . $pagelayout);
78946b9b
PS
1058 // fallback to standard normal layout
1059 return "$CFG->dirroot/theme/base/layout/general.php";
1060 }
ebebf55c 1061
78946b9b
PS
1062 /**
1063 * Returns auxiliary page layout options specified in layout configuration array.
1064 * @param string $pagelayout
1065 * @return array
1066 */
1067 public function pagelayout_options($pagelayout) {
1068 $info = $this->layout_info_for_page($pagelayout);
1069 if (!empty($info['options'])) {
1070 return $info['options'];
34a2777c 1071 }
78946b9b
PS
1072 return array();
1073 }
34a2777c 1074
78946b9b
PS
1075 /**
1076 * Inform a block_manager about the block regions this theme wants on this
1077 * page layout.
1078 * @param string $pagelayout the general type of the page.
1079 * @param block_manager $blockmanager the block_manger to set up.
1080 * @return void
1081 */
1082 public function setup_blocks($pagelayout, $blockmanager) {
1083 $layoutinfo = $this->layout_info_for_page($pagelayout);
1084 if (!empty($layoutinfo['regions'])) {
1085 $blockmanager->add_regions($layoutinfo['regions']);
1086 $blockmanager->set_default_region($layoutinfo['defaultregion']);
ebebf55c 1087 }
34a2777c 1088 }
1089
ebebf55c 1090 /**
78946b9b
PS
1091 * Get the list of all block regions known to this theme in all templates.
1092 * @return array internal region name => human readable name.
ebebf55c 1093 */
78946b9b
PS
1094 public function get_all_block_regions() {
1095 $regions = array();
1096 //TODO: this is weird because the regions from different layouts override each other
1097 foreach ($this->layouts as $layoutinfo) {
1098 foreach ($layoutinfo['regions'] as $region) {
1099 $regions[$region] = get_string('region-' . $region, 'theme_' . $layoutinfo['theme']);
ebebf55c 1100 }
34a2777c 1101 }
78946b9b 1102 return $regions;
34a2777c 1103 }
ebebf55c 1104}
34a2777c 1105
78946b9b 1106
ebebf55c 1107/**
d9c8f425 1108 * This class keeps track of which HTML tags are currently open.
1109 *
1110 * This makes it much easier to always generate well formed XHTML output, even
1111 * if execution terminates abruptly. Any time you output some opening HTML
1112 * without the matching closing HTML, you should push the necessary close tags
1113 * onto the stack.
ebebf55c 1114 *
1115 * @copyright 2009 Tim Hunt
1116 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1117 * @since Moodle 2.0
1118 */
d9c8f425 1119class xhtml_container_stack {
1120 /** @var array stores the list of open containers. */
1121 protected $opencontainers = array();
fa1afe32 1122 /**
d9c8f425 1123 * @var array in developer debug mode, stores a stack trace of all opens and
1124 * closes, so we can output helpful error messages when there is a mismatch.
fa1afe32 1125 */
d9c8f425 1126 protected $log = array();
fa1afe32 1127 /**
d9c8f425 1128 * Store whether we are developer debug mode. We need this in several places
1129 * including in the destructor where we may no thave access to $CFG.
1130 * @var boolean
fa1afe32 1131 */
d9c8f425 1132 protected $isdebugging;
34a2777c 1133
d9c8f425 1134 public function __construct() {
1135 $this->isdebugging = debugging('', DEBUG_DEVELOPER);
ebebf55c 1136 }
34a2777c 1137
fa1afe32 1138 /**
d9c8f425 1139 * Push the close HTML for a recently opened container onto the stack.
1140 * @param string $type The type of container. This is checked when {@link pop()}
1141 * is called and must match, otherwise a developer debug warning is output.
1142 * @param string $closehtml The HTML required to close the container.
1143 * @return void
fa1afe32 1144 */
d9c8f425 1145 public function push($type, $closehtml) {
1146 $container = new stdClass;
1147 $container->type = $type;
1148 $container->closehtml = $closehtml;
1149 if ($this->isdebugging) {
1150 $this->log('Open', $type);
3aaa27f4 1151 }
d9c8f425 1152 array_push($this->opencontainers, $container);
ebebf55c 1153 }
34a2777c 1154
fa1afe32 1155 /**
d9c8f425 1156 * Pop the HTML for the next closing container from the stack. The $type
1157 * must match the type passed when the container was opened, otherwise a
1158 * warning will be output.
1159 * @param string $type The type of container.
1160 * @return string the HTML required to close the container.
fa1afe32 1161 */
d9c8f425 1162 public function pop($type) {
1163 if (empty($this->opencontainers)) {
1164 debugging('<p>There are no more open containers. This suggests there is a nesting problem.</p>' .
1165 $this->output_log(), DEBUG_DEVELOPER);
1166 return;
3aaa27f4 1167 }
ebebf55c 1168
d9c8f425 1169 $container = array_pop($this->opencontainers);
1170 if ($container->type != $type) {
1171 debugging('<p>The type of container to be closed (' . $container->type .
1172 ') does not match the type of the next open container (' . $type .
1173 '). This suggests there is a nesting problem.</p>' .
1174 $this->output_log(), DEBUG_DEVELOPER);
ebebf55c 1175 }
d9c8f425 1176 if ($this->isdebugging) {
1177 $this->log('Close', $type);
e8775320 1178 }
d9c8f425 1179 return $container->closehtml;
ebebf55c 1180 }
e8775320 1181
fa1afe32 1182 /**
d9c8f425 1183 * Close all but the last open container. This is useful in places like error
1184 * handling, where you want to close all the open containers (apart from <body>)
1185 * before outputting the error message.
1186 * @param bool $shouldbenone assert that the stack should be empty now - causes a
1187 * developer debug warning if it isn't.
1188 * @return string the HTML required to close any open containers inside <body>.
fa1afe32 1189 */
d9c8f425 1190 public function pop_all_but_last($shouldbenone = false) {
1191 if ($shouldbenone && count($this->opencontainers) != 1) {
1192 debugging('<p>Some HTML tags were opened in the body of the page but not closed.</p>' .
1193 $this->output_log(), DEBUG_DEVELOPER);
1194 }
1195 $output = '';
1196 while (count($this->opencontainers) > 1) {
1197 $container = array_pop($this->opencontainers);
1198 $output .= $container->closehtml;
e8775320 1199 }
d9c8f425 1200 return $output;
e8775320 1201 }
34a2777c 1202
ebebf55c 1203 /**
d9c8f425 1204 * You can call this function if you want to throw away an instance of this
1205 * class without properly emptying the stack (for example, in a unit test).
1206 * Calling this method stops the destruct method from outputting a developer
1207 * debug warning. After calling this method, the instance can no longer be used.
1208 * @return void
ebebf55c 1209 */
d9c8f425 1210 public function discard() {
1211 $this->opencontainers = null;
ebebf55c 1212 }
d9c8f425 1213
fa1afe32 1214 /**
d9c8f425 1215 * Adds an entry to the log.
1216 * @param string $action The name of the action
1217 * @param string $type The type of action
1218 * @return void
fa1afe32 1219 */
d9c8f425 1220 protected function log($action, $type) {
1221 $this->log[] = '<li>' . $action . ' ' . $type . ' at:' .
1222 format_backtrace(debug_backtrace()) . '</li>';
ebebf55c 1223 }
34a2777c 1224
fa1afe32 1225 /**
d9c8f425 1226 * Outputs the log's contents as a HTML list.
1227 * @return string HTML list of the log
fa1afe32 1228 */
d9c8f425 1229 protected function output_log() {
1230 return '<ul>' . implode("\n", $this->log) . '</ul>';
34a2777c 1231 }
1232}