JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
wfpl_template: renamed to wfpl_tem_data to avoid conflict with old system.
[wfpl.git] / messages.php
1 <?php
2
3 #  Copyright (C) 2007 Jason Woofenden
4 #
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.
9 #  
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.
14 #  
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/>.
17
18
19 # This file is useful for putting message box(es) on the screen.
20 #
21 # Just call message("message here") whenever you have something to report.
22 #
23 # Once a template is loaded, call display_messages(). Your template should have
24 # a <!--~message?~--> section with a ~text:html~ tag in it.
25 #
26 # If you want a divider (any text between message boxes when there are
27 # multiple boxes) provide a sub-template section named "separator"
28 # INSIDE "message" at the begining of it.
29 #
30 # If you'd like something around the group of all message boxes, you can put
31 # the whole thing in a sub-template section called "messages"
32
33 # Simple example:
34 #
35 #    <!--~message?~-->
36 #        <p>~text:html~</p>
37 #    <!--~.~-->
38
39 # Full-featured example:
40 #
41 #    <!--~messages?~-->
42 #         <div style="border: 2px solid red; background: #f88; padding: 5px">
43 #         <!--~message?~-->
44 #             <!--~separator?~-->
45 #                 <hr />
46 #             <!--~separator.~-->
47 #             <p style="font-size: 120%">~text:html~</p>
48 #         <!--~message.~-->
49 #         </div>
50 #    <!--~messages.~-->
51
52 require_once('code/wfpl/template.php');
53
54 function message($msg) {
55         if(!isset($GLOBALS['wfpl_messages'])) {
56                 if(function_exists('session_restore_messages')) {
57                         $GLOBALS['wfpl_messages'] = session_restore_messages();
58                 } else $GLOBALS['wfpl_messages'] = array();
59         }
60
61         $GLOBALS['wfpl_messages'][] = $msg;
62 }
63
64 function display_messages(&$tem = NULL) {
65         if(!$GLOBALS['wfpl_messages']) return;
66         foreach($GLOBALS['wfpl_messages'] as $msg) {
67                 $sub = array('text' => $msg);
68                 $GLOBALS['wfpl_tem_data']['message'][] = $sub;
69                 $GLOBALS['wfpl_tem_data']['messages'] = TRUE;
70         }
71 }