From: skodak Date: Fri, 14 Dec 2007 21:22:38 +0000 (+0000) Subject: MDL-12221 reworked container autoclosing - error() and notice() do not work everywher... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d795bfdbf9c54f9637d652d62dd5a4640d46dca9;p=moodle.git MDL-12221 reworked container autoclosing - error() and notice() do not work everywhere though; notice print header if needed now; new print_footer('empty') for empty footer - removes some hacky - merged from MOODLE_19_STABLE --- diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 2e4b88630a..a1e797ec09 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -1079,6 +1079,7 @@ $string['notenrolledprofile'] = 'This profile is not available because this user $string['noteuserschangednonetocourse'] = 'Note: course users need to be restored when restoring user data (in activities, files or messages). This setting has been changed for you.'; $string['nothingnew'] = 'Nothing new since your last login'; $string['nothingtodisplay'] = 'Nothing to display'; +$string['notice'] = 'Notice'; $string['noticenewerbackup'] = 'This backup file has been created with Moodle $a->backuprelease ($a->backupversion) and it\'s newer than your currently installed Moodle $a->serverrelease ($a->serverversion). This could cause some inconsistencies because backwards compatibility of backup files cannot be guaranteed.'; $string['notifications'] = 'Notifications'; $string['notifyloginfailuresmessage'] = '$a->time, IP: $a->ip, User: $a->info'; diff --git a/lib/adminlib.php b/lib/adminlib.php index ffa9b146da..1406e9a4ea 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3115,26 +3115,27 @@ function admin_externalpage_print_header() { foreach ($lt1 as $column) { switch ($column) { case 'left': - echo ''; - print_container_start(); - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); - print_container_end(); - echo ''; + echo ''; + print_container_start(); + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); + print_container_end(); + echo ''; break; case 'middle': - echo ''; - print_container_start(true); + echo ''; + print_container_start(true); + $THEME->open_header_containers++; // this is hacky workaround for the error()/notice() autoclosing problems on admin pages break; case 'right': - if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) { - echo ''; - print_container_start(); - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); - print_container_end(); - echo ''; - } + if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) { + echo ''; + print_container_start(); + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); + print_container_end(); + echo ''; + } break; } } @@ -3169,27 +3170,27 @@ function admin_externalpage_print_footer() { foreach ($lt as $column) { switch ($column) { case 'left': - echo ''; - print_container_start(); - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); - print_container_end(); - echo ''; + echo ''; + print_container_start(); + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); + print_container_end(); + echo ''; break; case 'middle': - print_container_end(); - echo ''; + print_container_end(); + $THEME->open_header_containers--; // this is hacky workaround for the error()/notice() autoclosing problems on admin pages + echo ''; break; case 'right': - if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) { - echo ''; - print_container_start(); - blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); - - print_container_end(); - echo ''; - } + if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) { + echo ''; + print_container_start(); + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); + print_container_end(); + echo ''; + } break; } } diff --git a/lib/weblib.php b/lib/weblib.php index 767a9853a5..9d38699539 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -80,6 +80,13 @@ define('FORMAT_MARKDOWN', '4'); // Markdown-formatted text http://daringfireba define('TRUSTTEXT', '#####TRUSTTEXT#####'); +/** + * Javascript related defines + */ +define('REQUIREJS_BEFOREHEADER', 0); +define('REQUIREJS_INHEADER', 1); +define('REQUIREJS_AFTERHEADER', 2); + /** * Allowed tags - string of html tags that can be tested against for safe html tags * @global string $ALLOWED_TAGS @@ -2526,6 +2533,9 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $output = ob_get_contents(); ob_end_clean(); + // container debugging info + $THEME->open_header_containers = open_containers(); + // Skip to main content, see skip_main_destination(). if ($pageid=='course-view' or $pageid=='site-index' or $pageid=='course-index') { $skiplink = ''; @@ -2551,10 +2561,6 @@ function print_header ($title='', $heading='', $navigation='', $focus='', } } -define('REQUIREJS_BEFOREHEADER',0); -define('REQUIREJS_INHEADER',1); -define('REQUIREJS_AFTERHEADER',2); - /** * Used to include JavaScript libraries. * @@ -2758,12 +2764,14 @@ function print_header_simple($title='', $heading='', $navigation='', $focus='', /** * Can provide a course object to make the footer contain a link to * to the course home page, otherwise the link will go to the site home - * - * @uses $CFG * @uses $USER - * @param course $course {@link $COURSE} object containing course information - * @param ? $usercourse ? - * @todo Finish documenting this function + * @param mixed $course course object, used for course link button or + * 'none' means no user link, only docs link + * 'empty' means nothing printed in footer + * 'home' special frontpage footer + * @param object $usercourse course used in user link + * @param boolean $return output as string + * @return mixed string or void */ function print_footer($course=NULL, $usercourse=NULL, $return=false) { global $USER, $CFG, $THEME, $COURSE; @@ -2773,23 +2781,45 @@ function print_footer($course=NULL, $usercourse=NULL, $return=false) { return; } -/// Course links +/// Course links or special footer if ($course) { - if (is_string($course) && $course == 'none') { // Don't print any links etc + if ($course === 'empty') { + // special hack - sometimes we do not want even the docs link in footer + $output = ''; + if (!empty($THEME->open_header_containers)) { + for ($i=0; $i<$THEME->open_header_containers; $i++) { + $output .= print_container_end_all(); // containers opened from header + } + } else { + //1.8 theme compatibility + $output .= "\n"; // content div + } + $output .= "\n\n\n"; // close page div started in header + if ($return) { + return $output; + } else { + echo $output; + return; + } + + } else if ($course === 'none') { // Don't print any links etc $homelink = ''; $loggedinas = ''; $home = false; - } else if (is_string($course) && $course == 'home') { // special case for site home page - please do not remove + + } else if ($course === 'home') { // special case for site home page - please do not remove $course = get_site(); $homelink = ''; $home = true; + } else { $homelink = ''; $home = false; } + } else { $course = get_site(); // Set course as site course by default $homelink = ''; @@ -2818,9 +2848,9 @@ function print_footer($course=NULL, $usercourse=NULL, $return=false) { $menu = ''; } -/// there should be exactly one open container 'content' - if (open_containers() != 1) { - debugging('Unexpected number of open containers: '.open_containers().', expecting 1.', DEBUG_DEVELOPER); +/// there should be exactly the same number of open containers as after the header + if ($THEME->open_header_containers != open_containers()) { + debugging('Unexpected number of open containers: '.open_containers().', expecting '.$THEME->open_header_containers, DEBUG_DEVELOPER); } /// Provide some performance info if required @@ -3818,8 +3848,9 @@ function print_continue($link, $return=false) { * * @param string $message, the content of the box * @param string $classes, space-separated class names. - * @param string $ids, space-separated id names. + * @param string $idbase * @param boolean $return, return as string or just print it + * @return mixed string or void */ function print_box($message, $classes='generalbox', $ids='', $return=false) { @@ -3839,8 +3870,9 @@ function print_box($message, $classes='generalbox', $ids='', $return=false) { * Replaces print_simple_box_start (see deprecatedlib.php) * * @param string $classes, space-separated class names. - * @param string $ids, space-separated id names. + * @param string $idbase * @param boolean $return, return as string or just print it + * @return mixed string or void */ function print_box_start($classes='generalbox', $ids='', $return=false) { global $THEME; @@ -3868,9 +3900,11 @@ function print_box_end($return=false) { * Print a message in a standard themed container. * * @param string $message, the content of the container + * @param boolean $clearfix clear both sides * @param string $classes, space-separated class names. - * @param string $ids, space-separated id names. + * @param string $idbase * @param boolean $return, return as string or just print it + * @return string or void */ function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) { @@ -3888,9 +3922,11 @@ function print_container($message, $clearfix=false, $classes='', $idbase='', $re /** * Starts a container using divs * + * @param boolean $clearfix clear both sides * @param string $classes, space-separated class names. - * @param string $ids, space-separated id names. + * @param string $idbase * @param boolean $return, return as string or just print it + * @return mixed string or void */ function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) { global $THEME; @@ -3932,12 +3968,13 @@ function print_container_start($clearfix=false, $classes='', $idbase='', $return /** * Simple function to end a container (see above) * @param boolean $return, return as string or just print it + * @return mixed string or void */ function print_container_end($return=false) { global $THEME; if (empty($THEME->open_containers)) { - debugging('Incorrect closing of custom corners - no more open containers.', DEBUG_DEVELOPER); + debugging('Incorrect request to end container - no more open containers.', DEBUG_DEVELOPER); $idbase = ''; } else { $idbase = array_pop($THEME->open_containers); @@ -3971,17 +4008,15 @@ function open_containers() { } /** - * Force closing of all open containers except the main content one. + * Force closing of open containers * @param boolean $return, return as string or just print it + * @param int $keep number of containers to be kept open - usually theme or page containers + * @return mixed string or void */ -function print_container_end_all($return=false) { - global $THEME; - +function print_container_end_all($return=false, $keep=0) { $output = ''; - if (!empty($THEME->open_containers)) { - while(count($THEME->open_containers) > 1) { // the last one is the 'content' container - $output .= print_container_end($return); - } + while (open_containers() > $keep) { + $output .= print_container_end($return); } if ($return) { @@ -3996,7 +4031,9 @@ function print_container_end_all($return=false) { * Starting part of the surrounding divs for custom corners * * @param boolean $clearfix, add CLASS "clearfix" to the inner div against collapsing - * @param mixed $idbase, optionally, define one idbase to be added to all the elements in the corners + * @param string $classes + * @param mixed $idbase, optionally, define one idbase to be added to all the elements in the corners + * @return string */ function _print_custom_corners_start($clearfix=false, $classes='', $idbase='') { /// Analise if we want ids for the custom corner elements @@ -4031,6 +4068,8 @@ function _print_custom_corners_start($clearfix=false, $classes='', $idbase='') { /** * Internal function - do not use directly! * Ending part of the surrounding divs for custom corners + * @param string $idbase + * @return string */ function _print_custom_corners_end($idbase) { /// Analise if we want ids for the custom corner elements @@ -5639,7 +5678,7 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) { */ function error ($message, $link='') { - global $CFG, $SESSION; + global $CFG, $SESSION, $THEME; $message = clean_text($message); // In case nasties are in here if (defined('FULLME') && FULLME == 'cron') { @@ -5653,7 +5692,7 @@ function error ($message, $link='') { @header('HTTP/1.0 404 Not Found'); print_header(get_string('error')); } else { - print_container_end_all(); + print_container_end_all(false, $THEME->open_header_containers); } echo '
'; @@ -5909,17 +5948,28 @@ function editorshortcutshelpbutton() { * @todo Finish documenting this function */ function notice ($message, $link='', $course=NULL) { - global $CFG, $SITE; + global $CFG, $SITE, $THEME, $COURSE; - print_container_end_all(); + $message = clean_text($message); // In case nasties are in here - $message = clean_text($message); + if (defined('FULLME') && FULLME == 'cron') { + // notices in cron should be mtrace'd. + mtrace($message); + die; + } + + if (! defined('HEADER_PRINTED')) { + //header not yet printed + print_header(get_string('notice')); + } else { + print_container_end_all(false, $THEME->open_header_containers); + } print_box($message, 'generalbox', 'notice'); print_continue($link); if (empty($course)) { - print_footer($SITE); + print_footer($COURSE); } else { print_footer($course); } @@ -5978,7 +6028,7 @@ if (!function_exists('error_get_last')) { */ function redirect($url, $message='', $delay=-1) { - global $CFG; + global $CFG, $THEME; if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { $url = sid_process_url($url); @@ -6052,7 +6102,7 @@ function redirect($url, $message='', $delay=-1) { print_header('', '', '', '', $errorprinted ? '' : ('')); $delay += 3; // double redirect prevention, it was sometimes breaking upgrades before 1.7 } else { - print_container_end_all(); + print_container_end_all(false, $THEME->open_header_containers); } echo '
'; echo '
'. $message .'
'; diff --git a/message/user.php b/message/user.php index 6c54652e4c..5d5565886f 100644 --- a/message/user.php +++ b/message/user.php @@ -87,8 +87,6 @@ echo ''; - // this is hack! - print_container_end(); // container "content" started in header - echo '
'; // close page div started in header + print_footer('empty'); ?> diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php index c389234b41..f01cdd1a72 100644 --- a/mod/chat/gui_header_js/chatinput.php +++ b/mod/chat/gui_header_js/chatinput.php @@ -59,7 +59,6 @@ - - - - + diff --git a/mod/chat/gui_header_js/users.php b/mod/chat/gui_header_js/users.php index 8ceca1a30b..ea1ef674a7 100644 --- a/mod/chat/gui_header_js/users.php +++ b/mod/chat/gui_header_js/users.php @@ -135,7 +135,8 @@ echo ''; } // added 2 s, xhtml strict complaints - echo ''; + echo ''; + print_footer('empty'); // // Support HTTP Keep-Alive by printing Content-Length diff --git a/mod/chat/gui_sockets/chatinput.php b/mod/chat/gui_sockets/chatinput.php index c33e2ccb86..51697bcfe4 100644 --- a/mod/chat/gui_sockets/chatinput.php +++ b/mod/chat/gui_sockets/chatinput.php @@ -71,6 +71,6 @@ function reloadusers() { - - - + \ No newline at end of file diff --git a/mod/glossary/print.php b/mod/glossary/print.php index f9f5bde614..779cafc7a4 100644 --- a/mod/glossary/print.php +++ b/mod/glossary/print.php @@ -181,5 +181,5 @@ } } - echo ''; + print_footer('empty'); ?> diff --git a/mod/resource/type/file/localfile.php b/mod/resource/type/file/localfile.php index 576e7db020..bf5232d7e8 100644 --- a/mod/resource/type/file/localfile.php +++ b/mod/resource/type/file/localfile.php @@ -45,5 +45,6 @@ - - + \ No newline at end of file diff --git a/mod/resource/type/file/localpath.php b/mod/resource/type/file/localpath.php index c5a2e6f008..ef691baa9d 100644 --- a/mod/resource/type/file/localpath.php +++ b/mod/resource/type/file/localpath.php @@ -52,6 +52,6 @@ - - - + \ No newline at end of file diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index b16c6d9961..fa461245fd 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -414,7 +414,7 @@ class resource_file extends resource_base { get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource')); echo ''; } - echo ''; + print_footer('empty'); exit; } diff --git a/mod/resource/type/ims/resource.class.php b/mod/resource/type/ims/resource.class.php index 664b5d591c..ae5dc09d9b 100644 --- a/mod/resource/type/ims/resource.class.php +++ b/mod/resource/type/ims/resource.class.php @@ -479,12 +479,8 @@ class resource_ims extends resource_base { } /// content - this produces everything else $this->print_ims($cm, $course, $items, $resource, $page); - /// Now, let's print the footer. It's harcoded here to save some space - /// because it's impossible to use print_footer() to print NOTHING - /// Added programatic support to customcorners themes. - // this is hack! - print_container_end(); // container "content" started in header - echo ''; // close page div started in header + + print_footer('empty'); /// log it. add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);