3 # Copyright (C) 2007 Jason Woofenden
5 # This file is part of wfpl.
7 # wfpl is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU Lesser General Public License as published by the Free
9 # Software Foundation; either version 2.1 of the License, or (at your option)
12 # wfpl is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with wfpl; if not, write to the Free Software Foundation, Inc., 51
19 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 require_once('code/wfpl/file.php');
23 function dwt_reset() {
24 $GLOBALS['_dwt_keys'] = array('<!-- TemplateEndEditable -->');
25 $GLOBALS['_dwt_values'] = array('');
29 if(isset($GLOBALS['_dwt_keys']) && isset($GLOBALS['_dwt_values'])) {
35 function dwt_load_str($str) {
36 $GLOBALS['_dwt_template'] = $str;
40 function dwt_load($filename) {
41 dwt_load_str(read_whole_file($filename));
44 function dwt_set_raw($name, $value) {
45 $GLOBALS['_dwt_keys'][] = $name;
46 $GLOBALS['_dwt_values'][] = $value;
49 function dwt_set($name, $value) {
50 dwt_set_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
53 # returns index into arrays
54 function dwt_find_raw($name) {
55 for($i = 0; $i < count($GLOBALS['_dwt_keys']); ++$i) {
56 if($GLOBALS['_dwt_keys'][$i] == $name) {
63 # returns index into arrays
64 function dwt_find($name) {
65 return dwt_find_raw("<!-- TemplateBeginEditable name=\"$name\" -->");
68 function dwt_append_raw($name, $value) {
69 $index = dwt_find_raw($name);
71 $GLOBALS['_dwt_values'][$index] .= $value;
73 dwt_set_raw($name, $value);
77 function dwt_append($name, $value) {
78 dwt_append_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
81 function dwt_output($filename = null) {
82 if($filename !== null) {
85 print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template']));