JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / messages.php
index cf979d7..a762e5e 100644 (file)
@@ -1,19 +1,9 @@
 <?php
 
-#  Copyright (C) 2007 Jason Woofenden
-#
-#  This program is free software: you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation, either version 3 of the License, or
-#  (at your option) any later version.
-#  
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#  
-#  You should have received a copy of the GNU General Public License
-#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# This program is in the public domain within the United States. Additionally,
+# we waive copyright and related rights in the work worldwide through the CC0
+# 1.0 Universal public domain dedication, which can be found at
+# http://creativecommons.org/publicdomain/zero/1.0/
 
 
 # This file is useful for putting message box(es) on the screen. If you include
 # Just call message("message here") whenever you have something to report.
 #
 #
-# Once a template is loaded, call display_messages(). run.php will do that
-# automatically after your main function returns, so long as you require_once
-# this file.
+# Once a template is loaded, call display_messages(). run.php will call
+# display_messages() for you automaticallly after your main function returns
+# (so long as you require_once this file.) If you want these messages to
+# persist accross browser redirects, then you should
+# require_once(__DIR__.'/'.'lib/wfpl/session_messages.php')
 #
-# Just make sure your template has a <!--~message {~--> section with a
-# ~value html~ tag in it.
+# Just make sure your template has a <!--~$messages {~--> section with a
+# ~message html~ tag in it.
 #
 # Simple example:
 #
-#    <!--~messages {~-->
-#      <p>~value html~</p>
+#    <!--~$messages {~-->
+#       <p>~message html~</p>
 #    <!--~}~-->
 #
 # Full-featured example:
 #
-#    <!--~wfpl_messages {~-->
-#      <!--~ first {~-->
-#        <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
-#      <!--~}~-->
-#          <p style="font-size: 120%; padding: 5px; margin: 0px">~data html~</p>
-#      <!--~ sep {~-->
-#          <hr>
-#      <!--~}~-->
-#      <!--~ last {~-->
-#        </div>
-#      <!--~}~-->
+#    <!--~$messages once_if {~-->
+#       <div id="wfpl_messages">
+#          <!--~$messages {~-->
+#             <p>~message html~</p>
+#             <!--~ sep {~-->
+#                <hr>
+#             <!--~}~-->
+#          <!--~}~-->
+#       </div>
 #    <!--~}~-->
 
-require_once('code/wfpl/template.php');
+require_once(__DIR__.'/'.'template.php');
 
+# call this to display a message
 function message($msg) {
        if(!isset($GLOBALS['wfpl_messages'])) {
                $GLOBALS['wfpl_messages'] = array();
@@ -61,6 +52,7 @@ function message($msg) {
        $GLOBALS['wfpl_messages'][] = $msg;
 }
 
+# destructive
 function get_messages() {
        if(!isset($GLOBALS['wfpl_messages'])) {
                $messages = array();
@@ -76,11 +68,10 @@ function get_messages() {
        return $messages;
 }
 
-# for old-style templates
-function display_messages(&$tem = NULL, $key = 'wfpl_messages') {
-       if($tem) {
-               $tem->data[$key] = columnize(get_messages());
-       } else {
-               $GLOBALS['wfpl_template']->data[$key] = columnize(get_messages());
+# called automatically by run.php
+function display_messages(&$tem = NULL, $key = '$messages') {
+       if(!$tem) {
+               $tem = &$GLOBALS['wfpl_template'];
        }
+       $tem->data[$key] = columnize(get_messages(), 'message');
 }