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 do that
27 # automatically after your main function returns, so long as you require_once
30 # Just make sure your template has a <!--~message {~--> section with a
31 # ~value html~ tag in it.
39 # Full-featured example:
41 # <!--~wfpl_messages {~-->
43 # <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
45 # <p style="font-size: 120%; padding: 5px; margin: 0px">~data html~</p>
54 require_once('code/wfpl/template.php');
56 function message($msg) {
57 if(!isset($GLOBALS['wfpl_messages'])) {
58 $GLOBALS['wfpl_messages'] = array();
61 $GLOBALS['wfpl_messages'][] = $msg;
64 function get_messages() {
65 if(!isset($GLOBALS['wfpl_messages'])) {
68 $messages = $GLOBALS['wfpl_messages'];
69 unset($GLOBALS['wfpl_messages']);
72 if(function_exists('session_restore_messages')) {
73 $messages = array_merge(session_restore_messages(), $messages);
79 # for old-style templates
80 function display_messages(&$tem = NULL, $key = 'wfpl_messages') {
82 $tem->data[$key] = columnize(get_messages());
84 $GLOBALS['wfpl_template']->data[$key] = columnize(get_messages());