+$GLOBALS['wfpl_states_assoc'] = array(array("AL", "Alabama"), array("AK", "Alaska"), array("AZ", "Arizona"), array("AR", "Arkansas"), array("CA", "California"), array("CO", "Colorado"), array("CT", "Connecticut"), array("DE", "Delaware"), array("FL", "Florida"), array("GA", "Georgia"), array("HI", "Hawaii"), array("ID", "Idaho"), array("IL", "Illinois"), array("IN", "Indiana"), array("IA", "Iowa"), array("KS", "Kansas"), array("KY", "Kentucky"), array("LA", "Louisiana"), array("ME", "Maine"), array("MD", "Maryland"), array("MA", "Massachusetts"), array("MI", "Michigan"), array("MN", "Minnesota"), array("MS", "Mississippi"), array("MO", "Missouri"), array("MT", "Montana"), array("NE", "Nebraska"), array("NV", "Nevada"), array("NH", "New Hampshire"), array("NJ", "New Jersey"), array("NM", "New Mexico"), array("NY", "New York"), array("NC", "North Carolina"), array("ND", "North Dakota"), array("OH", "Ohio"), array("OK", "Oklahoma"), array("OR", "Oregon"), array("PA", "Pennsylvania"), array("RI", "Rhode Island"), array("SC", "South Carolina"), array("SD", "South Dakota"), array("TN", "Tennessee"), array("TX", "Texas"), array("UT", "Utah"), array("VT", "Vermont"), array("VA", "Virginia"), array("WA", "Washington"), array("DC", "Washington, DC"), array("WV", "West Virginia"), array("WI", "Wisconsin"), array("WY", "Wyoming"));
+
+# display <option>s
+function enc_states($str) {
+ $ret = '';
+
+ return encode_options($str, $GLOBALS['wfpl_states_assoc']);
+}
+
+$GLOBALS['wfpl_provinces_assoc'] = array(array("AB", "Alberta"), array("BC", "British Columbia"), array("MB", "Manitoba"), array("NF", "Newfoundland"), array("NB", "New Brunswick"), array("NS", "Nova Scotia"), array("NT", "Northwest Territories"), array("NU", "Nunavut"), array("ON", "Ontario"), array("PE", "Prince Edward Island"), array("QC", "Quebec"), array("SK", "Saskatchewan"), array("YT", "Yukon Territory"));
+
+# display <option>s
+function enc_provinces($str) {
+ $ret = '';
+
+ return encode_options($str, $GLOBALS['wfpl_provinces_assoc']);
+}
+
+# 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 wfpl_nth_word($str, $n) {
+ $a = explode(' ', $str);
+ return isset($a[$n]) ? $a[$n] : null;
+}
+
+# encoding is a space separated list of:
+# image_filename width height thumb_filename thumb_width thumb_height
+function enc_image_src($str) { return wfpl_nth_word($str, 0); }
+function _enc_image_src_at_width($str, $width) {
+ $src = enc_image_src($str);
+ if ($src) {
+ return
+ substr($src, 0, -4)
+ . 'w'
+ . $width
+ . substr($src, -4);
+ }
+ return '';
+}
+# define these width constants in your config.php
+function enc_image_src_full($str) { return _enc_image_src_at_width($str, WFPL_IMAGE_WIDTH_FULL); }
+function enc_image_src_small($str) { return _enc_image_src_at_width($str, WFPL_IMAGE_WIDTH_SMALL); }
+function enc_image_src_thumb($str) { return _enc_image_src_at_width($str, WFPL_IMAGE_WIDTH_THUMB); }
+function enc_image_width($str) { return wfpl_nth_word($str, 1); }
+function enc_image_height($str) { return wfpl_nth_word($str, 2); }
+function enc_image_aspect($str) {
+ $a = explode(' ', $str);
+ if (count($a) < 3) {
+ return '';
+ }
+ return ''.(round(100000 * ((int)$a[2]) / ((int)$a[1]) / 1000)).'%';
+}
+# obsolete:
+function enc_thumb_src($str) { return wfpl_nth_word($str, 3); }
+function enc_thumb_width($str) { return wfpl_nth_word($str, 4); }
+function enc_thumb_height($str) { return wfpl_nth_word($str, 5); }
+
+# 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;
+}
+
+# turns a filename into the unix timestamp of that files modification date
+function enc_mtime($dummy, $filename) {
+ $stat = stat($filename);
+ if ($stat === false) {
+ return '';
+ }
+ return '' . $stat['mtime'];
+}