X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwt.php;h=d3477534fa964fe605732647be5b48b148c1ce4d;hb=cf0e2ed3d4be7a68b8a4480ebded912361521e6e;hp=78daa5443ce56be99b3e4ab1e7a9151b85e335f6;hpb=848c8a4d215f9cce1db0a7d37e733b5959b8210f;p=wfpl.git diff --git a/dwt.php b/dwt.php index 78daa54..d347753 100644 --- a/dwt.php +++ b/dwt.php @@ -18,7 +18,7 @@ # 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(''); @@ -32,14 +32,24 @@ 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) { @@ -61,15 +71,32 @@ function dwt_find($name) { return dwt_find_raw(""); } -function dwt_append($name, $value) { - $index = dwt_find($name); +function dwt_append_raw($name, $value) { + $index = dwt_find_raw($name); if($index !== null) { $GLOBALS['_dwt_values'][$index] .= $value; } else { - dwt_set($name, $value); + 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_output($filename = null) { if($filename !== null) { dwt_load($filename);