X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=messages.php;h=cf979d74975f1bc0d6c838e569f3ac2f051c040e;hb=96eb63cbbc2873d0f64979422a323e174a7d5f12;hp=9db80a136431c9c378fed518fce37509788a1244;hpb=856f805c6cbb6e712c662214f3b5821442f808a0;p=wfpl.git diff --git a/messages.php b/messages.php index 9db80a1..cf979d7 100644 --- a/messages.php +++ b/messages.php @@ -16,39 +16,40 @@ # along with this program. If not, see . - -# This file is useful for putting message boxe(s) on the screen. +# This file is useful for putting message box(es) on the screen. If you include +# session_messages.php these messages can even persist accross http redirects +# (such as you should do after receiving a POST. # # Just call message("message here") whenever you have something to report. # -# Once a template is loaded, call display_messages(). Your template should have -# a section with ~message_text.html~ tag in it. # -# If you want a divider (any text between message boxes when there are multiple -# boxes) provide a sub-template section named "message_divider" INSIDE -# "message_box" at the begining of it. +# Once a template is loaded, call display_messages(). run.php will do that +# automatically after your main function returns, so long as you require_once +# this file. +# +# Just make sure your template has a section with a +# ~value html~ tag in it. # -# If you'd like something around the group of all message boxes, you can put -# the whole thing in a sub-template section called "message_container" - # Simple example: # -# -#

~message_text.html~

-# - +# +#

~value html~

+# +# # Full-featured example: # -# -#
-# -# -#
-# -#

~message_text.html~

-# -#
-# +# +# +#
+# +#

~data html~

+# +#
+# +# +#
+# +# require_once('code/wfpl/template.php'); @@ -60,34 +61,26 @@ function message($msg) { $GLOBALS['wfpl_messages'][] = $msg; } -# if you want the messages in a template other than the default one, pass it like so: -# -# display_messages(ref($my_template)); -function display_messages($template = 0) { - $first = true; - if($template === 0) { - $template = &$GLOBALS['wfpl_template']; +function get_messages() { + if(!isset($GLOBALS['wfpl_messages'])) { + $messages = array(); } else { - $template = &$template->ref; + $messages = $GLOBALS['wfpl_messages']; + unset($GLOBALS['wfpl_messages']); } if(function_exists('session_restore_messages')) { - session_restore_messages(); + $messages = array_merge(session_restore_messages(), $messages); } - if($GLOBALS['wfpl_messages']) { - foreach($GLOBALS['wfpl_messages'] as $msg) { - if($first) { - $first = false; - } else { - $template->sub('message_divider'); - } - $template->set('message_text', $msg); - $template->sub('message_box'); - } - $template->sub('message_container'); - unset($GLOBALS['wfpl_messages']); - } + return $messages; } -?> +# for old-style templates +function display_messages(&$tem = NULL, $key = 'wfpl_messages') { + if($tem) { + $tem->data[$key] = columnize(get_messages()); + } else { + $GLOBALS['wfpl_template']->data[$key] = columnize(get_messages()); + } +}