JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / dwt.php
diff --git a/dwt.php b/dwt.php
index 82629ff..b4b821e 100644 (file)
--- a/dwt.php
+++ b/dwt.php
@@ -1,24 +1,11 @@
 <?php
 
-#  Copyright (C) 2007 Jason Woofenden
-#
-#  This file is part of wfpl.
-#
-#  wfpl is free software; you can redistribute it and/or modify it under the
-#  terms of the GNU Lesser General Public License as published by the Free
-#  Software Foundation; either version 2.1 of the License, or (at your option)
-#  any later version.
-#
-#  wfpl 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 Lesser General Public License for
-#  more details.
-#
-#  You should have received a copy of the GNU Lesser General Public License
-#  along with wfpl; if not, write to the Free Software Foundation, Inc., 51
-#  Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-
-require_once('code/wfpl/file.php');
+# 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/
+
+require_once(__DIR__.'/'.'file.php');
 
 function dwt_reset() {
        $GLOBALS['_dwt_keys'] = array('<!-- TemplateEndEditable -->');
@@ -42,8 +29,14 @@ function dwt_load($filename) {
 }
 
 function dwt_set_raw($name, $value) {
-       $GLOBALS['_dwt_keys'][] = $name;
-       $GLOBALS['_dwt_values'][] = $value;
+       $index = dwt_find_raw($name);
+       if($index) {
+               $GLOBALS['_dwt_keys'][$index] = $name;
+               $GLOBALS['_dwt_values'][$index] = $value;
+       } else {
+               $GLOBALS['_dwt_keys'][] = $name;
+               $GLOBALS['_dwt_values'][] = $value;
+       }
 }
 
 function dwt_set($name, $value) {
@@ -78,11 +71,35 @@ function dwt_append($name, $value) {
        dwt_append_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
 }
 
+function dwt_prepend_raw($name, $value) {
+       $index = dwt_find_raw($name);
+       if($index !== null) {
+               $GLOBALS['_dwt_values'][$index] = $value . $GLOBALS['_dwt_values'][$index];
+       } else {
+               dwt_set_raw($name, $value);
+       }
+}
+
+function dwt_prepend($name, $value) {
+       dwt_prepend_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
+}
+
+function dwt_get_raw($name) {
+       $index = dwt_find_raw($name);
+       if($index !== null) {
+               return $GLOBALS['_dwt_values'][$index];
+       } else {
+               return false;
+       }
+}
+
+function dwt_get($name) {
+       return dwt_get_raw("<!-- TemplateBeginEditable name=\"$name\" -->");
+}
+
 function dwt_output($filename = null) {
        if($filename !== null) {
                dwt_load($filename);
        }
        print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template']));
 }
-
-?>