X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwt.php;h=be75647bcd106ea10eda1b57f207eef0c8f863e8;hb=912bdab05d6262ab07e7ea6664192f97239db3e1;hp=7d68258d96269d301467c89258955c69fc75fdf1;hpb=ddd681b6dcd0ef511238e96a0c3b94d9e8600ef2;p=wfpl.git diff --git a/dwt.php b/dwt.php index 7d68258..be75647 100644 --- a/dwt.php +++ b/dwt.php @@ -1,28 +1,15 @@ '); + $GLOBALS['_dwt_values'] = array(''); } function dwt_init() { @@ -32,23 +19,89 @@ function dwt_init() { dwt_reset(); } -function dwt_load($filename) { - $GLOBALS['_dwt_template'] = read_whole_file($filename); +function dwt_load_str($str) { + $GLOBALS['_dwt_template'] = $str; dwt_init(); } +function dwt_load($filename) { + dwt_load_str(read_whole_file($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) { dwt_set_raw("", $value); } +# returns index into arrays +function dwt_find_raw($name) { + for($i = 0; $i < count($GLOBALS['_dwt_keys']); ++$i) { + if($GLOBALS['_dwt_keys'][$i] == $name) { + return $i; + } + } + return null; +} + +# returns index into arrays +function dwt_find($name) { + return dwt_find_raw(""); +} + +function dwt_append_raw($name, $value) { + $index = dwt_find_raw($name); + if($index !== null) { + $GLOBALS['_dwt_values'][$index] .= $value; + } else { + dwt_set_raw($name, $value); + } +} + +function dwt_append($name, $value) { + dwt_append_raw("", $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("", $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(""); +} + function dwt_output($filename = null) { if($filename !== null) { dwt_load($filename); } print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template'])); } + +?>