diff options
author | Michael Hamann <michael@content-space.de> | 2011-01-10 21:54:58 +0100 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2011-01-10 22:23:23 +0100 |
commit | cc58224cff540373081dcde9c64d00efbf0fbddc (patch) | |
tree | 0156a541c21223af83e0a4b51d2656d7f563675c | |
parent | bf0c93c21103a02f9efe4c427b9fefd6c5732666 (diff) | |
download | rpg-cc58224cff540373081dcde9c64d00efbf0fbddc.tar.gz rpg-cc58224cff540373081dcde9c64d00efbf0fbddc.tar.bz2 |
Fix msg() calls when messages have already been printed
This commit fixes two bugs that occurred when msg() was called after
html_msgarea() had already been called.
- the $MSG array is now cleared when it has been printed (otherwise $MSG
has been printed again when another msg() call was done)
- headers_sent() didn't work for me, it always reported false although
html_msgarea() had already been called which might be explainable with
output buffering. This makes msg() now depend on the first call of
html_msgarea() or headers_sent() in order to not to break msg() in
ajax requests etc.
-rw-r--r-- | inc/html.php | 7 | ||||
-rw-r--r-- | inc/infoutils.php | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/inc/html.php b/inc/html.php index 4e3744fd1..b6c5cc7ba 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1034,7 +1034,10 @@ function html_conflict($text,$summary){ * @author Andreas Gohr <andi@splitbrain.org> */ function html_msgarea(){ - global $MSG; + global $MSG, $MSG_shown; + // store if the global $MSG has already been shown and thus HTML output has been started + $MSG_shown = true; + if(!isset($MSG)) return; $shown = array(); @@ -1046,6 +1049,8 @@ function html_msgarea(){ print '</div>'; $shown[$hash] = 1; } + + unset($GLOBALS['MSG']); } /** diff --git a/inc/infoutils.php b/inc/infoutils.php index d3c6f2918..5f406aa3e 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -258,7 +258,7 @@ function check(){ * @see html_msgarea */ function msg($message,$lvl=0,$line='',$file=''){ - global $MSG; + global $MSG, $MSG_shown; $errors[-1] = 'error'; $errors[0] = 'info'; $errors[1] = 'success'; @@ -268,7 +268,7 @@ function msg($message,$lvl=0,$line='',$file=''){ if(!isset($MSG)) $MSG = array(); $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message); - if(headers_sent()){ + if(isset($MSG_shown) || headers_sent()){ if(function_exists('html_msgarea')){ html_msgarea(); }else{ |