3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
8 require_once(__DIR__.'/'.'file.php');
10 function dwt_reset() {
11 $GLOBALS['_dwt_keys'] = array('<!-- TemplateEndEditable -->');
12 $GLOBALS['_dwt_values'] = array('');
16 if(isset($GLOBALS['_dwt_keys']) && isset($GLOBALS['_dwt_values'])) {
22 function dwt_load_str($str) {
23 $GLOBALS['_dwt_template'] = $str;
27 function dwt_load($filename) {
28 dwt_load_str(read_whole_file($filename));
31 function dwt_set_raw($name, $value) {
32 $index = dwt_find_raw($name);
34 $GLOBALS['_dwt_keys'][$index] = $name;
35 $GLOBALS['_dwt_values'][$index] = $value;
37 $GLOBALS['_dwt_keys'][] = $name;
38 $GLOBALS['_dwt_values'][] = $value;
42 function dwt_set($name, $value) {
43 dwt_set_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
46 # returns index into arrays
47 function dwt_find_raw($name) {
48 for($i = 0; $i < count($GLOBALS['_dwt_keys']); ++$i) {
49 if($GLOBALS['_dwt_keys'][$i] == $name) {
56 # returns index into arrays
57 function dwt_find($name) {
58 return dwt_find_raw("<!-- TemplateBeginEditable name=\"$name\" -->");
61 function dwt_append_raw($name, $value) {
62 $index = dwt_find_raw($name);
64 $GLOBALS['_dwt_values'][$index] .= $value;
66 dwt_set_raw($name, $value);
70 function dwt_append($name, $value) {
71 dwt_append_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
74 function dwt_prepend_raw($name, $value) {
75 $index = dwt_find_raw($name);
77 $GLOBALS['_dwt_values'][$index] = $value . $GLOBALS['_dwt_values'][$index];
79 dwt_set_raw($name, $value);
83 function dwt_prepend($name, $value) {
84 dwt_prepend_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $value);
87 function dwt_get_raw($name) {
88 $index = dwt_find_raw($name);
90 return $GLOBALS['_dwt_values'][$index];
96 function dwt_get($name) {
97 return dwt_get_raw("<!-- TemplateBeginEditable name=\"$name\" -->");
100 function dwt_output($filename = null) {
101 if($filename !== null) {
104 print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template']));