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/>.
20 # This file is useful for putting message boxe(s) on the screen.
22 # Just call message("message here") whenever you have something to report.
24 # Once a template is loaded, call display_messages(). Your template should have
25 # a <!--~message_box start~--> section with ~message_text.html~ tag in it.
27 # If you want a divider (any text between message boxes when there are multiple
28 # boxes) provide a sub-template section named "message_divider" INSIDE
29 # "message_box" at the begining of it.
31 # If you'd like something around the group of all message boxes, you can put
32 # the whole thing in a sub-template section called "message_container"
36 # <!--~message_box start~-->
37 # <p>~message_text.html~</p>
40 # Full-featured example:
42 # <!--~message_container start~-->
43 # <div style="border: 2px solid red; background: #f88; padding: 5px">
44 # <!--~message_box start~-->
45 # <!--~message_divider start~-->
48 # <p style="font-size: 120%">~message_text.html~</p>
53 require_once('code/wfpl/template.php');
55 function message($msg) {
56 if(!isset($GLOBALS['wfpl_messages'])) {
57 $GLOBALS['wfpl_messages'] = array();
60 $GLOBALS['wfpl_messages'][] = $msg;
63 # if you want the messages in a template other than the default one, pass it like so:
65 # display_messages(ref($my_template));
66 function display_messages($template = 0) {
69 $template = &$GLOBALS['wfpl_template'];
71 $template = &$template->ref;
74 if(function_exists('session_restore_messages')) {
75 session_restore_messages();
78 if($GLOBALS['wfpl_messages']) {
79 foreach($GLOBALS['wfpl_messages'] as $msg) {
83 $template->sub('message_divider');
85 $template->set('message_text', $msg);
86 $template->sub('message_box');
88 $template->sub('message_container');
89 unset($GLOBALS['wfpl_messages']);