JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform: merge ckeditor settings from cms
[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. 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.
22 #
23 # Just call message("message here") whenever you have something to report.
24 #
25 #
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__.'/'.'lib/wfpl/session_messages.php')
31 #
32 # Just make sure your template has a <!--~$messages {~--> section with a
33 # ~message html~ tag in it.
34 #
35 # Simple example:
36 #
37 #    <!--~$messages {~-->
38 #       <p>~message html~</p>
39 #    <!--~}~-->
40 #
41 # Full-featured example:
42 #
43 #    <!--~$messages once_if {~-->
44 #       <div id="wfpl_messages">
45 #          <!--~$messages {~-->
46 #             <p>~message html~</p>
47 #             <!--~ sep {~-->
48 #                <hr>
49 #             <!--~}~-->
50 #          <!--~}~-->
51 #       </div>
52 #    <!--~}~-->
53
54 require_once(__DIR__.'/'.'template.php');
55
56 # call this to display a message
57 function message($msg) {
58         if(!isset($GLOBALS['wfpl_messages'])) {
59                 $GLOBALS['wfpl_messages'] = array();
60         }
61
62         $GLOBALS['wfpl_messages'][] = $msg;
63 }
64
65 # destructive
66 function get_messages() {
67         if(!isset($GLOBALS['wfpl_messages'])) {
68                 $messages = array();
69         } else {
70                 $messages = $GLOBALS['wfpl_messages'];
71                 unset($GLOBALS['wfpl_messages']);
72         }
73
74         if(function_exists('session_restore_messages')) {
75                 $messages = array_merge(session_restore_messages(), $messages);
76         }
77
78         return $messages;
79 }
80
81 # called automatically by run.php
82 function display_messages(&$tem = NULL, $key = '$messages') {
83         if(!$tem) {
84                 $tem = &$GLOBALS['wfpl_template'];
85         }
86         $tem->data[$key] = columnize(get_messages(), 'message');
87 }