3 # Copyright (C) 2007 Jason Woofenden
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 require_once('code/wfpl/file.php');
20 function dwt_reset() {
21 $GLOBALS['_dwt_keys'] = array('<!-- TemplateEndEditable -->');
22 $GLOBALS['_dwt_values'] = array('');
26 if(isset($GLOBALS['_dwt_keys']) && isset($GLOBALS['_dwt_values'])) {
32 function dwt_load_str($str) {
33 $GLOBALS['_dwt_template'] = $str;
37 function dwt_load($filename) {
38 dwt_load_str(read_whole_file($filename));
41 function dwt_set_raw($name, $value) {
42 $index = dwt_find_raw($name);
44 $GLOBALS['_dwt_keys'][$index] = $name;
45 $GLOBALS['_dwt_values'][$index] = $value;
47 $GLOBALS['_dwt_keys'][] = $name;
48 $GLOBALS['_dwt_values'][] = $value;
52 function dwt_set($name, $value) {
53 dwt_set_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
56 # returns index into arrays
57 function dwt_find_raw($name) {
58 for($i = 0; $i < count($GLOBALS['_dwt_keys']); ++$i) {
59 if($GLOBALS['_dwt_keys'][$i] == $name) {
66 # returns index into arrays
67 function dwt_find($name) {
68 return dwt_find_raw("<!-- TemplateBeginEditable name=\"$name\" -->");
71 function dwt_append_raw($name, $value) {
72 $index = dwt_find_raw($name);
74 $GLOBALS['_dwt_values'][$index] .= $value;
76 dwt_set_raw($name, $value);
80 function dwt_append($name, $value) {
81 dwt_append_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
84 function dwt_prepend_raw($name, $value) {
85 $index = dwt_find_raw($name);
87 $GLOBALS['_dwt_values'][$index] = $value . $GLOBALS['_dwt_values'][$index];
89 dwt_set_raw($name, $value);
93 function dwt_prepend($name, $value) {
94 dwt_prepend_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
97 function dwt_get_raw($name) {
98 $index = dwt_find_raw($name);
100 return $GLOBALS['_dwt_values'][$index];
106 function dwt_get($name) {
107 return dwt_get_raw("<!-- TemplateBeginEditable name=\"$name\" -->");
110 function dwt_output($filename = null) {
111 if($filename !== null) {
114 print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template']));