X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=messages.php;h=a762e5ed7429270e393d63e4b752b08f0f16ac4d;hp=0dc21e212fc5aa289354be044fe371efc601b467;hb=6be2bf0ba344177f0d1e57d9135bcb97579c54a3;hpb=19290886b2b738f1cc43f2d7bdea74bf05603b17 diff --git a/messages.php b/messages.php index 0dc21e2..a762e5e 100644 --- a/messages.php +++ b/messages.php @@ -1,19 +1,9 @@ . +# This program is in the public domain within the United States. Additionally, +# we waive copyright and related rights in the work worldwide through the CC0 +# 1.0 Universal public domain dedication, which can be found at +# http://creativecommons.org/publicdomain/zero/1.0/ # This file is useful for putting message box(es) on the screen. If you include @@ -23,36 +13,37 @@ # Just call message("message here") whenever you have something to report. # # -# 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. +# Once a template is loaded, call display_messages(). run.php will call +# display_messages() for you automaticallly after your main function returns +# (so long as you require_once this file.) If you want these messages to +# persist accross browser redirects, then you should +# require_once(__DIR__.'/'.'lib/wfpl/session_messages.php') # -# Just make sure your template has a section with a -# ~value html~ tag in it. +# Just make sure your template has a section with a +# ~message html~ tag in it. # # Simple example: # -# -#

~value html~

+# +#

~message html~

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

~data html~

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

~message html~

+# +#
+# +# +#
# -require_once('code/wfpl/template.php'); +require_once(__DIR__.'/'.'template.php'); +# call this to display a message function message($msg) { if(!isset($GLOBALS['wfpl_messages'])) { $GLOBALS['wfpl_messages'] = array(); @@ -61,6 +52,7 @@ function message($msg) { $GLOBALS['wfpl_messages'][] = $msg; } +# destructive function get_messages() { if(!isset($GLOBALS['wfpl_messages'])) { $messages = array(); @@ -76,11 +68,10 @@ function get_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()); +# called automatically by run.php +function display_messages(&$tem = NULL, $key = '$messages') { + if(!$tem) { + $tem = &$GLOBALS['wfpl_template']; } + $tem->data[$key] = columnize(get_messages(), 'message'); }