3 # Copyright (C) 2007 Jason Woofenden
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # This file is useful for putting message box(es) on the screen. If you include
20 # session_messages.php these messages can even persist accross http redirects
21 # (such as you should do after receiving a POST.
23 # Just call message("message here") whenever you have something to report.
26 # Once a template is loaded, call display_messages(). run.php will call
27 # display_messages() for you automaticallly after your main function returns
28 # (so long as you require_once this file.) If you want these messages to
29 # persist accross browser redirects, then you should
30 # require_once(__DIR__.'/'.'code/wfpl/session_messages.php')
32 # Just make sure your template has a <!--~$messages {~--> section with a
33 # ~message html~ tag in it.
37 # <!--~$messages {~-->
38 # <p>~message html~</p>
41 # Full-featured example:
43 # <!--~$messages once_if {~-->
44 # <div id="wfpl_messages">
45 # <!--~$messages {~-->
46 # <p>~message html~</p>
54 require_once(__DIR__.'/'.'template.php');
56 # call this to display a message
57 function message($msg) {
58 if(!isset($GLOBALS['wfpl_messages'])) {
59 $GLOBALS['wfpl_messages'] = array();
62 $GLOBALS['wfpl_messages'][] = $msg;
66 function get_messages() {
67 if(!isset($GLOBALS['wfpl_messages'])) {
70 $messages = $GLOBALS['wfpl_messages'];
71 unset($GLOBALS['wfpl_messages']);
74 if(function_exists('session_restore_messages')) {
75 $messages = array_merge(session_restore_messages(), $messages);
81 # called automatically by run.php
82 function display_messages(&$tem = NULL, $key = '$messages') {
84 $tem = &$GLOBALS['wfpl_template'];
86 $tem->data[$key] = columnize(get_messages(), 'message');