JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / messages.php
1 <?php
2
3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
7
8
9 # This file is useful for putting message box(es) on the screen. If you include
10 # session_messages.php these messages can even persist accross http redirects
11 # (such as you should do after receiving a POST.
12 #
13 # Just call message("message here") whenever you have something to report.
14 #
15 #
16 # Once a template is loaded, call display_messages(). run.php will call
17 # display_messages() for you automaticallly after your main function returns
18 # (so long as you require_once this file.) If you want these messages to
19 # persist accross browser redirects, then you should
20 # require_once(__DIR__.'/'.'lib/wfpl/session_messages.php')
21 #
22 # Just make sure your template has a <!--~$messages {~--> section with a
23 # ~message html~ tag in it.
24 #
25 # Simple example:
26 #
27 #    <!--~$messages {~-->
28 #       <p>~message html~</p>
29 #    <!--~}~-->
30 #
31 # Full-featured example:
32 #
33 #    <!--~$messages once_if {~-->
34 #       <div id="wfpl_messages">
35 #          <!--~$messages {~-->
36 #             <p>~message html~</p>
37 #             <!--~ sep {~-->
38 #                <hr>
39 #             <!--~}~-->
40 #          <!--~}~-->
41 #       </div>
42 #    <!--~}~-->
43
44 require_once(__DIR__.'/'.'template.php');
45
46 # call this to display a message
47 function message($msg) {
48         if(!isset($GLOBALS['wfpl_messages'])) {
49                 $GLOBALS['wfpl_messages'] = array();
50         }
51
52         $GLOBALS['wfpl_messages'][] = $msg;
53 }
54
55 # destructive
56 function get_messages() {
57         if(!isset($GLOBALS['wfpl_messages'])) {
58                 $messages = array();
59         } else {
60                 $messages = $GLOBALS['wfpl_messages'];
61                 unset($GLOBALS['wfpl_messages']);
62         }
63
64         if(function_exists('session_restore_messages')) {
65                 $messages = array_merge(session_restore_messages(), $messages);
66         }
67
68         return $messages;
69 }
70
71 # called automatically by run.php
72 function display_messages(&$tem = NULL, $key = '$messages') {
73         if(!$tem) {
74                 $tem = &$GLOBALS['wfpl_template'];
75         }
76         $tem->data[$key] = columnize(get_messages(), 'message');
77 }