JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
copyrighted dwt.php, metaform textboxes aren't puny by default, added kill_session()
[wfpl.git] / dwt.php
diff --git a/dwt.php b/dwt.php
new file mode 100644 (file)
index 0000000..7d68258
--- /dev/null
+++ b/dwt.php
@@ -0,0 +1,54 @@
+<?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/misc.php');
+
+function dwt_reset() {
+       $GLOBALS['_dwt_keys'] = array();
+       $GLOBALS['_dwt_values'] = array();
+}
+
+function dwt_init() {
+       if(isset($GLOBALS['_dwt_keys']) && isset($GLOBALS['_dwt_values'])) {
+               return;
+       }
+       dwt_reset();
+}
+
+function dwt_load($filename) {
+       $GLOBALS['_dwt_template'] = read_whole_file($filename);
+       dwt_init();
+}
+
+function dwt_set_raw($name, $value) {
+       $GLOBALS['_dwt_keys'][] = $name;
+       $GLOBALS['_dwt_values'][] = $value;
+}
+
+function dwt_set($name, $value) {
+       dwt_set_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
+}
+
+function dwt_output($filename = null) {
+       if($filename !== null) {
+               dwt_load($filename);
+       }
+       print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template']));
+}