X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwt.php;h=82629ffcf19be9bc1693766e3e69f34ba063b196;hb=332683184a73f7c141132c20c715cd731687f835;hp=7d68258d96269d301467c89258955c69fc75fdf1;hpb=ddd681b6dcd0ef511238e96a0c3b94d9e8600ef2;p=wfpl.git diff --git a/dwt.php b/dwt.php index 7d68258..82629ff 100644 --- a/dwt.php +++ b/dwt.php @@ -18,11 +18,11 @@ # 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'); +require_once('code/wfpl/file.php'); function dwt_reset() { - $GLOBALS['_dwt_keys'] = array(); - $GLOBALS['_dwt_values'] = array(); + $GLOBALS['_dwt_keys'] = array(''); + $GLOBALS['_dwt_values'] = array(''); } function dwt_init() { @@ -32,11 +32,15 @@ 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; @@ -46,9 +50,39 @@ 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_output($filename = null) { if($filename !== null) { dwt_load($filename); } print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template'])); } + +?>