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';
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() {
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']));
}
+
+?>
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;
+}
+
?>
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);
'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)'),
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();
}
~form_name~ form submitted with the following:
<!--~fields start~-->
-~caption~: ~~~name~~~<!--~end~-->
+~caption~: ~~~name~~~<!--~end~--><!--~multi_line start~-->
+~caption~:
+~~~name~.tab~~<!--~end~-->
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
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();
+}
?>