From a5cb8d6987e90d976330580935339513b66b138e Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 29 Jun 2009 08:17:31 +0000 Subject: [PATCH] MDL-19077 - Finish eliminating customcorners-specific code in core. The custom-corners-specific code now in theme/customcornser/renderers.php and lib/deprecatedlib.php. Also, $CFG->pixpath is now causing more problems than ever. If it is giving your problems, please call $OUTPUT->initialise_deprecated_cfg_pixpath() as a temporary fix. As you can imagine, we are thinking about a better long-term fix, which is why that method as a silly, and easy to grep name. --- lib/deprecatedlib.php | 115 +++++++++++- lib/outputlib.php | 269 ++++++++++++++++----------- lib/weblib.php | 195 +------------------ mod/quiz/edit.php | 22 ++- mod/resource/type/ims/javascript.php | 3 + question/category_class.php | 3 +- theme/custom_corners/README.html | 8 +- theme/custom_corners/config.php | 93 +++++---- theme/custom_corners/renderers.php | 195 +++++++++++++++++++ 9 files changed, 537 insertions(+), 366 deletions(-) create mode 100644 theme/custom_corners/renderers.php diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index c2fca7a794..c0146a2d46 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -1,7 +1,7 @@ . @@ -130,7 +130,7 @@ function isguest($userid=0) { /** * Get the guest user information from the database * - * @todo Is object(user) a correct return type? Or is array the proper return type with a + * @todo Is object(user) a correct return type? Or is array the proper return type with a * note that the contents include all details for a user. * * @return object(user) An associative array with the details of the guest user account. @@ -1567,7 +1567,7 @@ function update_record($table, $dataobject) { * @param mixed $fields * @param mixed $limitfrom * @param mixed $limitnum - + * * @return void Throws an error and does nothing */ function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') { @@ -1727,7 +1727,7 @@ function require_js($lib) { /** * Makes an upload directory for a particular module. * - * This funciton has been deprecated by the file API changes in Moodle 2.0. + * This function has been deprecated by the file API changes in Moodle 2.0. * * @deprecated * @param int $courseid The id of the course in question - maps to id field of 'course' table. @@ -1739,6 +1739,32 @@ function make_mod_upload_directory($courseid) { return make_upload_directory($courseid .'/'. $CFG->moddata); } + +/** + * This is a slight variatoin on the standard_renderer_factory that uses + * custom_corners_core_renderer instead of moodle_core_renderer. + * + * This generates the slightly different HTML that the custom_corners theme expects. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @deprecated Required to make the old $THEME->customcorners setting work. + */ +class custom_corners_renderer_factory extends standard_renderer_factory { + /** + * Constructor. + * @param object $theme the theme we are rendering for. + * @param moodle_page $page the page we are doing output for. + */ + public function __construct($theme, $page) { + global $CFG; + parent::__construct($theme, $page); + require_once($CFG->themedir . '/customcorners/renderers.php'); + $this->renderers = array('core' => new custom_corners_core_renderer($this->opencontainers, $this->page, $this)); + } +} + + /** * Prints some red text using echo * @@ -1959,7 +1985,7 @@ function print_container_end($return=false) { * @param string $style Optional style to display message text in * @param string $align Alignment option * @param bool $return whether to return an output string or echo now - * @return string|bool Depending on $result + * @return string|bool Depending on $result */ function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) { global $OUTPUT; @@ -2111,4 +2137,77 @@ function print_footer($course = NULL, $usercourse = NULL, $return = false) { } else { echo $output; } -} \ No newline at end of file +} + +/** + * Prints a nice side block with an optional header. The content can either + * be a block of HTML or a list of text with optional icons. + * + * @todo Finish documenting this function. Show example of various attributes, etc. + * + * @static int $block_id Increments for each call to the function + * @param string $heading HTML for the heading. Can include full HTML or just + * plain text - plain text will automatically be enclosed in the appropriate + * heading tags. + * @param string $content HTML for the content + * @param array $list an alternative to $content, it you want a list of things with optional icons. + * @param array $icons optional icons for the things in $list. + * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer"> + * @param array $attributes an array of attribute => value pairs that are put on the + * outer div of this block. If there is a class attribute ' sideblock' gets appended to it. If there isn't + * already a class, class='sideblock' is used. + * @param string $title Plain text title, as embedded in the $heading. + * @deprecated + */ +function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') { + global $OUTPUT; + $bc = new block_contents(); + $bc->heading = $heading; + $bc->content = $content; + $bc->list = $list; + $bc->icons = $icons; + $bc->footer = $footer; + $bc->title = $title; + + if (isset($attributes['id'])) { + $bc->id = $attributes['id']; + unset($attributes['id']); + } + if (isset($attributes['class'])) { + $bc->set_classes($attributes['class']); + unset($attributes['class']); + } + $bc->attributes = $attributes; + + echo $OUTPUT->block($bc); +} + +/** + * Starts a nice side block with an optional header. + * + * @todo Finish documenting this function + * + * @global object + * @global object + * @param string $heading HTML for the heading. Can include full HTML or just + * plain text - plain text will automatically be enclosed in the appropriate + * heading tags. + * @param array $attributes HTML attributes to apply if possible + * @deprecated + */ +function print_side_block_start($heading='', $attributes = array()) { + throw new coding_exception('print_side_block_start has been deprecated. Please cahnge your code to use $OUTPUT->block().'); +} + +/** + * Print table ending tags for a side block box. + * + * @global object + * @global object + * @param array $attributes HTML attributes to apply if possible [id] + * @param string $title + * @deprecated + */ +function print_side_block_end($attributes = array(), $title='') { + throw new coding_exception('print_side_block_end has been deprecated. Please cahnge your code to use $OUTPUT->block().'); +} diff --git a/lib/outputlib.php b/lib/outputlib.php index 7660c30cbf..251548c476 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -196,29 +196,6 @@ class standard_renderer_factory extends renderer_factory_base { } -/** - * This is a slight variatoin on the standard_renderer_factory that uses - * custom_corners_core_renderer instead of moodle_core_renderer. - * - * This generates the slightly different HTML that the custom_corners theme expects. - * - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class custom_corners_renderer_factory extends standard_renderer_factory { - /** - * Constructor. - * @param object $theme the theme we are rendering for. - * @param moodle_page $page the page we are doing output for. - */ - public function __construct($theme, $page) { - parent::__construct($theme, $page); - $this->renderers = array('core' => new custom_corners_core_renderer($this->opencontainers, $this->page, $this)); - } -} - - /** * This is a slight variation on the standard_renderer_factory used by CLI scripts. * @@ -242,7 +219,7 @@ class cli_renderer_factory extends standard_renderer_factory { /** * 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 * a renderer for 'component', it will create a mytheme_component_renderer or a @@ -313,7 +290,7 @@ class theme_overridden_renderer_factory extends standard_renderer_factory { * exists. Then, a call to $OUTPUT->greeting() will cause the template * /theme/yourtheme/templates/core/greeting.php to be rendered, with the variable * $name available. The greeting.php template might contain - * + * *
  * 

Hello !

*
@@ -421,6 +398,9 @@ class moodle_renderer_base { } } protected function output_attributes($attributes) { + if (empty($attributes)) { + $attributes = array(); + } $output = ''; foreach ($attributes as $name => $value) { $output .= $this->output_attribute($name, $value); @@ -812,7 +792,7 @@ class moodle_core_renderer extends moodle_renderer_base { $output .= ob_get_contents(); ob_end_clean(); $output .= $this->page->requires->get_head_code(); - + foreach ($this->page->alternateversions as $type => $alt) { $output .= $this->output_empty_tag('link', array('rel' => 'alternate', 'type' => $type, 'title' => $alt->title, 'href' => $alt->url)); @@ -1113,12 +1093,93 @@ class moodle_core_renderer extends moodle_renderer_base { return $output . $footer; } + /** + * Prints a nice side block with an optional header. + * + * The content is described + * by a {@link block_contents} object. + * + * @param block $content HTML for the content + * @return string the HTML to be output. + */ + function block($bc) { + $bc = clone($bc); + $bc->prepare(); + + $title = strip_tags($bc->title); + if (empty($title)) { + $output = ''; + $skipdest = ''; + } else { + $output = $this->output_tag('a', array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'), + get_string('skipa', 'access', $title)); + $skipdest = $this->output_tag('span', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to'), ''); + } + + $bc->attributes['id'] = $bc->id; + $bc->attributes['class'] = $bc->get_classes_string(); + $output .= $this->output_start_tag('div', $bc->attributes); + + if ($bc->heading) { + // Some callers pass in complete html for the heading, which may include + // complicated things such as the 'hide block' button; some just pass in + // text. If they only pass in plain text i.e. it doesn't include a + //
, then we add in standard tags that make it look like a normal + // page block including the h2 for accessibility + if (strpos($bc->heading, '
') === false) { + $bc->heading = $this->output_tag('div', array('class' => 'title'), + $this->output_tag('h2', null, $bc->heading)); + } + + $output .= $this->output_tag('div', array('class' => 'header'), $bc->heading); + } + + $output .= $this->output_start_tag('div', array('class' => 'content')); + + if ($bc->content) { + $output .= $bc->content; + + } else if ($bc->list) { + $row = 0; + $output .= $this->output_start_tag('ul', array('class' => 'list')); + $items = array(); + foreach ($bc->list as $key => $string) { + $item = $this->output_start_tag('li', array('class' => 'r' . $row)); + if ($bc->icons) { + $item .= $this->output_tag('div', array('class' => 'icon column c0'), $bc->icons[$key]); + } + $item .= $this->output_tag('div', array('class' => 'column c1'), $string); + $item .= $this->output_end_tag('li'); + $items[] = $item; + $row = 1 - $row; // Flip even/odd. + } + $output .= $this->output_tag('ul', array('class' => 'list'), implode("\n", $items)); + } + + if ($bc->footer) { + $output .= $this->output_tag('div', array('class' => 'footer'), $bc->footer); + } + + $output .= $this->output_end_tag('div'); + $output .= $this->output_end_tag('div'); + $output .= $skipdest; + + if (!empty($CFG->allowuserblockhiding) && isset($attributes['id'])) { + $strshow = addslashes_js(get_string('showblocka', 'access', $title)); + $strhide = addslashes_js(get_string('hideblocka', 'access', $title)); + $output .= $this->page->requires->js_function_call('elementCookieHide', array( + $bc->id, $strshow, $strhide))->asap(); + } + + return $output; + } + public function link_to_popup_window() { - + } public function button_to_popup_window() { - + } public function close_window_button($buttontext = null, $reloadopener = false) { @@ -1344,6 +1405,21 @@ class moodle_core_renderer extends moodle_renderer_base { public function container_end() { return $this->opencontainers->pop('container'); } + + /** + * At the moment we frequently have a problem with $CFG->pixpath not being + * initialised when it is needed. Unfortunately, there is no nice way to handle + * this. I think we need to replace $CFG->pixpath with something like $OUTPUT->icon(...). + * However, until then, we need a way to force $CFG->pixpath to be initialised, + * to fix the error messages, and that is what this function if for. + */ + public function initialise_deprecated_cfg_pixpath() { + // Actually, we don't have to do anything here. Just calling any method + // of $OBJECT is enough. However, if the only reason you are calling + // an $OUTPUT method is to get $CFG->pixpath initialised, please use this + // method, so we can find them and clean them up later once we have + // found a better replacement for $CFG->pixpath. + } } @@ -1376,7 +1452,7 @@ class moodle_html_component { if (is_array($classes)) { return $classes; } else { - return explode(' '. trim($classes)); + return explode(' ', trim($classes)); } } @@ -1532,6 +1608,63 @@ class moodle_select_menu extends moodle_html_component { } +/** + * This class hold all the information required to describe a Moodle block. + * + * That is, it holds all the different bits of HTML content that need to be put into the block. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +class block_contents extends moodle_html_component { + protected static $idcounter = 1; + /** + * @param string $heading HTML for the heading. Can include full HTML or just + * plain text - plain text will automatically be enclosed in the appropriate + * heading tags. + */ + public $heading = ''; + /** + * @param string $title Plain text title, as embedded in the $heading. + */ + public $title = ''; + /** + * @param string $content HTML for the content + */ + public $content = ''; + /** + * @param array $list an alternative to $content, it you want a list of things with optional icons. + */ + public $list = array(); + /** + * @param array $icons optional icons for the things in $list. + */ + public $icons = array(); + /** + * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer"> + */ + public $footer = ''; + /** + * @param array $attributes an array of attribute => value pairs that are put on the + * outer div of this block. {@link $id} and {@link $classes} attributes should be set separately. + */ + public $attributes = array(); + /** + * @param integer $skipid do not set this manually. It is set automatically be the {@link prepare()} method. + */ + public $skipid; + + /* @see lib/moodle_html_component#prepare() */ + public function prepare() { + $this->skipid = self::$idcounter; + self::$idcounter += 1; + $this->add_class('sideblock'); + parent::prepare(); + } +} + + /** * A renderer that generates output for commandlines scripts. * @@ -1582,81 +1715,3 @@ class cli_core_renderer extends moodle_core_renderer { } } - -/** - * A renderer for the custom corner theme, and other themes based on it. - * - * Generates the slightly different HTML that the custom corners theme wants. - * - * @copyright 2009 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class custom_corners_core_renderer extends moodle_core_renderer { - protected $wraplevel = 1; - - protected function custom_corners_divs($classes = '', $idbase = '') { - if (strpos($classes, 'clearfix') !== false) { - $clearfix = ' clearfix'; - $classes = trim(str_replace('clearfix', '', $classes)); - } else { - $clearfix = ''; - } - - // Analise if we want ids for the custom corner elements - $id = ''; - $idbt = ''; - $idi1 = ''; - $idi2 = ''; - $idi3 = ''; - $idbb = ''; - if ($idbase) { - $id = $idbase; - $idbt = $idbase . '-bt'; - $idi1 = $idbase . '-i1'; - $idi2 = $idbase . '-i2'; - $idi3 = $idbase . '-i3'; - $idbb = $idbase . '-bb'; - } - - // Create start tags. - $start = $this->output_start_tag('div', array('id' => $id, 'class' => "wrap wraplevel{$this->wraplevel} $classes")) . "\n"; - $start .= $this->output_tag('div', array('id' => $idbt, 'class' => 'bt'), '
 
') . "\n"; - $start .= $this->output_start_tag('div', array('id' => $idi1, 'class' => 'i1')); - $start .= $this->output_start_tag('div', array('id' => $idi2, 'class' => 'i2')); - $start .= $this->output_start_tag('div', array('id' => $idi3, 'class' => "i3$clearfix")); - - // Create end tags. - $end = $this->output_end_tag('div'); - $end .= $this->output_end_tag('div'); - $end .= $this->output_end_tag('div'); - $end .= $this->output_tag('div', array('id' => $idbb, 'class' => 'bb'), '
 
') . "\n"; - $end .= $this->output_end_tag('div'); - - return array($start, $end); - } - - public function box_start($classes = 'generalbox', $id = '') { - list($start, $end) = $this->custom_corners_divs('ccbox box ' . moodle_renderer_base::prepare_classes($classes), $id); - $this->opencontainers->push('box', $end); - $this->wraplevel += 1; - return $start; - } - - public function box_end() { - $this->wraplevel -= 1; - return parent::box_end(); - } - - public function container_start($classes = '', $id = '') { - list($start, $end) = $this->custom_corners_divs(moodle_renderer_base::prepare_classes($classes), $id); - $this->opencontainers->push('container', $end); - $this->wraplevel += 1; - return $start; - } - - public function container_end() { - $this->wraplevel -= 1; - return parent::container_end(); - } -} diff --git a/lib/weblib.php b/lib/weblib.php index 689a193a4b..38555dbc1e 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3201,7 +3201,14 @@ function theme_setup($theme = '', $params=NULL) { // Support legacy themes, by setting sensible defaults for some of the new // properties that were introduced in Moodle 2.0. if (empty($THEME->rendererfactory)) { - $THEME->rendererfactory = 'standard_renderer_factory'; + if (!empty($THEME->customcorners)) { + // $THEME->customcorners is deprecated but we provide support for it via the + // custom_corners_renderer_factory class in lib/deprecatedlib.php + debugging('$THEME->customcorners is deprecated. Please use the new $THEME->rendererfactory to control HTML generation.', DEBUG_DEVELOPER); + $THEME->rendererfactory = 'custom_corners_renderer_factory'; + } else { + $THEME->rendererfactory = 'standard_renderer_factory'; + } } if (empty($THEME->blockregions)) { $THEME->blockregions = array('side-pre', 'side-post'); @@ -5906,191 +5913,6 @@ function rebuildnolinktag($text) { return $text; } -/** - * Prints a nice side block with an optional header. The content can either - * be a block of HTML or a list of text with optional icons. - * - * @todo Finish documenting this function. Show example of various attributes, etc. - * - * @static int $block_id Increments for each call to the function - * @param string $heading HTML for the heading. Can include full HTML or just - * plain text - plain text will automatically be enclosed in the appropriate - * heading tags. - * @param string $content HTML for the content - * @param array $list an alternative to $content, it you want a list of things with optional icons. - * @param array $icons optional icons for the things in $list. - * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer"> - * @param array $attributes an array of attribute => value pairs that are put on the - * outer div of this block. If there is a class attribute ' sideblock' gets appended to it. If there isn't - * already a class, class='sideblock' is used. - * @param string $title Plain text title, as embedded in the $heading. - * @return void Echo's output - */ -function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') { - - //Accessibility: skip block link, with title-text (or $block_id) to differentiate links. - static $block_id = 0; - $block_id++; - $skip_text = get_string('skipa', 'access', strip_tags($title)); - $skip_link = ''.$skip_text.''; - $skip_dest = ''; - - $strip_title = strip_tags($title); - if (! empty($strip_title)) { - echo $skip_link; - } - //ELSE: a single link on a page "Skip block 4" is too confusing - ignore. - - print_side_block_start($heading, $attributes); - - // The content. - if ($content) { - echo $content; - } else { - if ($list) { - $row = 0; - //Accessibility: replaced unnecessary table with list, see themes/standard/styles_layout.css - echo "\n\n"; - } - } - - // Footer, if any. - if ($footer) { - echo ''; - } - - print_side_block_end($attributes, $title); - echo $skip_dest; -} - -/** - * Starts a nice side block with an optional header. - * - * @todo Finish documenting this function - * - * @global object - * @global object - * @param string $heading HTML for the heading. Can include full HTML or just - * plain text - plain text will automatically be enclosed in the appropriate - * heading tags. - * @param array $attributes HTML attributes to apply if possible - * @return void Echo's output - */ -function print_side_block_start($heading='', $attributes = array()) { - - global $CFG, $THEME; - - // If there are no special attributes, give a default CSS class - if (empty($attributes) || !is_array($attributes)) { - $attributes = array('class' => 'sideblock'); - - } else if(!isset($attributes['class'])) { - $attributes['class'] = 'sideblock'; - - } else if(!strpos($attributes['class'], 'sideblock')) { - $attributes['class'] .= ' sideblock'; - } - - // OK, the class is surely there and in addition to anything - // else, it's tagged as a sideblock - - /* - - // IE misery: if I do it this way, blocks which start hidden cannot be "unhidden" - - // If there is a cookie to hide this thing, start it hidden - if (!empty($attributes['id']) && isset($_COOKIE['hide:'.$attributes['id']])) { - $attributes['class'] = 'hidden '.$attributes['class']; - } - */ - - $attrtext = ''; - foreach ($attributes as $attr => $val) { - $attrtext .= ' '.$attr.'="'.$val.'"'; - } - - echo '
'; - - if (!empty($THEME->customcorners)) { - echo '
'."\n"; - } - if ($heading) { - // Some callers pass in complete html for the heading, which may include - // complicated things such as the 'hide block' button; some just pass in - // text. If they only pass in plain text i.e. it doesn't include a - //
, then we add in standard tags that make it look like a normal - // page block including the h2 for accessibility - if(strpos($heading,'
')===false) { - $heading='

'.$heading.'

'; - } - - echo '
'; - if (!empty($THEME->customcorners)) { - echo '
 
'; - echo '
'; - echo '
'; - } - echo $heading; - if (!empty($THEME->customcorners)) { - echo '
'; - } - echo '
'; - } else { - if (!empty($THEME->customcorners)) { - echo '
 
'; - } - } - - if (!empty($THEME->customcorners)) { - echo '
'; - echo '
'; - } - echo '
'; - -} - - -/** - * Print table ending tags for a side block box. - * - * @global object - * @global object - * @param array $attributes HTML attributes to apply if possible [id] - * @param string $title - * @return void Echo's output - */ -function print_side_block_end($attributes = array(), $title='') { - global $CFG, $THEME; - - echo '
'; - - if (!empty($THEME->customcorners)) { - echo '
 
'; - } - - echo '
'; - - $strshow = addslashes_js(get_string('showblocka', 'access', strip_tags($title))); - $strhide = addslashes_js(get_string('hideblocka', 'access', strip_tags($title))); - - // IE workaround: if I do it THIS way, it works! WTF? - if (!empty($CFG->allowuserblockhiding) && isset($attributes['id'])) { - echo ''; - } - -} - /** * @todo Remove this deprecated function when no longer used * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the . @@ -6812,7 +6634,6 @@ abstract class moodle_progress_trace { * Called when the processing is finished. */ public function finished() { - } } diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 2b67a56237..599de73913 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -473,15 +473,9 @@ if ($quiz_qbanktool) { $bankclass = 'collapsed'; $quizcontentsclass = 'quizwhenbankcollapsed'; } -print_side_block_start(get_string('questionbankcontents', 'quiz') . - ' [' . get_string('show'). - '] - [' . get_string('hide'). - '] - ', array('class' => 'questionbankwindow ' . $bankclass)); +// Nasty short-term hack, becuase I am getting rid of separate print_side_block_start/end functions. +ob_start(); echo ''; echo '
'; echo '
'; @@ -495,7 +489,17 @@ $questionbank->display('editq', echo '
'; echo '
'; echo ''; -print_side_block_end(); +$qbhtml = ob_get_contents(); +ob_end_clean(); + +print_side_block(get_string('questionbankcontents', 'quiz') . + ' [' . get_string('show'). + '] + [' . get_string('hide'). + '] + ', $qbhtml, null, null, '', array('class' => 'questionbankwindow ' . $bankclass)); echo '
'; if ($quiz->shufflequestions) { diff --git a/mod/resource/type/ims/javascript.php b/mod/resource/type/ims/javascript.php index e5666453de..dd31b6a270 100644 --- a/mod/resource/type/ims/javascript.php +++ b/mod/resource/type/ims/javascript.php @@ -11,6 +11,9 @@ /// Let's know if we are using a customcorners theme. It implies new calculations /// within the resizeiframe function. +// TODO this will no longer work. We have the more general mechanism using renderers/renderer_factories +// to determine what HTML is output. If this JavaScript is really still necessary, then we will have +// to find another way to handle this. if (!empty($THEME->customcorners)) { $customcorners = 'true'; } else { diff --git a/question/category_class.php b/question/category_class.php index cbedaafbfc..3d783b8b80 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -148,7 +148,7 @@ class question_category_object { * Gets necessary strings and sets relevant path information */ public function question_category_object($page, $pageurl, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts) { - global $CFG, $COURSE; + global $CFG, $COURSE, $OUTPUT; $this->tab = str_repeat(' ', $this->tabsize); @@ -173,6 +173,7 @@ class question_category_object { $this->str->cancel = get_string('cancel'); $this->str->editcategories = get_string('editcategories', 'quiz'); $this->str->page = get_string('page'); + $OUTPUT->initialise_deprecated_cfg_pixpath(); $this->pixpath = $CFG->pixpath; $this->pageurl = $pageurl; diff --git a/theme/custom_corners/README.html b/theme/custom_corners/README.html index 2785ca2556..4c9f063328 100644 --- a/theme/custom_corners/README.html +++ b/theme/custom_corners/README.html @@ -1,15 +1,15 @@

"Custom corners", the Moodle theme with graphics for transparent custom corners and borders.

- This theme contains graphics for customising corners and borders. It makes use of a technique described by + This theme contains graphics for customising corners and borders. It makes use of a technique described by Roger Johansson - see "customising_custom_corners_and_borders" - However, the custom corners theme doesn't use all the JavaScript mentioned by Roger Johansson. - Instead, divs are added when "$THEME->customcorners = true;" is set in config.php. + However, the custom corners theme doesn't use all the JavaScript mentioned by Roger Johansson. + Instead, divs are added when using the custom_corners_core_renderer (defined in renderers.php) instead of moodle_core renderer.

- Note: Custom corners is included in Moodle 1.9 as an experimental feature. + Note: Custom corners is included in Moodle 1.9 as an experimental feature.

diff --git a/theme/custom_corners/config.php b/theme/custom_corners/config.php index 28b893d4d9..52cddd9ba1 100644 --- a/theme/custom_corners/config.php +++ b/theme/custom_corners/config.php @@ -1,12 +1,12 @@ sheets = array('user_styles'); -/// This variable is an array containing the names of all the +/// This variable is an array containing the names of all the /// stylesheet files you want included in this theme, and in what order //////////////////////////////////////////////////////////////////////////////// @@ -14,67 +14,67 @@ $THEME->sheets = array('user_styles'); $THEME->standardsheets = array('styles_layout', 'styles_color'); /// This variable can be set to an array containing -/// filenames from the *STANDARD* theme. If the -/// array exists, it will be used to choose the +/// filenames from the *STANDARD* theme. If the +/// array exists, it will be used to choose the /// files to include in the standard style sheet. /// When false, then no files are used. /// When true or NON-EXISTENT, then ALL standard files are used. -/// This parameter can be used, for example, to prevent +/// This parameter can be used, for example, to prevent /// having to override too many classes. /// Note that the trailing .css should not be included /// eg $THEME->standardsheets = array('styles_layout','styles_fonts','styles_color'); //////////////////////////////////////////////////////////////////////////////// -$THEME->parent = ''; +$THEME->parent = ''; /// This variable can be set to the name of a parent theme /// which you want to have included before the current theme. -/// This can make it easy to make modifications to another +/// This can make it easy to make modifications to another /// theme without having to actually change the files -/// If this variable is empty or false then a parent theme +/// If this variable is empty or false then a parent theme /// is not used. //////////////////////////////////////////////////////////////////////////////// -$THEME->parentsheets = false; +$THEME->parentsheets = false; /// This variable can be set to an array containing -/// filenames from a chosen *PARENT* theme. If the -/// array exists, it will be used to choose the +/// filenames from a chosen *PARENT* theme. If the +/// array exists, it will be used to choose the /// files to include in the standard style sheet. /// When false, then no files are used. /// When true or NON-EXISTENT, then ALL standard files are used. -/// This parameter can be used, for example, to prevent +/// This parameter can be used, for example, to prevent /// having to override too many classes. /// Note that the trailing .css should not be included /// eg $THEME->parentsheets = array('styles_layout','styles_fonts','styles_color'); //////////////////////////////////////////////////////////////////////////////// -$THEME->modsheets = true; +$THEME->modsheets = true; -/// When this is enabled, then this theme will search for -/// files named "styles.php" inside all Activity modules and -/// include them. This allows modules to provide some basic +/// When this is enabled, then this theme will search for +/// files named "styles.php" inside all Activity modules and +/// include them. This allows modules to provide some basic /// layouts so they work out of the box. /// It is HIGHLY recommended to leave this enabled. -$THEME->blocksheets = true; +$THEME->blocksheets = true; -/// When this is enabled, then this theme will search for -/// files named "styles.php" inside all Block modules and -/// include them. This allows Blocks to provide some basic +/// When this is enabled, then this theme will search for +/// files named "styles.php" inside all Block modules and +/// include them. This allows Blocks to provide some basic /// layouts so they work out of the box. /// It is HIGHLY recommended to leave this enabled. $THEME->langsheets = false; -/// By setting this to true, then this theme will search for +/// By setting this to true, then this theme will search for /// a file named "styles.php" inside the current language -/// directory. This allows different languages to provide +/// directory. This allows different languages to provide /// different styles. @@ -84,7 +84,7 @@ $THEME->block_r_min_width = 180; $THEME->block_r_max_width = 210; /// These values define the min and max width of the left and right -/// sieblocks in the course pages. If not set or false the standard +/// sieblocks in the course pages. If not set or false the standard /// values are taken. @@ -98,37 +98,37 @@ $THEME->block_r_max_width = 210; $THEME->courseformatsheets = true; -/// When this is enabled, this theme will search for files -/// named "styles.php" inside all course formats and -/// include them. This allows course formats to provide +/// When this is enabled, this theme will search for files +/// named "styles.php" inside all course formats and +/// include them. This allows course formats to provide /// their own default styles. $THEME->metainclude = true; -/// When this is enabled (or not set!) then Moodle will try -/// to include a file meta.php from this theme into the +/// When this is enabled (or not set!) then Moodle will try +/// to include a file meta.php from this theme into the /// part of the page. $THEME->standardmetainclude = true; -/// When this is enabled (or not set!) then Moodle will try -/// to include a file meta.php from the standard theme into the +/// When this is enabled (or not set!) then Moodle will try +/// to include a file meta.php from the standard theme into the /// part of the page. $THEME->parentmetainclude = false; -/// When this is enabled (or not set!) then Moodle will try -/// to include a file meta.php from the parent theme into the +/// When this is enabled (or not set!) then Moodle will try +/// to include a file meta.php from the parent theme into the /// part of the page. $THEME->navmenuwidth = 50; -/// You can use this to control the cutoff point for strings +/// You can use this to control the cutoff point for strings /// in the navmenus (list of activities in popup menu etc) /// Default is 50 characters wide. @@ -137,38 +137,31 @@ $THEME->makenavmenulist = false; /// By setting this to true, then you will have access to a /// new variable in your header.html and footer.html called -/// $navmenulist ... this contains a simple XHTML menu of -/// all activities in the current course, mostly useful for +/// $navmenulist ... this contains a simple XHTML menu of +/// all activities in the current course, mostly useful for /// creating popup navigation menus and so on. // $THEME->layouttable = array('middle', 'left', 'right'); -$THEME->customcorners = true; - -/// By setting this to true, Moodle will generate extra divs in -/// all pages to enable graphical rich custom corners and borders. -/// Please have a look at the README with more details. - - // $CFG->CSSEdit = true; /// When this is enabled then Moodle will include all CSS files /// seperately instead of writing all CSS code into one single -/// CSS file per theme. The single CSS files can then be edited +/// CSS file per theme. The single CSS files can then be edited /// and saved with interactive CSS editors like CSSEdit. -$THEME->resource_mp3player_colors = +$THEME->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'; -/// With this you can control the colours of the "big" MP3 player +/// With this you can control the colours of the "big" MP3 player /// that is used for MP3 resources. -$THEME->filter_mediaplugin_colors = +$THEME->filter_mediaplugin_colors = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'. 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'. 'waitForPlay=yes'; @@ -178,15 +171,15 @@ $THEME->filter_mediaplugin_colors = $THEME->custompix = false; -/// If true, then this theme must have a "pix" -/// subdirectory that contains copies of all +/// If true, then this theme must have a "pix" +/// subdirectory that contains copies of all /// files from the moodle/pix directory, plus a -/// "pix/mod" directory containing all the icons +/// "pix/mod" directory containing all the icons /// for all the activity modules. //////////////////////////////////////////////////////////////////////////////// -$THEME->rendererfactory = 'custom_corners_renderer_factory'; +$THEME->rendererfactory = 'theme_overridden_renderer_factory'; /// This is an advanced features that lets you control the HTML that Moodle /// generates. You need to specify a class that implements the renderer_factory /// interface. As well as the default 'standard_renderer_factory', there is diff --git a/theme/custom_corners/renderers.php b/theme/custom_corners/renderers.php new file mode 100644 index 0000000000..9f666af3ae --- /dev/null +++ b/theme/custom_corners/renderers.php @@ -0,0 +1,195 @@ +. + + +/** + * Functions for generating the HTML that Moodle should output. + * + * Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML + * for an overview. + * + * @package moodlecore + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5) + */ + + +/** + * A renderer for the custom corner theme, and other themes based on it. + * + * Generates the slightly different HTML that the custom corners theme wants. + * + * @copyright 2009 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 2.0 + */ +class custom_corners_core_renderer extends moodle_core_renderer { + protected $wraplevel = 1; + + protected function custom_corners_divs($classes = '', $idbase = '') { + if (strpos($classes, 'clearfix') !== false) { + $clearfix = ' clearfix'; + $classes = trim(str_replace('clearfix', '', $classes)); + } else { + $clearfix = ''; + } + + // Analise if we want ids for the custom corner elements + $id = ''; + $idbt = ''; + $idi1 = ''; + $idi2 = ''; + $idi3 = ''; + $idbb = ''; + if ($idbase) { + $id = $idbase; + $idbt = $idbase . '-bt'; + $idi1 = $idbase . '-i1'; + $idi2 = $idbase . '-i2'; + $idi3 = $idbase . '-i3'; + $idbb = $idbase . '-bb'; + } + + // Create start tags. + $start = $this->output_start_tag('div', array('id' => $id, 'class' => "wrap wraplevel{$this->wraplevel} $classes")) . "\n"; + $start .= $this->output_tag('div', array('id' => $idbt, 'class' => 'bt'), '

 
') . "\n"; + $start .= $this->output_start_tag('div', array('id' => $idi1, 'class' => 'i1')); + $start .= $this->output_start_tag('div', array('id' => $idi2, 'class' => 'i2')); + $start .= $this->output_start_tag('div', array('id' => $idi3, 'class' => "i3$clearfix")); + + // Create end tags. + $end = $this->output_end_tag('div'); + $end .= $this->output_end_tag('div'); + $end .= $this->output_end_tag('div'); + $end .= $this->output_tag('div', array('id' => $idbb, 'class' => 'bb'), '
 
') . "\n"; + $end .= $this->output_end_tag('div'); + + return array($start, $end); + } + + public function box_start($classes = 'generalbox', $id = '') { + list($start, $end) = $this->custom_corners_divs('ccbox box ' . moodle_renderer_base::prepare_classes($classes), $id); + $this->opencontainers->push('box', $end); + $this->wraplevel += 1; + return $start; + } + + public function box_end() { + $this->wraplevel -= 1; + return parent::box_end(); + } + + public function container_start($classes = '', $id = '') { + list($start, $end) = $this->custom_corners_divs(moodle_renderer_base::prepare_classes($classes), $id); + $this->opencontainers->push('container', $end); + $this->wraplevel += 1; + return $start; + } + + public function container_end() { + $this->wraplevel -= 1; + return parent::container_end(); + } + + /** + * Prints a nice side block with an optional header. + * + * The content is described + * by a {@link block_contents} object. + * + * @param block $content HTML for the content + * @return string the HTML to be output. + */ + function block($bc) { + $bc = clone($bc); + $bc->prepare(); + + $title = strip_tags($bc->title); + if (empty($title)) { + $output = ''; + $skipdest = ''; + } else { + $output = $this->output_tag('a', array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'), + get_string('skipa', 'access', $title)); + $skipdest = $this->output_tag('span', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to'), ''); + } + + $bc->attributes['id'] = $bc->id; + $bc->attributes['class'] = $bc->get_classes_string(); + $output .= $this->output_start_tag('div', $bc->attributes); + $output .= $this->output_start_tag('div', array('class' => 'wrap')); + + if ($bc->heading) { + // Some callers pass in complete html for the heading, which may include + // complicated things such as the 'hide block' button; some just pass in + // text. If they only pass in plain text i.e. it doesn't include a + //
, then we add in standard tags that make it look like a normal + // page block including the h2 for accessibility + if (strpos($bc->heading, '
') === false) { + $bc->heading = $this->output_tag('div', array('class' => 'title'), + $this->output_tag('h2', null, $bc->heading)); + } + + $output .= '
 
'; + $output .= '
'; + $output .= $bc->heading; + $output .= '
'; + } else { + $output .= '
 
'; + } + + $output .= '
'; + + if ($bc->content) { + $output .= $bc->content; + + } else if ($bc->list) { + $row = 0; + $output .= $this->output_start_tag('ul', array('class' => 'list')); + $items = array(); + foreach ($bc->list as $key => $string) { + $item = $this->output_start_tag('li', array('class' => 'r' . $row)); + if ($bc->icons) { + $item .= $this->output_tag('div', array('class' => 'icon column c0'), $bc->icons[$key]); + } + $item .= $this->output_tag('div', array('class' => 'column c1'), $string); + $item .= $this->output_end_tag('li'); + $items[] = $item; + $row = 1 - $row; // Flip even/odd. + } + $output .= $this->output_tag('ul', array('class' => 'list'), implode("\n", $items)); + } + + if ($bc->footer) { + $output .= $this->output_tag('div', array('class' => 'footer'), $bc->footer); + } + + $output .= '
 
'; + $output .= $skipdest; + + if (!empty($CFG->allowuserblockhiding) && isset($attributes['id'])) { + $strshow = addslashes_js(get_string('showblocka', 'access', $title)); + $strhide = addslashes_js(get_string('hideblocka', 'access', $title)); + $output .= $this->page->requires->js_function_call('elementCookieHide', array( + $bc->id, $strshow, $strhide))->asap(); + } + + return $output; + } + + +} -- 2.39.5