JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
moved read_whole_file() to file no file.php. tar.php uses rsync, and supports links
[wfpl.git] / dwt.php
diff --git a/dwt.php b/dwt.php
index 7d68258..49fac82 100644 (file)
--- a/dwt.php
+++ b/dwt.php
 #  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('<!-- TemplateEndEditable -->');
+       $GLOBALS['_dwt_values'] = array('');
 }
 
 function dwt_init() {
@@ -46,9 +46,35 @@ function dwt_set($name, $value) {
        dwt_set_raw("<!-- TemplateBeginEditable name=\"$name\" -->", $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("<!-- TemplateBeginEditable name=\"$name\" -->");
+}
+
+function dwt_append($name, $value) {
+       $index = dwt_find($name);
+       if($index !== null) {
+               $GLOBALS['_dwt_values'][$index] .= $value;
+       } else {
+               dwt_set($name, $value);
+       }
+}
+
 function dwt_output($filename = null) {
        if($filename !== null) {
                dwt_load($filename);
        }
        print(str_replace($GLOBALS['_dwt_keys'], $GLOBALS['_dwt_values'], $GLOBALS['_dwt_template']));
 }
+
+?>