JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
db_printf()'s %s, dwt_append(), states pulldown, tem_top_subs()
authorJason Woofenden <jason183@herkamire.com>
Tue, 17 Apr 2007 17:34:23 +0000 (13:34 -0400)
committerJason Woofenden <jason183@herkamire.com>
Tue, 17 Apr 2007 17:34:23 +0000 (13:34 -0400)
textareas get their own line(s) in e-mails

db.php
dwt.php
encode.php
format.php
metaform.php
metaform/template.email.txt
template.php

diff --git a/db.php b/db.php
index 065ac0e..3e4f725 100644 (file)
--- a/db.php
+++ b/db.php
@@ -130,6 +130,8 @@ function _db_printf($str, $args) {
 
                if($chr == '"') {
                        $out .= '"' . enc_sql(array_pop($args)) . '"';
+               } elseif($chr == 's') {
+                       $out .= enc_sql(array_pop($args));
                } elseif($chr == 'i') {
                        $int = format_int(array_pop($args));
                        if($int == '') $int = '0';
diff --git a/dwt.php b/dwt.php
index 7d68258..78daa54 100644 (file)
--- a/dwt.php
+++ b/dwt.php
@@ -21,8 +21,8 @@
 require_once('code/wfpl/misc.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']));
 }
+
+?>
index ab2c271..a4c4587 100644 (file)
@@ -89,4 +89,20 @@ function enc_tab($str) {
        return substr($out, 0, -1);
 }
 
+
+# display <option>s
+function enc_states($str) {
+       $states_assoc = array("AL" => "Alabama", "AK" => "Alaska", "AZ" => "Arizona", "AR" => "Arkansas", "CA" => "California", "CO" => "Colorado", "CT" => "Connecticut", "DE" => "Delaware", "FL" => "Florida", "GA" => "Georgia", "HI" => "Hawaii", "ID" => "Idaho", "IL" => "Illinois", "IN" => "Indiana", "IA" => "Iowa", "KS" => "Kansas", "KY" => "Kentucky", "LA" => "Louisiana", "ME" => "Maine", "MD" => "Maryland", "MA" => "Massachusetts", "MI" => "Michigan", "MN" => "Minnesota", "MS" => "Mississippi", "MO" => "Missouri", "MT" => "Montana", "NE" => "Nebraska", "NV" => "Nevada", "NH" => "New Hampshire", "NJ" => "New Jersey", "NM" => "New Mexico", "NY" => "New York", "NC" => "North Carolina", "ND" => "North Dakota", "OH" => "Ohio", "OK" => "Oklahoma", "OR" => "Oregon", "PA" => "Pennsylvania", "RI" => "Rhode Island", "SC" => "South Carolina", "SD" => "South Dakota", "TN" => "Tennessee", "TX" => "Texas", "UT" => "Utah", "VT" => "Vermont", "VA" => "Virginia", "WA" => "Washington", "DC" => "Washington, DC", "WV" => "West Virginia", "WI" => "Wisconsin", "WY" => "Wyoming");
+       $ret = '';
+
+       foreach($states_assoc as $code => $name) {
+               $ret .= "<option name=\"$code\"";
+               if($code == $str) {
+                       $ret .= " selected";
+               }
+               $ret .= ">$name</option>\n";
+       }
+       return $ret;
+}
+
 ?>
index a0e2f85..1bac609 100644 (file)
@@ -26,6 +26,10 @@ function format_int($str) {
        return ereg_replace('^0*([1-9])', '\1', $str);
 }
 
+function format_zip($str) {
+       return ereg_replace('[^0-9]', '', $str);
+}
+
 function format_filename($str) {
        $str = strtolower($str);
        $str = ereg_replace('[^a-z0-9_.-]', '_', $str);
index 9d6f4dd..f5c71f2 100644 (file)
@@ -34,6 +34,7 @@ $GLOBALS['types'] = array(
        'bigint' =>     array('textbox',     'int',        'varchar(100)'), # up to 100 digits, stored as a string
        'email' =>      array('textbox',     'email',      'varchar(100)'),
        'phone' =>      array('textbox',     'phone',      'varchar(32)'),
+       'state' =>      array('states',      'oneline',    'varchar(2)'),
        'money' =>      array('textbox',     'money',      'varchar(32)'),
        'dollars' =>    array('textbox',     'dollars',    'varchar(32)'),
        'url' =>        array('textbox',     'url',        'varchar(200)'),
@@ -261,7 +262,11 @@ function make_email() {
                list($name, $type, $input, $format, $sql) = $field;
                $tem->set('name', $name);
                $tem->set('caption', $name); # fixme
-               $tem->sub('fields');
+               if($type == 'textarea') {
+                       $tem->sub('multi_line');
+               } else {
+                       $tem->sub('fields');
+               }
        }
        return $tem->run();
 }
index 6e9ecc6..d96e828 100644 (file)
@@ -1,3 +1,5 @@
 ~form_name~ form submitted with the following:
 <!--~fields start~-->
-~caption~: ~~~name~~~<!--~end~-->
+~caption~: ~~~name~~~<!--~end~--><!--~multi_line start~-->
+~caption~:
+~~~name~.tab~~<!--~end~-->
index 1187a54..43cceae 100644 (file)
@@ -169,6 +169,23 @@ class tem {
        function output($templ = false) {
                print($this->run($templ));
        }
+
+       # return the contents of the top-level sub-templates
+       #
+       # this does not run the sub-templates, so if you've not called tem_sub() on them, they will be blank.
+       #
+       # Return a hash.
+       #     keys: name of top level sub-template.
+       #     values: contents of said sub-template.
+       function top_subs() {
+               $ret = array();
+               if(isset($this->sub_subs['top_level_subs'])) {
+                       foreach($this->sub_subs['top_level_subs'] as $name) {
+                               $ret[$name] = $this->get($name);
+                       }
+               }
+               return $ret;
+       }
 }
 
 # Below are functions so you can use the above class without allocating or
@@ -240,5 +257,9 @@ function template_run($template, &$keyval) {
        return preg_replace_callback(array('|<!--~([^~]*)~-->|', '|~([^~]*)~|', '|<span class="template">([^<]*)</span>|', '|<p class="template">([^<]*)</p>|'), 'template_filler', $template);
 }
 
+function tem_top_subs() {
+       tem_init();
+       return $GLOBALS['wfpl_template']->top_subs();
+}
 
 ?>