+$GLOBALS['wfpl_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");
+
+# display <option>s
+function enc_states($str) {
+ $ret = '';
+
+ return encode_options($str, $GLOBALS['wfpl_states_assoc'], PULLDOWN_HASH);
+}
+
+$GLOBALS['wfpl_provinces_assoc'] = array("AB" => "Alberta", "BC" => "British Columbia", "MB" => "Manitoba", "NF" => "Newfoundland", "NB" => "New Brunswick", "NS" => "Nova Scotia", "NT" => "Northwest Territories", "NU" => "Nunavut", "ON" => "Ontario", "PE" => "Prince Edward Island", "QC" => "Quebec", "SK" => "Saskatchewan", "YT" => "Yukon Territory");
+
+# display <option>s
+function enc_provinces($str) {
+ $ret = '';
+
+ return encode_options($str, $GLOBALS['wfpl_provinces_assoc'], PULLDOWN_HASH);
+}
+
+# returns "odd", then "even", then "odd" etc.
+function enc_evenodd($values, $name) {
+ if(!isset($GLOBALS['wfpl_even_odds'])) {
+ $GLOBALS['wfpl_even_odds'] = array();
+ }
+
+ if($GLOBALS['wfpl_even_odds'][$name]) {
+ $GLOBALS['wfpl_even_odds'][$name] = false;
+ return 'even';
+ } else {
+ $GLOBALS['wfpl_even_odds'][$name] = true;
+ return 'odd';
+ }
+}
+
+function enc_image_src($str) {
+ list($src, $width, $height, $a, $b, $c) = explode(' ', $str);
+ return $src;
+}
+
+function enc_image_width($str) {
+ list($src, $width, $height, $a, $b, $c) = explode(' ', $str);
+ return $width;
+}
+
+function enc_image_height($str) {
+ list($src, $width, $height, $a, $b, $c) = explode(' ', $str);
+ return $height;
+}
+
+function enc_thumb_src($str) {
+ list($a, $b, $c, $src, $width, $height) = explode(' ', $str);
+ return $src;
+}
+
+function enc_thumb_width($str) {
+ list($a, $b, $c, $src, $width, $height) = explode(' ', $str);
+ return $width;
+}
+function enc_thumb_height($str) {
+ list($a, $b, $c, $src, $width, $height) = explode(' ', $str);
+ return $height;
+}
+
+# example template: Length: ~length html~ day~length s~
+function enc_s($str) {
+ if($str == '1') {
+ return '';
+ }
+
+ return 's';
+}
+
+# turn http/ftp (s) urls into html links (and encode everything for html)
+# does not encode without protocol (eg "www.foo.com")
+# does not linkify email addresses
+function enc_linkify($str) {
+ $ret = '';
+ $even = true;
+ $pieces = preg_split("/((?:ht|f)tps?:\/\/[^ \,\"\n\r\t<]+)/is", $str, null, PREG_SPLIT_DELIM_CAPTURE);
+ foreach($pieces as $piece) {
+ if($even) {
+ $ret .= enc_html($piece);
+ } else {
+ $ret .= '<a href="' . enc_attr($piece) . '">' . enc_html($piece) . '</a>';
+ }
+ $even = !$even;
+ }
+ return $ret;
+}