X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=messages.php;h=cf979d74975f1bc0d6c838e569f3ac2f051c040e;hb=4d41dacb3ebdf58ee0fd52b5f8db75310e3bec97;hp=2d065e32e16bca925ad8c33916b52d14548c5539;hpb=a0e5ba78fcf29b7dd798e4f691068634e5355806;p=wfpl.git
diff --git a/messages.php b/messages.php
index 2d065e3..cf979d7 100644
--- a/messages.php
+++ b/messages.php
@@ -16,56 +16,71 @@
# along with this program. If not, see .
-# This file is useful for putting message box(es) 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 a ~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 "separator"
-# INSIDE "message" 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 "messages"
-
# Simple example:
#
-#
-#
~text:html~
-#
-
+#
+# ~value html~
+#
+#
# Full-featured example:
#
-#
-#
-#
-#
-#
-#
-#
~text:html~
-#
-#
-#
+#
+#
+#
+#
+#
~data html~
+#
+#
+#
+#
+#
+#
+#
require_once('code/wfpl/template.php');
function message($msg) {
if(!isset($GLOBALS['wfpl_messages'])) {
- if(function_exists('session_restore_messages')) {
- $GLOBALS['wfpl_messages'] = session_restore_messages();
- } else $GLOBALS['wfpl_messages'] = array();
+ $GLOBALS['wfpl_messages'] = array();
}
$GLOBALS['wfpl_messages'][] = $msg;
}
-function display_messages(&$tem = NULL) {
- if(!$GLOBALS['wfpl_messages']) return;
- foreach($GLOBALS['wfpl_messages'] as $msg) {
- $sub = array('text' => $msg);
- $GLOBALS['wfpl_tem_data']['message'][] = $sub;
- $GLOBALS['wfpl_tem_data']['messages'] = TRUE;
+function get_messages() {
+ if(!isset($GLOBALS['wfpl_messages'])) {
+ $messages = array();
+ } else {
+ $messages = $GLOBALS['wfpl_messages'];
+ unset($GLOBALS['wfpl_messages']);
+ }
+
+ if(function_exists('session_restore_messages')) {
+ $messages = array_merge(session_restore_messages(), $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());
}
}