Merge branch 'wip-MDL-30979-m23' of git://github.com/samhemelryk/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2012-02-20 11:38:20 +01:00
6 changed files with 1093 additions and 622 deletions
+37 -20
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -21,10 +20,10 @@
* Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
* for an overview.
*
* @package core
* @subpackage lib
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core
* @category output
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -33,38 +32,36 @@ defined('MOODLE_INTERNAL') || die();
* Helper class used by other components that involve an action on the page (URL or JS).
*
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class component_action {
/**
* The DOM event that will trigger this action when caught
* @var string $event DOM event
* @var string $event The DOM event that will trigger this action when caught
*/
public $event;
/**
* @var string A function name to call when the button is clicked
* The JS function you create must have two arguments:
* 1. The event object
* 2. An object/array of arguments ($jsfunctionargs)
* @var string $jsfunction A function name to call when the button is clicked
*/
public $jsfunction = false;
/**
* @var array $jsfunctionargs An array of arguments to pass to the JS function
* @var array An array of arguments to pass to the JS function
*/
public $jsfunctionargs = array();
/**
* Constructor
* @param string $event DOM event
* @param moodle_url $url A moodle_url object, required if no jsfunction is given
* @param string $method 'post' or 'get'
* @param string $jsfunction An optional JS function. Required if jsfunctionargs is given
* @param array $jsfunctionargs An array of arguments to pass to the jsfunction
* @return void
* @param array $jsfunctionargs An array of arguments to pass to the jsfunction
*/
public function __construct($event, $jsfunction, $jsfunctionargs=array()) {
$this->event = $event;
@@ -83,8 +80,23 @@ class component_action {
/**
* Confirm action
*
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class confirm_action extends component_action {
/**
* Constructs the confirm action object
*
* @param string $message The message to display to the user when they are shown
* the confirm dialogue.
* @param string $callback The method to call when the user confirms the action.
* @param string $continuelabel The string to use for he continue button
* @param string $cancellabel The string to use for the cancel button
*/
public function __construct($message, $callback = null, $continuelabel = null, $cancellabel = null) {
parent::__construct('click', 'M.util.show_confirm_dialog', array(
'message' => $message, 'callback' => $callback,
@@ -97,15 +109,20 @@ class confirm_action extends component_action {
* Component action for a popup window.
*
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class popup_action extends component_action {
/**
* @var string The JS function to call for the popup
*/
public $jsfunction = 'openpopup';
/**
* @var array $params An array of parameters that will be passed to the openpopup JS function
* @var array An array of parameters that will be passed to the openpopup JS function
*/
public $params = array(
'height' => 400,
@@ -124,11 +141,11 @@ class popup_action extends component_action {
/**
* Constructor
*
* @param string $event DOM event
* @param moodle_url|string $url A moodle_url object, required if no jsfunction is given
* @param string $method 'post' or 'get'
* @param string $name The JS function to call for the popup (default 'popup')
* @param array $params An array of popup parameters
* @return void
*/
public function __construct($event, $url, $name='popup', $params=array()) {
global $CFG;
+536 -331
View File
File diff suppressed because it is too large Load Diff
+43 -27
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -16,16 +15,15 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Interface and classes for creating appropriate renderers for various
* parts of Moodle.
* Interface and classes for creating appropriate renderers for various parts of Moodle.
*
* Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
* for an overview.
*
* @package core
* @subpackage lib
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core
* @category output
*/
defined('MOODLE_INTERNAL') || die();
@@ -45,7 +43,7 @@ define('RENDERER_TARGET_TEXTEMAIL', 'textemail');
/** Rich text html rendering intended for sending via email */
define('RENDERER_TARGET_HTMLEMAIL', 'htmlemail');
/* note: maybe we could define portfolio export target too */
// note: maybe we could define portfolio export target too
/**
@@ -59,10 +57,13 @@ define('RENDERER_TARGET_HTMLEMAIL', 'htmlemail');
* (See {@link renderer_factory_base::__construct} for an example.)
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
interface renderer_factory {
/**
* Return the renderer for a particular part of Moodle.
*
@@ -86,7 +87,7 @@ interface renderer_factory {
* @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
* @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
* @param string $target one of rendering target constants
* @return object an object implementing the requested renderer interface.
* @return renderer_base an object implementing the requested renderer interface.
*/
public function get_renderer(moodle_page $page, $component, $subtype=null, $target=null);
}
@@ -102,15 +103,20 @@ interface renderer_factory {
* the definition of, the standard renderer class for a given module.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
abstract class renderer_factory_base implements renderer_factory {
/** @var theme_config the theme we belong to. */
/**
* @var theme_config The theme we belong to.
*/
protected $theme;
/**
* Constructor.
*
* @param theme_config $theme the theme we belong to.
*/
public function __construct(theme_config $theme) {
@@ -119,6 +125,7 @@ abstract class renderer_factory_base implements renderer_factory {
/**
* Returns suffix of renderer class expected for given target.
*
* @param string $target one of the renderer target constants, target is guessed if null used
* @return array two element array, first element is target, second the target suffix string
*/
@@ -195,23 +202,27 @@ abstract class renderer_factory_base implements renderer_factory {
}
}
/**
* This is the default renderer factory for Moodle. It simply returns an instance
* of the appropriate standard renderer class.
* This is the default renderer factory for Moodle.
*
* It simply returns an instance of the appropriate standard renderer class.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class standard_renderer_factory extends renderer_factory_base {
/**
* Implement the subclass method
*
* @param moodle_page $page the page the renderer is outputting content for.
* @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
* @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
* @param string $target one of rendering target constants
* @return object an object implementing the requested renderer interface.
* @return renderer_base an object implementing the requested renderer interface.
*/
public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) {
$classname = $this->standard_renderer_classname($component, $subtype);
@@ -232,8 +243,7 @@ class standard_renderer_factory extends renderer_factory_base {
/**
* This is renderer factory allows themes to override the standard renderers using
* php code.
* This is renderer factory allows themes to override the standard renderers using php code.
*
* It will load any code from theme/mytheme/renderers.php and
* theme/parenttheme/renderers.php, if then exist. Then whenever you ask for
@@ -242,16 +252,21 @@ class standard_renderer_factory extends renderer_factory_base {
* if either of those classes exist.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class theme_overridden_renderer_factory extends renderer_factory_base {
/**
* @var array An array of renderer prefixes
*/
protected $prefixes = array();
/**
* Constructor.
* @param object $theme the theme we are rendering for.
* @param theme_config $theme the theme we are rendering for.
*/
public function __construct(theme_config $theme) {
parent::__construct($theme);
@@ -261,11 +276,12 @@ class theme_overridden_renderer_factory extends renderer_factory_base {
/**
* Implement the subclass method
*
* @param moodle_page $page the page the renderer is outputting content for.
* @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
* @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
* @param string $target one of rendering target constants
* @return object an object implementing the requested renderer interface.
* @return renderer_base an object implementing the requested renderer interface.
*/
public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) {
$classname = $this->standard_renderer_classname($component, $subtype);
@@ -303,4 +319,4 @@ class theme_overridden_renderer_factory extends renderer_factory_base {
return new $classname($page, $target);
}
}
}
+123 -96
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -21,10 +20,10 @@
* Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
* for an overview.
*
* @package core
* @subpackage lib
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core
* @category output
*/
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +36,11 @@ require_once($CFG->libdir.'/outputrequirementslib.php');
/**
* Invalidate all server and client side caches.
* @return void
*
* This method deletes the phsyical directory that is used to cache the theme
* files used for serving.
* Because it deletes the main theme cache directoy all themes are reset by
* this function.
*/
function theme_reset_all_caches() {
global $CFG;
@@ -49,8 +52,8 @@ function theme_reset_all_caches() {
/**
* Enable or disable theme designer mode.
*
* @param bool $state
* @return void
*/
function theme_set_designer_mod($state) {
theme_reset_all_caches();
@@ -59,6 +62,7 @@ function theme_set_designer_mod($state) {
/**
* Returns current theme revision number.
*
* @return int
*/
function theme_get_revision() {
@@ -81,10 +85,10 @@ function theme_get_revision() {
* This class represents the configuration variables of a Moodle theme.
*
* All the variables with access: public below (with a few exceptions that are marked)
* are the properties you can set in your theme's config.php file.
* are the properties you can set in your themes config.php file.
*
* There are also some methods and protected variables that are part of the inner
* workings of Moodle's themes system. If you are just editing a theme's config.php
* workings of Moodle's themes system. If you are just editing a themes config.php
* file, you can just ignore those, and the following information for developers.
*
* Normally, to create an instance of this class, you should use the
@@ -93,87 +97,75 @@ function theme_get_revision() {
* will create one for you, accessible as $PAGE->theme.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class theme_config {
/**
* @var string default theme, used when requested theme not found
* @var string Default theme, used when requested theme not found.
*/
const DEFAULT_THEME = 'standard';
/**
* You can base your theme on other themes by linking to the other theme as
* @var array You can base your theme on other themes by linking to the other theme as
* parents. This lets you use the CSS and layouts from the other themes
* (see {@link $layouts}).
* (see {@link theme_config::$layouts}).
* That makes it easy to create a new theme that is similar to another one
* but with a few changes. In this theme's CSS you only need to override
* but with a few changes. In this themes CSS you only need to override
* those rules you want to change.
*
* @var array
*/
public $parents;
/**
* The names of all the stylesheets from this theme that you would
* @var array The names of all the stylesheets from this theme that you would
* like included, in order. Give the names of the files without .css.
*
* @var array
*/
public $sheets = array();
/**
* The names of all the stylesheets from parents that should be excluded.
* @var array The names of all the stylesheets from parents that should be excluded.
* true value may be used to specify all parents or all themes from one parent.
* If no value specified value from parent theme used.
*
* @var array or arrays, true means all, null means use value from parent
*/
public $parents_exclude_sheets = null;
/**
* List of plugin sheets to be excluded.
* @var array List of plugin sheets to be excluded.
* If no value specified value from parent theme used.
*
* @var array of full plugin names, null means use value from parent
*/
public $plugins_exclude_sheets = null;
/**
* List of style sheets that are included in the text editor bodies.
* @var array List of style sheets that are included in the text editor bodies.
* Sheets from parent themes are used automatically and can not be excluded.
*
* @var array
*/
public $editor_sheets = array();
/**
* The names of all the javascript files this theme that you would
* @var array The names of all the javascript files this theme that you would
* like included from head, in order. Give the names of the files without .js.
*
* @var array
*/
public $javascripts = array();
/**
* The names of all the javascript files this theme that you would
* @var array The names of all the javascript files this theme that you would
* like included from footer, in order. Give the names of the files without .js.
*
* @var array
*/
public $javascripts_footer = array();
/**
* The names of all the javascript files from parents that should be excluded.
* true value may be used to specify all parents or all themes from one parent.
* @var array The names of all the javascript files from parents that should
* be excluded. true value may be used to specify all parents or all themes
* from one parent.
* If no value specified value from parent theme used.
*
* @var array or arrays, true means all, null means use value from parent
*/
public $parents_exclude_javascripts = null;
/**
* Which file to use for each page layout.
* @var array Which file to use for each page layout.
*
* This is an array of arrays. The keys of the outer array are the different layouts.
* Pages in Moodle are using several different layouts like 'normal', 'course', 'home',
@@ -219,13 +211,12 @@ class theme_config {
* the page, but in non-existent regions, they appear here. (Imaging, for example,
* that someone added blocks using a different theme that used different region
* names, and then switched to this theme.)
*
* @var array
*/
public $layouts = array();
/**
* Name of the renderer factory class to use.
* @var string Name of the renderer factory class to use. Must implement the
* {@link renderer_factory} interface.
*
* This is an advanced feature. Moodle output is generated by 'renderers',
* you can customise the HTML that is output by writing custom renderers,
@@ -239,99 +230,83 @@ class theme_config {
* <li>{@link theme_overridden_renderer_factory} - use this if you want to write
* your own custom renderers in a lib.php file in this theme (or the parent theme).</li>
* </ul>
*
* @var string name of a class implementing the {@link renderer_factory} interface.
*/
public $rendererfactory = 'standard_renderer_factory';
/**
* Function to do custom CSS post-processing.
* @var string Function to do custom CSS post-processing.
*
* This is an advanced feature. If you want to do custom post-processing on the
* CSS before it is output (for example, to replace certain variable names
* with particular values) you can give the name of a function here.
*
* @var string the name of a function.
*/
public $csspostprocess = null;
/**
* Accessibility: Right arrow-like character is
* @var string Accessibility: Right arrow-like character is
* used in the breadcrumb trail, course navigation menu
* (previous/next activity), calendar, and search forum block.
* If the theme does not set characters, appropriate defaults
* are set automatically. Please DO NOT
* use &lt; &gt; &raquo; - these are confusing for blind users.
*
* @var string
*/
public $rarrow = null;
/**
* Accessibility: Right arrow-like character is
* @var string Accessibility: Right arrow-like character is
* used in the breadcrumb trail, course navigation menu
* (previous/next activity), calendar, and search forum block.
* If the theme does not set characters, appropriate defaults
* are set automatically. Please DO NOT
* use &lt; &gt; &raquo; - these are confusing for blind users.
*
* @var string
*/
public $larrow = null;
/**
* Some themes may want to disable ajax course editing.
* @var bool
* @var bool Some themes may want to disable ajax course editing.
*/
public $enablecourseajax = true;
//==Following properties are not configurable from theme config.php==
/**
* The name of this theme. Set automatically when this theme is
* @var string The name of this theme. Set automatically when this theme is
* loaded. This can not be set in theme config.php
* @var string
*/
public $name;
/**
* the folder where this themes files are stored. This is set
* @var string The folder where this themes files are stored. This is set
* automatically. This can not be set in theme config.php
* @var string
*/
public $dir;
/**
* Theme settings stored in config_plugins table.
* @var stdClass Theme settings stored in config_plugins table.
* This can not be set in theme config.php
* @var object
*/
public $setting = null;
/**
* If set to true and the theme enables the dock then blocks will be able
* @var bool If set to true and the theme enables the dock then blocks will be able
* to be moved to the special dock
* @var bool
*/
public $enable_dock = false;
/**
* If set to true then this theme will not be shown in the theme selector unless
* @var bool If set to true then this theme will not be shown in the theme selector unless
* theme designer mode is turned on.
* @var bool
*/
public $hidefromselector = false;
/**
* Instance of the renderer_factory implementation
* @var renderer_factory Instance of the renderer_factory implementation
* we are using. Implementation detail.
* @var renderer_factory
*/
protected $rf = null;
/**
* List of parent config objects.
* @var array list of parent configs
* @var array List of parent config objects.
**/
protected $parent_configs = array();
@@ -460,7 +435,7 @@ class theme_config {
$this->check_theme_arrows();
}
/*
/**
* Checks if arrows $THEME->rarrow, $THEME->larrow have been set (theme/-/config.php).
* If not it applies sensible defaults.
*
@@ -498,7 +473,7 @@ class theme_config {
$this->larrow = '&lt;';
}
/// RTL support - in RTL languages, swap r and l arrows
// RTL support - in RTL languages, swap r and l arrows
if (right_to_left()) {
$t = $this->rarrow;
$this->rarrow = $this->larrow;
@@ -510,6 +485,7 @@ class theme_config {
/**
* Returns output renderer prefixes, these are used when looking
* for the overridden renderers in themes.
*
* @return array
*/
public function renderer_prefixes() {
@@ -526,6 +502,7 @@ class theme_config {
/**
* Returns the stylesheet URL of this editor content
*
* @param bool $encoded false means use & and true use &amp; in URLs
* @return string
*/
@@ -545,6 +522,7 @@ class theme_config {
/**
* Returns the content of the CSS to be used in editor content
*
* @return string
*/
public function editor_css_files() {
@@ -587,7 +565,8 @@ class theme_config {
/**
* Get the stylesheet URL of this theme
* @param bool $encoded false means use & and true use &amp; in URLs
*
* @param moodle_page $page Not used... deprecated?
* @return array of moodle_url
*/
public function css_urls(moodle_page $page) {
@@ -664,6 +643,7 @@ class theme_config {
/**
* Returns an array of organised CSS files required for this output
*
* @return array
*/
public function css_files() {
@@ -732,6 +712,7 @@ class theme_config {
/**
* Returns the content of the one huge CSS merged from all style sheets.
*
* @return string
*/
public function css_content() {
@@ -744,7 +725,7 @@ class theme_config {
* Given an array of file paths or a single file path loads the contents of
* the CSS file, processes it then returns it in the same structure it was given.
*
* Can be used recursively on the results of {@see css_files}
* Can be used recursively on the results of {@link css_files}
*
* @param array|string $file An array of file paths or a single file path
* @param array $keys An array of previous array keys [recursive addition]
@@ -764,7 +745,8 @@ class theme_config {
/**
* Get the javascript URL of this theme
* Generate a URL to the file that serves theme JavaScript files.
*
* @param bool $inhead true means head url, false means footer
* @return moodle_url
*/
@@ -778,6 +760,14 @@ class theme_config {
return new moodle_url($CFG->httpswwwroot.'/theme/javascript.php', $params);
}
/**
* Get the URL's for the JavaScript files used by this theme.
* They won't be served directly, instead they'll be mediated through
* theme/javascript.php.
*
* @param string $type Either javascripts_footer, or javascripts
* @return array
*/
public function javascript_files($type) {
if ($type === 'footer') {
$type = 'javascripts_footer';
@@ -824,13 +814,14 @@ class theme_config {
}
/**
* Resolves an exclude setting to the theme's setting is applicable or the
* Resolves an exclude setting to the themes setting is applicable or the
* setting of its closest parent.
*
* @param string $variable The name of the setting the exclude setting to resolve
* @param string $default
* @return mixed
*/
protected function resolve_excludes($variable, $default=null) {
protected function resolve_excludes($variable, $default = null) {
$setting = $default;
if (is_array($this->{$variable}) or $this->{$variable} === true) {
$setting = $this->{$variable};
@@ -850,7 +841,8 @@ class theme_config {
/**
* Returns the content of the one huge javascript file merged from all theme javascript files.
* @param bool $inhead
*
* @param bool $type
* @return string
*/
public function javascript_content($type) {
@@ -862,6 +854,17 @@ class theme_config {
return $js;
}
/**
* Post processes CSS.
*
* This method post processes all of the CSS before it is served for this theme.
* This is done so that things such as image URL's can be swapped in and to
* run any specific CSS post process method the theme has requested.
* This allows themes to use CSS settings.
*
* @param string $css The CSS to process.
* @return string The processed CSS.
*/
public function post_process($css) {
global $CFG;
@@ -895,7 +898,7 @@ class theme_config {
* Return the URL for an image
*
* @param string $imagename the name of the icon.
* @param string $component, specification of one plugin like in get_string()
* @param string $component specification of one plugin like in get_string()
* @return moodle_url
*/
public function pix_url($imagename, $component) {
@@ -975,6 +978,7 @@ class theme_config {
/**
* Checks if file with any image extension exists.
*
* @param string $filepath
* @return string image name with extension
*/
@@ -994,9 +998,10 @@ class theme_config {
/**
* Loads the theme config from config.php file.
*
* @param string $themename
* @param object $settings from config_plugins table
* @return object
* @param stdClass $settings from config_plugins table
* @return stdClass The theme configuration
*/
private static function find_theme_config($themename, $settings) {
// We have to use the variable name $THEME (upper case) because that
@@ -1026,6 +1031,7 @@ class theme_config {
/**
* Finds the theme location and verifies the theme has all needed files
* and is not obsoleted.
*
* @param string $themename
* @return string full dir path or null if not found
*/
@@ -1052,8 +1058,9 @@ class theme_config {
/**
* Get the renderer for a part of Moodle for this theme.
*
* @param moodle_page $page the page we are rendering
* @param string $module the name of part of moodle. E.g. 'core', 'quiz', 'qtype_multichoice'.
* @param string $component the name of part of moodle. E.g. 'core', 'quiz', 'qtype_multichoice'.
* @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
* @param string $target one of rendering target constants
* @return renderer_base the requested renderer.
@@ -1069,6 +1076,7 @@ class theme_config {
/**
* Get the information from {@link $layouts} for this type of page.
*
* @param string $pagelayout the the page layout name.
* @return array the appropriate part of {@link $layouts}.
*/
@@ -1120,6 +1128,7 @@ class theme_config {
/**
* Returns auxiliary page layout options specified in layout configuration array.
*
* @param string $pagelayout
* @return array
*/
@@ -1134,9 +1143,9 @@ class theme_config {
/**
* Inform a block_manager about the block regions this theme wants on this
* page layout.
*
* @param string $pagelayout the general type of the page.
* @param block_manager $blockmanager the block_manger to set up.
* @return void
*/
public function setup_blocks($pagelayout, $blockmanager) {
$layoutinfo = $this->layout_info_for_page($pagelayout);
@@ -1146,6 +1155,13 @@ class theme_config {
}
}
/**
* Gets the visible name for the requested block region.
*
* @param string $region The region name to get
* @param string $theme The theme the region belongs to (may come from the parent theme)
* @return string
*/
protected function get_region_name($region, $theme) {
$regionstring = get_string('region-' . $region, 'theme_' . $theme);
// A name exists in this theme, so use it
@@ -1168,6 +1184,7 @@ class theme_config {
/**
* Get the list of all block regions known to this theme in all templates.
*
* @return array internal region name => human readable name.
*/
public function get_all_block_regions() {
@@ -1190,7 +1207,6 @@ class theme_config {
}
}
/**
* This class keeps track of which HTML tags are currently open.
*
@@ -1200,34 +1216,43 @@ class theme_config {
* onto the stack.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class xhtml_container_stack {
/** @var array stores the list of open containers. */
protected $opencontainers = array();
/**
* @var array in developer debug mode, stores a stack trace of all opens and
* @var array Stores the list of open containers.
*/
protected $opencontainers = array();
/**
* @var array In developer debug mode, stores a stack trace of all opens and
* closes, so we can output helpful error messages when there is a mismatch.
*/
protected $log = array();
/**
* Store whether we are developer debug mode. We need this in several places
* including in the destructor where we may not have access to $CFG.
* @var boolean
* @var boolean Store whether we are developer debug mode. We need this in
* several places including in the destructor where we may not have access to $CFG.
*/
protected $isdebugging;
/**
* Constructor
*/
public function __construct() {
$this->isdebugging = debugging('', DEBUG_DEVELOPER);
}
/**
* Push the close HTML for a recently opened container onto the stack.
*
* @param string $type The type of container. This is checked when {@link pop()}
* is called and must match, otherwise a developer debug warning is output.
* @param string $closehtml The HTML required to close the container.
* @return void
*/
public function push($type, $closehtml) {
$container = new stdClass;
@@ -1243,6 +1268,7 @@ class xhtml_container_stack {
* Pop the HTML for the next closing container from the stack. The $type
* must match the type passed when the container was opened, otherwise a
* warning will be output.
*
* @param string $type The type of container.
* @return string the HTML required to close the container.
*/
@@ -1270,6 +1296,7 @@ class xhtml_container_stack {
* Close all but the last open container. This is useful in places like error
* handling, where you want to close all the open containers (apart from <body>)
* before outputting the error message.
*
* @param bool $shouldbenone assert that the stack should be empty now - causes a
* developer debug warning if it isn't.
* @return string the HTML required to close any open containers inside <body>.
@@ -1292,7 +1319,6 @@ class xhtml_container_stack {
* class without properly emptying the stack (for example, in a unit test).
* Calling this method stops the destruct method from outputting a developer
* debug warning. After calling this method, the instance can no longer be used.
* @return void
*/
public function discard() {
$this->opencontainers = null;
@@ -1300,9 +1326,9 @@ class xhtml_container_stack {
/**
* Adds an entry to the log.
*
* @param string $action The name of the action
* @param string $type The type of action
* @return void
*/
protected function log($action, $type) {
$this->log[] = '<li>' . $action . ' ' . $type . ' at:' .
@@ -1311,9 +1337,10 @@ class xhtml_container_stack {
/**
* Outputs the log's contents as a HTML list.
*
* @return string HTML list of the log
*/
protected function output_log() {
return '<ul>' . implode("\n", $this->log) . '</ul>';
}
}
}
+262 -92
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -18,11 +17,20 @@
/**
* Classes for rendering HTML output for Moodle.
*
* Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
* Please see {@link http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML}
* for an overview.
*
* @package core
* @subpackage lib
* Included in this file are the primary renderer classes:
* - renderer_base: The renderer outline class that all renderers
* should inherit from.
* - core_renderer: The standard HTML renderer.
* - core_renderer_cli: An adaption of the standard renderer for CLI scripts.
* - core_renderer_ajax: An adaption of the standard renderer for AJAX scripts.
* - plugin_renderer_base: A renderer class that should be extended by all
* plugin renderers.
*
* @package core
* @category output
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -37,19 +45,35 @@ defined('MOODLE_INTERNAL') || die();
* Also has methods to facilitate generating HTML output.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class renderer_base {
/** @var xhtml_container_stack the xhtml_container_stack to use. */
/**
* @var xhtml_container_stack The xhtml_container_stack to use.
*/
protected $opencontainers;
/** @var moodle_page the page we are rendering for. */
/**
* @var moodle_page The Moodle page the renderer has been created to assist with.
*/
protected $page;
/** @var requested rendering target */
/**
* @var string The requested rendering target.
*/
protected $target;
/**
* Constructor
*
* The constructor takes two arguments. The first is the page that the renderer
* has been created to assist with, and the second is the target.
* The target is an additional identifier that can be used to load different
* renderers for different options.
*
* @param moodle_page $page the page we are doing output for.
* @param string $target one of rendering target constants
*/
@@ -61,6 +85,13 @@ class renderer_base {
/**
* Returns rendered widget.
*
* The provided widget needs to be an object that extends the renderable
* interface.
* If will then be rendered by a method based upon the classname for the widget.
* For instance a widget of class `crazywidget` will be rendered by a protected
* render_crazywidget method of this renderer.
*
* @param renderable $widget instance with renderable interface
* @return string
*/
@@ -73,12 +104,17 @@ class renderer_base {
}
/**
* Adds JS handlers needed for event execution for one html element id
* @param component_action $actions
* Adds a JS action for the element with the provided id.
*
* This method adds a JS event for the provided component action to the page
* and then returns the id that the event has been attached to.
* If no id has been provided then a new ID is generated by {@link html_writer::random_id()}
*
* @param component_action $action
* @param string $id
* @return string id of element, either original submitted or random new if not supplied
*/
public function add_action_handler(component_action $action, $id=null) {
public function add_action_handler(component_action $action, $id = null) {
if (!$id) {
$id = html_writer::random_id($action->event);
}
@@ -87,7 +123,8 @@ class renderer_base {
}
/**
* Have we started output yet?
* Returns true is output has already started, and false if not.
*
* @return boolean true if the header has been printed.
*/
public function has_started() {
@@ -96,6 +133,7 @@ class renderer_base {
/**
* Given an array or space-separated list of classes, prepares and returns the HTML class attribute value
*
* @param mixed $classes Space-separated string or array of classes
* @return string HTML class attribute value
*/
@@ -108,6 +146,7 @@ class renderer_base {
/**
* Return the moodle_url for an image.
*
* The exact image location and extension is determined
* automatically by searching for gif|png|jpg|jpeg, please
* note there can not be diferent images with the different
@@ -138,19 +177,24 @@ class renderer_base {
/**
* Basis for all plugin renderers.
*
* @author Petr Skoda (skodak)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @copyright Petr Skoda (skodak)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class plugin_renderer_base extends renderer_base {
/**
* A reference to the current general renderer probably {@see core_renderer}
* @var renderer_base
* @var renderer_base|core_renderer A reference to the current renderer.
* The renderer provided here will be determined by the page but will in 90%
* of cases by the {@link core_renderer}
*/
protected $output;
/**
* Constructor method, calls the parent constructor
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
@@ -160,7 +204,8 @@ class plugin_renderer_base extends renderer_base {
}
/**
* Returns rendered widget.
* Renders the provided widget and returns the HTML to display it.
*
* @param renderable $widget instance with renderable interface
* @return string
*/
@@ -198,30 +243,50 @@ class plugin_renderer_base extends renderer_base {
* The standard implementation of the core_renderer interface.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class core_renderer extends renderer_base {
/**
* Do NOT use, please use <?php echo $OUTPUT->main_content() ?>
* in layout files instead.
* @var string used in {@link header()}.
* @deprecated
* @var string used in {@link core_renderer::header()}.
*/
const MAIN_CONTENT_TOKEN = '[MAIN CONTENT GOES HERE]';
/** @var string used to pass information from {@link doctype()} to {@link standard_head_html()}. */
/**
* @var string Used to pass information from {@link core_renderer::doctype()} to
* {@link core_renderer::standard_head_html()}.
*/
protected $contenttype;
/** @var string used by {@link redirect_message()} method to communicate with {@link header()}. */
/**
* @var string Used by {@link core_renderer::redirect_message()} method to communicate
* with {@link core_renderer::header()}.
*/
protected $metarefreshtag = '';
/** @var string unique token */
/**
* @var string Unique token for the closing HTML
*/
protected $unique_end_html_token;
/** @var string unique token */
/**
* @var string Unique token for performance information
*/
protected $unique_performance_info_token;
/** @var string unique token */
/**
* @var string Unique token for the main content.
*/
protected $unique_main_content_token;
/**
* Constructor
*
* @param moodle_page $page the page we are doing output for.
* @param string $target one of rendering target constants
*/
@@ -238,6 +303,7 @@ class core_renderer extends renderer_base {
/**
* Get the DOCTYPE declaration that should be used with this page. Designed to
* be called in theme layout.php files.
*
* @return string the DOCTYPE declaration (and any XML prologue) that should be used.
*/
public function doctype() {
@@ -271,6 +337,7 @@ class core_renderer extends renderer_base {
/**
* The attributes that should be added to the <html> tag. Designed to
* be called in theme layout.php files.
*
* @return string HTML fragment.
*/
public function htmlattributes() {
@@ -281,6 +348,7 @@ class core_renderer extends renderer_base {
* The standard tags (meta tags, links to stylesheets and JavaScript, etc.)
* that should be included in the <head> tag. Designed to be called in theme
* layout.php files.
*
* @return string HTML fragment.
*/
public function standard_head_html() {
@@ -354,6 +422,7 @@ class core_renderer extends renderer_base {
/**
* The standard tags (typically skip links) that should be output just inside
* the start of the <body> tag. Designed to be called in theme layout.php files.
*
* @return string HTML fragment.
*/
public function standard_top_of_body_html() {
@@ -369,14 +438,15 @@ class core_renderer extends renderer_base {
* The standard tags (typically performance information and validation links,
* if we are in developer debug mode) that should be output in the footer area
* of the page. Designed to be called in theme layout.php files.
*
* @return string HTML fragment.
*/
public function standard_footer_html() {
global $CFG, $SCRIPT;
// This function is normally called from a layout.php file in {@link header()}
// This function is normally called from a layout.php file in {@link core_renderer::header()}
// but some of the content won't be known until later, so we return a placeholder
// for now. This will be replaced with the real content in {@link footer()}.
// for now. This will be replaced with the real content in {@link core_renderer::footer()}.
$output = $this->unique_performance_info_token;
if ($this->page->devicetypeinuse == 'legacy') {
// The legacy theme is in use print the notification
@@ -416,6 +486,7 @@ class core_renderer extends renderer_base {
/**
* Returns standard main content placeholder.
* Designed to be called in theme layout.php files.
*
* @return string HTML fragment.
*/
public function main_content() {
@@ -425,18 +496,20 @@ class core_renderer extends renderer_base {
/**
* The standard tags (typically script tags that are not needed earlier) that
* should be output after everything else, . Designed to be called in theme layout.php files.
*
* @return string HTML fragment.
*/
public function standard_end_of_body_html() {
// This function is normally called from a layout.php file in {@link header()}
// This function is normally called from a layout.php file in {@link core_renderer::header()}
// but some of the content won't be known until later, so we return a placeholder
// for now. This will be replaced with the real content in {@link footer()}.
// for now. This will be replaced with the real content in {@link core_renderer::footer()}.
return $this->unique_end_html_token;
}
/**
* Return the standard string that says whether you are logged in (and switched
* roles/logged in as another user).
*
* @return string HTML fragment.
*/
public function login_info() {
@@ -522,6 +595,7 @@ class core_renderer extends renderer_base {
/**
* Return the 'back' link that normally appears in the footer.
*
* @return string HTML fragment.
*/
public function home_link() {
@@ -666,6 +740,11 @@ class core_renderer extends renderer_base {
/**
* Renders and outputs the page layout file.
*
* This is done by preparing the normal globals available to a script, and
* then including the layout file provided by the current theme for the
* requested layout.
*
* @param string $layoutfile The name of the layout file
* @return string HTML code
*/
@@ -690,6 +769,7 @@ class core_renderer extends renderer_base {
/**
* Outputs the page's footer
*
* @return string HTML fragment
*/
public function footer() {
@@ -727,6 +807,7 @@ class core_renderer extends renderer_base {
* Close all but the last open container. This is useful in places like error
* handling, where you want to close all the open containers (apart from <body>)
* before outputting the error message.
*
* @param bool $shouldbenone assert that the stack should be empty now - causes a
* developer debug warning if it isn't.
* @return string the HTML required to close any open containers inside <body>.
@@ -737,7 +818,8 @@ class core_renderer extends renderer_base {
/**
* Returns lang menu or '', this method also checks forcing of languages in courses.
* @return string
*
* @return string The lang menu HTML or empty string
*/
public function lang_menu() {
global $CFG;
@@ -766,8 +848,9 @@ class core_renderer extends renderer_base {
/**
* Output the row of editing icons for a block, as defined by the controls array.
*
* @param array $controls an array like {@link block_contents::$controls}.
* @return HTML fragment.
* @return string HTML fragment.
*/
public function block_controls($controls) {
if (empty($controls)) {
@@ -786,7 +869,7 @@ class core_renderer extends renderer_base {
* Prints a nice side block with an optional header.
*
* The content is described
* by a {@link block_contents} object.
* by a {@link core_renderer::block_contents} object.
*
* <div id="inst{$instanceid}" class="block_{$blockname} block">
* <div class="header"></div>
@@ -803,7 +886,7 @@ class core_renderer extends renderer_base {
* @param string $region the region the block is appearing in.
* @return string the HTML to be output.
*/
function block(block_contents $bc, $region) {
public function block(block_contents $bc, $region) {
$bc = clone($bc); // Avoid messing up the object passed in.
if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
$bc->collapsible = block_contents::NOT_HIDEABLE;
@@ -909,8 +992,8 @@ class core_renderer extends renderer_base {
/**
* Calls the JS require function to hide a block.
*
* @param block_contents $bc A block_contents object
* @return void
*/
protected function init_block_hider_js(block_contents $bc) {
if (!empty($bc->attributes['id']) and $bc->collapsible != block_contents::NOT_HIDEABLE) {
@@ -928,6 +1011,7 @@ class core_renderer extends renderer_base {
/**
* Render the contents of a block_list.
*
* @param array $icons the icon for each item.
* @param array $items the content of each item.
* @return string HTML
@@ -950,6 +1034,7 @@ class core_renderer extends renderer_base {
/**
* Output all the blocks in a particular region.
*
* @param string $region the name of a region on this page.
* @return string the HTML to be output.
*/
@@ -971,6 +1056,7 @@ class core_renderer extends renderer_base {
/**
* Output a place where the block that is currently being moved can be dropped.
*
* @param block_move_target $target with the necessary details.
* @return string the HTML to be output.
*/
@@ -985,7 +1071,7 @@ class core_renderer extends renderer_base {
* @param string $text HTML fragment
* @param component_action $action
* @param array $attributes associative array of html link attributes + disabled
* @return HTML fragment
* @return string HTML fragment
*/
public function action_link($url, $text, component_action $action = null, array $attributes=null) {
if (!($url instanceof moodle_url)) {
@@ -997,7 +1083,11 @@ class core_renderer extends renderer_base {
}
/**
* Implementation of action_link rendering
* Renders an action_link object.
*
* The provided link is renderer and the HTML returned. At the same time the
* associated actions are setup in JS by {@link core_renderer::add_action_handler()}
*
* @param action_link $link
* @return string HTML fragment
*/
@@ -1037,7 +1127,11 @@ class core_renderer extends renderer_base {
/**
* Similar to action_link, image is used instead of the text
* Renders an action_icon.
*
* This function uses the {@link core_renderer::action_link()} method for the
* most part. What it does different is prepare the icon as HTML and use it
* as the link text.
*
* @param string|moodle_url $url A string URL or moodel_url
* @param pix_icon $pixicon
@@ -1131,7 +1225,10 @@ class core_renderer extends renderer_base {
}
/**
* Internal implementation of single_button rendering
* Renders a single button widget.
*
* This will return HTML to display a form containing a single button.
*
* @param single_button $button
* @return string HTML fragment
*/
@@ -1184,6 +1281,7 @@ class core_renderer extends renderer_base {
/**
* Returns a form with a single select widget.
*
* @param moodle_url $url form action target, includes hidden fields
* @param string $name name of selection field - the changing parameter in url
* @param array $options list of options
@@ -1192,7 +1290,7 @@ class core_renderer extends renderer_base {
* @param string $formid
* @return string HTML fragment
*/
public function single_select($url, $name, array $options, $selected='', $nothing=array(''=>'choosedots'), $formid=null) {
public function single_select($url, $name, array $options, $selected = '', $nothing = array('' => 'choosedots'), $formid = null) {
if (!($url instanceof moodle_url)) {
$url = new moodle_url($url);
}
@@ -1203,6 +1301,7 @@ class core_renderer extends renderer_base {
/**
* Internal implementation of single_select rendering
*
* @param single_select $select
* @return string HTML fragment
*/
@@ -1271,20 +1370,22 @@ class core_renderer extends renderer_base {
/**
* Returns a form with a url select widget.
*
* @param array $urls list of urls - array('/course/view.php?id=1'=>'Frontpage', ....)
* @param string $selected selected element
* @param array $nothing
* @param string $formid
* @return string HTML fragment
*/
public function url_select(array $urls, $selected, $nothing=array(''=>'choosedots'), $formid=null) {
public function url_select(array $urls, $selected, $nothing = array('' => 'choosedots'), $formid = null) {
$select = new url_select($urls, $selected, $nothing, $formid);
return $this->render($select);
}
/**
* Internal implementation of url_select rendering
* @param single_select $select
*
* @param url_select $select
* @return string HTML fragment
*/
protected function render_url_select(url_select $select) {
@@ -1391,6 +1492,7 @@ class core_renderer extends renderer_base {
/**
* Returns a string containing a link to the user documentation.
* Also contains an icon by default. Shown to teachers and admin only.
*
* @param string $path The page link after doc root and language, no leading slash.
* @param string $text The text to be displayed for the link
* @return string
@@ -1411,7 +1513,8 @@ class core_renderer extends renderer_base {
}
/**
* Render icon
* Return HTML for a pix_icon.
*
* @param string $pix short pix name
* @param string $alt mandatory alt attribute
* @param string $component standard compoennt name like 'moodle', 'mod_forum', etc.
@@ -1424,7 +1527,8 @@ class core_renderer extends renderer_base {
}
/**
* Render icon
* Renders a pix_icon widget and returns the HTML to display it.
*
* @param pix_icon $icon
* @return string HTML fragment
*/
@@ -1435,7 +1539,8 @@ class core_renderer extends renderer_base {
}
/**
* Render emoticon
* Return HTML to display an emoticon icon.
*
* @param pix_emoticon $emoticon
* @return string HTML fragment
*/
@@ -1446,9 +1551,11 @@ class core_renderer extends renderer_base {
}
/**
* Produces the html that represents this rating in the UI
* @param $page the page object on which this rating will appear
*/
* Produces the html that represents this rating in the UI
*
* @param rating $rating the page object on which this rating will appear
* @return string
*/
function render_rating(rating $rating) {
global $CFG, $USER;
@@ -1540,9 +1647,10 @@ class core_renderer extends renderer_base {
return $ratinghtml;
}
/*
/**
* Centered heading with attached help button (same title text)
* and optional icon attached
* and optional icon attached.
*
* @param string $text A heading text
* @param string $helpidentifier The keyword that defines a help page
* @param string $component component name
@@ -1550,7 +1658,7 @@ class core_renderer extends renderer_base {
* @param string $iconalt icon alt text
* @return string HTML fragment
*/
public function heading_with_help($text, $helpidentifier, $component='moodle', $icon='', $iconalt='') {
public function heading_with_help($text, $helpidentifier, $component = 'moodle', $icon = '', $iconalt = '') {
$image = '';
if ($icon) {
$image = $this->pix_icon($icon, $iconalt, $component, array('class'=>'icon'));
@@ -1565,10 +1673,10 @@ class core_renderer extends renderer_base {
}
/**
* Print a help icon.
* Returns HTML to display a help icon.
*
* @deprecated since Moodle 2.0
* @param string $page The keyword that defines a help page
* @param string $helpidentifier The keyword that defines a help page
* @param string $title A descriptive text for accessibility only
* @param string $component component name
* @param string|bool $linktext true means use $title as link text, string means link text value
@@ -1587,7 +1695,8 @@ class core_renderer extends renderer_base {
/**
* Implementation of user image rendering.
* @param help_icon $helpicon
*
* @param old_help_icon $helpicon A help icon instance
* @return string HTML fragment
*/
protected function render_old_help_icon(old_help_icon $helpicon) {
@@ -1629,7 +1738,7 @@ class core_renderer extends renderer_base {
}
/**
* Print a help icon.
* Returns HTML to display a help icon.
*
* @param string $identifier The keyword that defines a help page
* @param string $component component name
@@ -1649,7 +1758,8 @@ class core_renderer extends renderer_base {
/**
* Implementation of user image rendering.
* @param help_icon $helpicon
*
* @param help_icon $helpicon A help icon instance
* @return string HTML fragment
*/
protected function render_help_icon(help_icon $helpicon) {
@@ -1693,11 +1803,11 @@ class core_renderer extends renderer_base {
}
/**
* Print scale help icon.
* Returns HTML to display a scale help icon.
*
* @param int $courseid
* @param object $scale instance
* @return string HTML fragment
* @param stdClass $scale instance
* @return string HTML fragment
*/
public function help_icon_scale($courseid, stdClass $scale) {
global $CFG;
@@ -1717,8 +1827,9 @@ class core_renderer extends renderer_base {
/**
* Creates and returns a spacer image with optional line break.
*
* @param array $attributes
* @param boo spacer
* @param array $attributes Any HTML attributes to add to the spaced.
* @param bool $br Include a BR after the spacer.... DON'T USE THIS. Don't be
* laxy do it with CSS which is a much better solution.
* @return string HTML fragment
*/
public function spacer(array $attributes = null, $br = false) {
@@ -1741,7 +1852,7 @@ class core_renderer extends renderer_base {
}
/**
* Print the specified user's avatar.
* Returns HTML to display the specified user's avatar.
*
* User avatar may be obtained in two ways:
* <pre>
@@ -1756,7 +1867,7 @@ class core_renderer extends renderer_base {
* $OUTPUT->render($userpic);
* </pre>
*
* @param object Object with at least fields id, picture, imagealt, firstname, lastname
* @param stdClass $user Object with at least fields id, picture, imagealt, firstname, lastname
* If any of these are missing, the database is queried. Avoid this
* if at all possible, particularly for reports. It is very bad for performance.
* @param array $options associative array with user picture options, used only if not a user_picture object,
@@ -1781,6 +1892,7 @@ class core_renderer extends renderer_base {
/**
* Internal implementation of user image rendering.
*
* @param user_picture $userpicture
* @return string
*/
@@ -1850,6 +1962,7 @@ class core_renderer extends renderer_base {
/**
* Internal implementation of file tree viewer items rendering.
*
* @param array $dir
* @return string
*/
@@ -1869,8 +1982,9 @@ class core_renderer extends renderer_base {
return $result;
}
/**
* Print the file picker
* Returns HTML to display the file picker
*
* <pre>
* $OUTPUT->file_picker($options);
@@ -1890,8 +2004,10 @@ class core_renderer extends renderer_base {
$fp = new file_picker($options);
return $this->render($fp);
}
/**
* Internal implementation of file picker rendering.
*
* @param file_picker $fp
* @return string
*/
@@ -1946,7 +2062,7 @@ EOD;
}
/**
* Prints the 'Update this Modulename' button that appears on module pages.
* Returns HTML to display the 'Update this Modulename' button that appears on module pages.
*
* @param string $cmid the course_module id.
* @param string $modulename the module name, eg. "forum", "quiz" or "workshop"
@@ -1965,7 +2081,8 @@ EOD;
}
/**
* Prints a "Turn editing on/off" button in a form.
* Returns HTML to display a "Turn editing on/off" button in a form.
*
* @param moodle_url $url The URL + params to send through when clicking the button
* @return string HTML the button
*/
@@ -1984,7 +2101,7 @@ EOD;
}
/**
* Prints a simple button to close a window
* Returns HTML to display a simple button to close a window
*
* @param string $text The lang string for the button's label (already output from get_string())
* @return string html fragment
@@ -2002,6 +2119,7 @@ EOD;
/**
* Output an error message. By default wraps the error message in <span class="error">.
* If the error message is blank, nothing is output.
*
* @param string $message the error message.
* @return string the HTML to output.
*/
@@ -2115,7 +2233,7 @@ EOD;
}
/**
* Print a continue button that goes to a particular URL.
* Returns HTML to display a continue button that goes to a particular URL.
*
* @param string|moodle_url $url The url the button goes to.
* @return string the HTML to output.
@@ -2131,7 +2249,7 @@ EOD;
}
/**
* Prints a single paging bar to provide access to other pages (usually in a search)
* Returns HTML to display a single paging bar to provide access to other pages (usually in a search)
*
* @param int $totalcount The total number of entries available to be paged through
* @param int $page The page you are currently viewing
@@ -2147,6 +2265,7 @@ EOD;
/**
* Internal implementation of paging bar rendering.
*
* @param paging_bar $pagingbar
* @return string
*/
@@ -2184,6 +2303,7 @@ EOD;
/**
* Output the place a skip link goes to.
*
* @param string $id The target name from the corresponding $PAGE->requires->skip_link_to($target) call.
* @return string the HTML to output.
*/
@@ -2193,6 +2313,7 @@ EOD;
/**
* Outputs a heading
*
* @param string $text The text of the heading
* @param int $level The level of importance of the heading. Defaulting to 2
* @param string $classes A space-separated list of CSS classes
@@ -2209,6 +2330,7 @@ EOD;
/**
* Outputs a box.
*
* @param string $contents The contents of the box
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
@@ -2220,6 +2342,7 @@ EOD;
/**
* Outputs the opening section of a box.
*
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
* @return string the HTML to output.
@@ -2232,6 +2355,7 @@ EOD;
/**
* Outputs the closing section of a box.
*
* @return string the HTML to output.
*/
public function box_end() {
@@ -2240,6 +2364,7 @@ EOD;
/**
* Outputs a container.
*
* @param string $contents The contents of the box
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
@@ -2251,6 +2376,7 @@ EOD;
/**
* Outputs the opening section of a container.
*
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
* @return string the HTML to output.
@@ -2263,6 +2389,7 @@ EOD;
/**
* Outputs the closing section of a container.
*
* @return string the HTML to output.
*/
public function container_end() {
@@ -2284,12 +2411,11 @@ EOD;
* <</ul>>
* </pre>
*
* @param array[]tree_item $items
* @param array[string]string $attrs html attributes passed to the top of
* the list
* @param array $items
* @param array $attrs html attributes passed to the top ofs the list
* @return string HTML
*/
function tree_block_contents($items, $attrs=array()) {
public function tree_block_contents($items, $attrs = array()) {
// exit if empty, we don't want an empty ul element
if (empty($items)) {
return '';
@@ -2333,6 +2459,7 @@ EOD;
/**
* Return the navbar content so that it can be echoed out by the layout
*
* @return string XHTML navbar
*/
public function navbar() {
@@ -2360,6 +2487,12 @@ EOD;
return $navbarcontent;
}
/**
* Renders a navigation node object.
*
* @param navigation_node $item The navigation node to render.
* @return string HTML fragment
*/
protected function render_navigation_node(navigation_node $item) {
$content = $item->get_content();
$title = $item->get_title();
@@ -2410,6 +2543,7 @@ EOD;
* If the theme does not set characters, appropriate defaults
* are set automatically. Please DO NOT
* use &lt; &gt; &raquo; - these are confusing for blind users.
*
* @return string
*/
public function rarrow() {
@@ -2423,6 +2557,7 @@ EOD;
* If the theme does not set characters, appropriate defaults
* are set automatically. Please DO NOT
* use &lt; &gt; &raquo; - these are confusing for blind users.
*
* @return string
*/
public function larrow() {
@@ -2496,7 +2631,7 @@ EOD;
* The custom menu this method produces makes use of the YUI3 menunav widget
* and requires very specific html elements and classes.
*
* @see render_custom_menu()
* @see core:renderer::render_custom_menu()
*
* @staticvar int $submenucount
* @param custom_menu_item $menunode
@@ -2574,20 +2709,22 @@ EOD;
}
}
/// RENDERERS
/**
* A renderer that generates output for command-line scripts.
*
* The implementation of this renderer is probably incomplete.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class core_renderer_cli extends core_renderer {
/**
* Returns the page header.
*
* @return string HTML fragment
*/
public function header() {
@@ -2596,6 +2733,7 @@ class core_renderer_cli extends core_renderer {
/**
* Returns a template fragment representing a Heading.
*
* @param string $text The text of the heading
* @param int $level The level of importance of the heading
* @param string $classes A space-separated list of CSS classes
@@ -2616,6 +2754,7 @@ class core_renderer_cli extends core_renderer {
/**
* Returns a template fragment representing a fatal error.
*
* @param string $message The message to output
* @param string $moreinfourl URL where more info can be found about the error
* @param string $link Link for the Continue button
@@ -2640,6 +2779,7 @@ class core_renderer_cli extends core_renderer {
/**
* Returns a template fragment representing a notification.
*
* @param string $message The message to include
* @param string $classes A space-separated list of CSS classes
* @return string A template fragment for a notification
@@ -2661,12 +2801,16 @@ class core_renderer_cli extends core_renderer {
* encoded error messages, all other output is ignored.
*
* @copyright 2010 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class core_renderer_ajax extends core_renderer {
/**
* Returns a template fragment representing a fatal error.
*
* @param string $message The message to output
* @param string $moreinfourl URL where more info can be found about the error
* @param string $link Link for the Continue button
@@ -2697,12 +2841,30 @@ class core_renderer_ajax extends core_renderer {
return json_encode($e);
}
public function notification($message, $classes = 'notifyproblem') {
}
/**
* Used to display a notification.
* For the AJAX notifications are discarded.
*
* @param string $message
* @param string $classes
*/
public function notification($message, $classes = 'notifyproblem') {}
public function redirect_message($encodedurl, $message, $delay, $debugdisableredirect) {
}
/**
* Used to display a redirection message.
* AJAX redirections should not occur and as such redirection messages
* are discarded.
*
* @param moodle_url|string $encodedurl
* @param string $message
* @param int $delay
* @param bool $debugdisableredirect
*/
public function redirect_message($encodedurl, $message, $delay, $debugdisableredirect) {}
/**
* Prepares the start of an AJAX output.
*/
public function header() {
// unfortunately YUI iframe upload does not support application/json
if (!empty($_FILES)) {
@@ -2711,7 +2873,7 @@ class core_renderer_ajax extends core_renderer {
@header('Content-type: application/json; charset=utf-8');
}
/// Headers to make it not cacheable and json
// Headers to make it not cacheable and json
@header('Cache-Control: no-store, no-cache, must-revalidate');
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@@ -2720,10 +2882,18 @@ class core_renderer_ajax extends core_renderer {
@header('Accept-Ranges: none');
}
public function footer() {
}
public function heading($text, $level = 2, $classes = 'main', $id = null) {
}
}
/**
* There is no footer for an AJAX request, however we must override the
* footer method to prevent the default footer.
*/
public function footer() {}
/**
* No need for headers in an AJAX request... this should never happen.
* @param string $text
* @param int $level
* @param string $classes
* @param string $id
*/
public function heading($text, $level = 2, $classes = 'main', $id = null) {}
}
+92 -56
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,20 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library functions to facilitate the use of JavaScript in Moodle.
*
* @package core
* @subpackage lib
* @copyright 2009 Tim Hunt, 2010 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* Note: you can find history of this file in lib/ajax/ajaxlib.php
*
* @copyright 2009 Tim Hunt, 2010 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core
* @category output
*/
defined('MOODLE_INTERNAL') || die();
// note: you can find history of this file in lib/ajax/ajaxlib.php
/**
* This class tracks all the things that are needed by the current page.
*
@@ -53,63 +51,99 @@ defined('MOODLE_INTERNAL') || die();
* individual methods for details.
*
* @copyright 2009 Tim Hunt, 2010 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package core
* @category output
*/
class page_requirements_manager {
/** List of string available from JS */
protected $stringsforjs = array();
/** List of JS variables to be initialised */
protected $jsinitvariables = array('head'=>array(), 'footer'=>array());
/** Included JS scripts */
protected $jsincludes = array('head'=>array(), 'footer'=>array());
/** List of needed function calls */
protected $jscalls = array('normal'=>array(), 'ondomready'=>array());
/**
* List of skip links, those are needed for accessibility reasons
* @var array
* @var array List of string available from JS
*/
protected $stringsforjs = array();
/**
* @var array List of JS variables to be initialised
*/
protected $jsinitvariables = array('head'=>array(), 'footer'=>array());
/**
* @var array Included JS scripts
*/
protected $jsincludes = array('head'=>array(), 'footer'=>array());
/**
* @var array List of needed function calls
*/
protected $jscalls = array('normal'=>array(), 'ondomready'=>array());
/**
* @var array List of skip links, those are needed for accessibility reasons
*/
protected $skiplinks = array();
/**
* Javascript code used for initialisation of page, it should be relatively small
* @var array
* @var array Javascript code used for initialisation of page, it should
* be relatively small
*/
protected $jsinitcode = array();
/**
* Theme sheets, initialised only from core_renderer
* @var array of moodle_url
* @var array of moodle_url Theme sheets, initialised only from core_renderer
*/
protected $cssthemeurls = array();
/**
* List of custom theme sheets, these are strongly discouraged!
* @var array of moodle_url List of custom theme sheets, these are strongly discouraged!
* Useful mostly only for CSS submitted by teachers that is not part of the theme.
* @var array of moodle_url
*/
protected $cssurls = array();
/**
* List of requested event handlers
* @var array
* @var array List of requested event handlers
*/
protected $eventhandlers = array();
/**
* Extra modules
* @var array
* @var array Extra modules
*/
protected $extramodules = array();
/** Flag indicated head stuff already printed */
/**
* @var bool Flag indicated head stuff already printed
*/
protected $headdone = false;
/** Flag indicating top of body already printed */
/**
* @var bool Flag indicating top of body already printed
*/
protected $topofbodydone = false;
/** YUI PHPLoader instance responsible for YUI2 loading from PHP only */
/**
* @var YAHOO_util_Loader YUI PHPLoader instance responsible for YUI2 loading
* from PHP only
*/
protected $yui2loader;
/** YUI PHPLoader instance responsible for YUI3 loading from PHP only */
/**
* @var stdClass YUI PHPLoader instance responsible for YUI3 loading from PHP only
*/
protected $yui3loader;
/** YUI loader information for YUI3 loading from javascript */
/**
* @var stdClass YUI loader information for YUI3 loading from javascript
*/
protected $M_yui_loader;
/** some config vars exposed in JS, please no secret stuff there */
/**
* @var array Some config vars exposed in JS, please no secret stuff there
*/
protected $M_cfg;
/** stores debug backtraces from when JS modules were included in the page */
/**
* @var array Stores debug backtraces from when JS modules were included in the page
*/
protected $debug_moduleloadstacktraces = array();
/**
@@ -205,8 +239,8 @@ class page_requirements_manager {
}
/**
* This method adds yui2 modules into the yui3 JS loader-
* @return void
* This method adds yui2 modules into the yui3 JS loader so that they can
* be easily included for use in JavaScript.
*/
protected function add_yui2_modules() {
//note: this function is definitely not perfect, because
@@ -319,9 +353,8 @@ class page_requirements_manager {
* @param string|moodle_url $url The path to the .js file, relative to $CFG->dirroot / $CFG->wwwroot.
* For example '/mod/mymod/customscripts.js'; use moodle_url for external scripts
* @param bool $inhead initialise in head
* @return void
*/
public function js($url, $inhead=false) {
public function js($url, $inhead = false) {
$url = $this->js_fix_url($url);
$where = $inhead ? 'head' : 'footer';
$this->jsincludes[$where][$url->out()] = $url;
@@ -342,7 +375,6 @@ class page_requirements_manager {
* is put into the page header, otherwise it is loaded in the page footer.
*
* @param string|array $libname the name of the YUI2 library you require. For example 'autocomplete'.
* @return void
*/
public function yui2_lib($libname) {
$libnames = (array)$libname;
@@ -353,6 +385,7 @@ class page_requirements_manager {
/**
* Returns the actual url through which a script is served.
*
* @param moodle_url|string $url full moodle url, or shortened path to script
* @return moodle_url
*/
@@ -380,6 +413,7 @@ class page_requirements_manager {
/**
* Find out if JS module present and return details.
*
* @param string $component name of component in frankenstyle, ex: core_group, mod_forum
* @return array description of module or null if not found
*/
@@ -388,7 +422,6 @@ class page_requirements_manager {
$module = null;
if (strpos($component, 'core_') === 0) {
// must be some core stuff - list here is not complete, this is just the stuff used from multiple places
// so that we do nto have to repeat the definition of these modules over and over again
@@ -488,7 +521,8 @@ class page_requirements_manager {
/**
* Append YUI3 module to default YUI3 JS loader.
* The structure of module array is described at http://developer.yahoo.com/yui/3/yui/:
* The structure of module array is described at {@link http://developer.yahoo.com/yui/3/yui/}
*
* @param string|array $module name of module (details are autodetected), or full module specification as array
* @return void
*/
@@ -616,6 +650,7 @@ class page_requirements_manager {
/**
* Add theme stylkesheet to page - do not use from plugin code,
* this should be called only from the core renderer!
*
* @param moodle_url $stylesheet
* @return void
*/
@@ -667,9 +702,9 @@ class page_requirements_manager {
* @param array $arguments and array of arguments to be passed to the function.
* When generating the function call, this will be escaped using json_encode,
* so passing objects and arrays should work.
* @param bool $ondomready
* @param int $delay
* @return void
* @param bool $ondomready If tru the function is only called when the dom is
* ready for manipulation.
* @param int $delay The delay before the function is called.
*/
public function js_function_call($function, array $arguments = null, $ondomready = false, $delay = 0) {
$where = $ondomready ? 'ondomready' : 'normal';
@@ -739,7 +774,6 @@ class page_requirements_manager {
* already loaded.
* @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM)
* @param array $module JS module specification array
* @return void
*/
public function js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) {
$jscode = js_writer::function_call_with_Y($function, $extraarguments);
@@ -761,7 +795,6 @@ class page_requirements_manager {
* @param string $jscode
* @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM)
* @param array $module JS module specification array
* @return void
*/
public function js_init_code($jscode, $ondomready = false, array $module = null) {
$jscode = trim($jscode, " ;\n"). ';';
@@ -812,7 +845,7 @@ class page_requirements_manager {
* alert(M.str.moodle.fullnamedisplay);
*
* To substitute the placeholder at client side, use M.util.get_string()
* function. It implements the same logic as {@see get_string()}:
* function. It implements the same logic as {@link get_string()}:
*
* // require the string in PHP but keep {$a} as it is
* $PAGE->requires->string_for_js('fullnamedisplay', 'moodle');
@@ -905,7 +938,6 @@ class page_requirements_manager {
* @param string $event A valid DOM event (click, mousedown, change etc.)
* @param string $function The name of the function to call
* @param array $arguments An optional array of argument parameters to pass to the function
* @return void
*/
public function event_handler($selector, $event, $function, array $arguments = null) {
$this->eventhandlers[] = array('selector'=>$selector, 'event'=>$event, 'function'=>$function, 'arguments'=>$arguments);
@@ -944,7 +976,7 @@ class page_requirements_manager {
/**
* Returns js code to be executed when Y is available.
* @return unknown_type
* @return string
*/
protected function get_javascript_init_code() {
if (count($this->jsinitcode)) {
@@ -1028,6 +1060,7 @@ class page_requirements_manager {
/**
* Returns html tags needed for inclusion of theme CSS
*
* @return string
*/
protected function get_css_code() {
@@ -1057,6 +1090,7 @@ class page_requirements_manager {
/**
* Adds extra modules specified after printing of page header
*
* @return string
*/
protected function get_extra_modules_code() {
@@ -1205,14 +1239,18 @@ class page_requirements_manager {
}
/**
* @return boolean Have we already output the code in the <head> tag?
* Have we already output the code in the <head> tag?
*
* @return bool
*/
public function is_head_done() {
return $this->headdone;
}
/**
* @return boolean Have we already output the code at the start of the <body> tag?
* Have we already output the code at the start of the <body> tag?
*
* @return bool
*/
public function is_top_of_body_done() {
return $this->topofbodydone;
@@ -1221,7 +1259,6 @@ class page_requirements_manager {
/**
* Invalidate all server and client side JS caches.
* @return void
*/
function js_reset_all_caches() {
global $CFG;
@@ -1229,5 +1266,4 @@ function js_reset_all_caches() {
set_config('jsrev', empty($CFG->jsrev) ? 1 : $CFG->jsrev+1);
fulldelete("$CFG->cachedir/js");
}
}