X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=messages.php;h=98ada56c16029afc69cbb2ebfee198c2ab4192fc;hb=ca169135c8b3ec936846befa20f583849b8c1108;hp=71d19bece58a3c30ee22ae37a3a20be0eb0044c2;hpb=ba50d9a564ca3b8637212c634b5a61a38e6feb9f;p=wfpl.git
diff --git a/messages.php b/messages.php
index 71d19be..98ada56 100644
--- a/messages.php
+++ b/messages.php
@@ -16,57 +16,72 @@
# 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 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("code/wfpl/session_messages.php")
+#
+# Just make sure your template has a section with a
+# ~message 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~
-#
-
+#
+# ~message html~
+#
+#
# Full-featured example:
#
-#
-#
-#
-#
-#
-#
-#
~text: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'])) {
- 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(!$tem) $tem = &$GLOBALS['wfpl_template'];
+# destructive
+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;
+}
- foreach($GLOBALS['wfpl_messages'] as $msg) {
- $sub = array('text' => $msg);
- $tem['message'][] = $sub;
- $tem['messages'] = TRUE;
+# 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');
}