From 8ec50604b1b69058848ef3ef714b3b42a3497e5b Mon Sep 17 00:00:00 2001 From: dongsheng Date: Tue, 1 Apr 2008 04:15:13 +0000 Subject: [PATCH] Move error() to deprecatelib.php, merged from MOODLE_19_STABLE --- lib/deprecatedlib.php | 60 +++++++++++++++++++++++++++++++++++ lib/weblib.php | 73 ------------------------------------------- 2 files changed, 60 insertions(+), 73 deletions(-) diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 1c87f75d17..5fa923876b 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -1616,4 +1616,64 @@ function document_file($file, $include=true) { return false; } +/** + * Print an error page displaying an error message. + * Old method, don't call directly in new code - use print_error instead. + * + * + * @uses $SESSION + * @uses $CFG + * @param string $message The message to display to the user about the error. + * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page. + */ +function error ($message, $link='') { + + global $CFG, $SESSION, $THEME; + $message = clean_text($message); // In case nasties are in here + + if (defined('FULLME') && FULLME == 'cron') { + // Errors in cron should be mtrace'd. + mtrace($message); + die; + } + + if (! defined('HEADER_PRINTED')) { + //header not yet printed + @header('HTTP/1.0 404 Not Found'); + print_header(get_string('error')); + } else { + print_container_end_all(false, $THEME->open_header_containers); + } + + echo '
'; + print_simple_box($message, '', '', '', '', 'errorbox'); + + debugging('Stack trace:', DEBUG_DEVELOPER); + + // in case we are logging upgrade in admin/index.php stop it + if (function_exists('upgrade_log_finish')) { + upgrade_log_finish(); + } + + if (empty($link) and !defined('ADMIN_EXT_HEADER_PRINTED')) { + if ( !empty($SESSION->fromurl) ) { + $link = $SESSION->fromurl; + unset($SESSION->fromurl); + } else { + $link = $CFG->wwwroot .'/'; + } + } + + if (!empty($link)) { + print_continue($link); + } + + print_footer(); + + for ($i=0;$i<512;$i++) { // Padding to help IE work with 404 + echo ' '; + } + + die; +} ?> diff --git a/lib/weblib.php b/lib/weblib.php index 9191b29a29..d5f8aa57ae 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -5657,79 +5657,6 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) { } } -/** - * Print an error page displaying an error message. - * Old method, don't call directly in new code - use print_error instead. - * - * - * @uses $SESSION - * @uses $CFG - * @param string $message The message to display to the user about the error. - * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page. - */ -function error ($message, $link='') { - - global $CFG, $SESSION, $THEME; - $message = clean_text($message); // In case nasties are in here - - if (defined('CLI_UPGRADE') && CLI_UPGRADE) { - console_write(STDERR,$message,'',false); - die ; - } - - if (defined('FULLME') && FULLME == 'cron') { - // Errors in cron should be mtrace'd. - mtrace($message); - die; - } - - if (defined('UNITTEST')) { - // Errors in unit test become exceptions, so you can unit test - // code that might call error(). - throw new Exception('error() call: '. - $message.($link!=='' ? ' ['.$link.']' : '')); - } - - if (! defined('HEADER_PRINTED')) { - //header not yet printed - @header('HTTP/1.0 404 Not Found'); - print_header(get_string('error')); - } else { - print_container_end_all(false, $THEME->open_header_containers); - } - - echo '
'; - print_simple_box($message, '', '', '', '', 'errorbox'); - - debugging('Stack trace:', DEBUG_DEVELOPER); - - // in case we are logging upgrade in admin/index.php stop it - if (function_exists('upgrade_log_finish')) { - upgrade_log_finish(); - } - - if (empty($link) and !defined('ADMIN_EXT_HEADER_PRINTED')) { - if ( !empty($SESSION->fromurl) ) { - $link = $SESSION->fromurl; - unset($SESSION->fromurl); - } else { - $link = $CFG->wwwroot .'/'; - } - } - - if (!empty($link)) { - print_continue($link); - } - - print_footer(); - - for ($i=0;$i<512;$i++) { // Padding to help IE work with 404 - echo ' '; - } - - die; -} - /** * Print an error page displaying an error message. New method - use this for new code. * -- 2.39.5