X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=messages.php;h=53d2d649b47e43b78fd76a2836c8844c56c5ef46;hp=c2389516f58ad5158121cfde2657c753a3c8b045;hb=062d46e16429f2e55573567518cb01c83b319ac4;hpb=ea4bb89646ab0b8c0a697d7c8eb339114da052a9 diff --git a/messages.php b/messages.php index c238951..53d2d64 100644 --- a/messages.php +++ b/messages.php @@ -2,59 +2,58 @@ # Copyright (C) 2007 Jason Woofenden # -# This file is part of wfpl. -# -# wfpl is free software; you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation; either version 2.1 of the License, or (at your option) -# any later version. -# -# wfpl is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for -# more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with wfpl; if not, write to the Free Software Foundation, Inc., 51 -# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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 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 +# ~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 "message_container" - # Simple example: # -# -#

~message_text.html~

-# - +# +#

~message html~

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

~message_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'])) { $GLOBALS['wfpl_messages'] = array(); @@ -63,34 +62,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']; +# destructive +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; } -?> +# 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'); +}