[turba] UK and Australian address mapping patch
subOrbit.com
turba.list at suborbit.com
Sun Feb 27 12:06:37 PST 2005
After a little playing I've managed to add mapping links for UK and
Australian addresses. The file that needs patching is,
[Horde home]/lib/Horde/UI/VarRenderer/html.php
The patch is (excuse bad line breaks):
--- html.php.old 2005-02-27 01:40:04.000000000 +0000
+++ html.php 2005-02-27 16:14:47.000000000 +0000
@@ -971,7 +971,41 @@
{
$address = $var->getValue($vars);
- if
(preg_match('/(.*)\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/',
$address, $addressParts)) {
+
$uk_pc_regexp='(?:(?:A[BL]|B[ABDHLNRST]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO|ZE)\d(?:\d|[A-Z])?
\d[A-Z]{2})';
+
+ $aus_state_regexp='(?:ACT|NSW|NT|QLD|SA|TAS|VIC|WA)';
+
+ if (preg_match('/(' . $uk_pc_regexp . ')/', $address,
$postcode)) {
+ /* UK postcode detected. */
+ /* Multimap.co.uk generated map */
+ $mapurl = 'http://www.multimap.com/map/browse.cgi?pc=' .
urlencode($postcode[1]);
+ $desc = _("Multimap UK map");
+ $icon = 'map.png';
+ } elseif (preg_match('/' . $aus_state_regexp . '/', $address))
{
+ /* Australian state detected. */
+ /* Whereis.com.au generated map */
+ $mapurl =
'http://www.whereis.com.au/whereis/mapping/geocodeAddress.do?';
+ $desc = _("Whereis Aus. map");
+ $icon = 'map.png';
+ /* Split out the address, line-by-line. */
+ if ($addressLines = explode('\n', $address)) {
+ for ($i=0; $i<count($addressLines); $i++) {
+ /* See if it's the street number & name. */
+ if
(preg_match('/(\d+\s*\/\s*)?(\d+|\d+[a-zA-Z])\s+([a-zA-Z ]*)/',
$addressLines[$i], $lineParts)) {
+ $mapurl .= '&streetNumber=' .
urlencode($lineParts[2]);
+ $mapurl .= '&streetName=' .
urlencode($lineParts[3]);
+ }
+ /* Look for "Suburb, State". */
+ if (preg_match('/([a-zA-Z ]*),?\s+' .
$aus_state_regexp . '/', $addressLines[$i], $lineParts)) {
+ $mapurl .= '&suburb=' .
urlencode($lineParts[1]);
+ }
+ /* Look for "State <4 digit postcode>". */
+ if (preg_match('/(' . $aus_state_regexp .
')\s+(\d{4})/', $addressLines[$i], $lineParts)) {
+ $mapurl .= '&state=' .
urlencode($lineParts[1]);
+ }
+ }
+ }
+ } elseif
(preg_match('/(.*)\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/',
$address, $addressParts)) {
/* American/Canadian address style. */
/* Mapquest generated map */
$mapurl =
'http://www.mapquest.com/maps/map.adp?size=big&zoom=7';
More information about the turba
mailing list