Index: trunk/extensions/Maps/Includes/Maps_DistanceParser.php |
— | — | @@ -40,6 +40,8 @@ |
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | |
| 44 | + $distance = self::normalizeDistance( $distance ); |
| 45 | + |
44 | 46 | $matches = array(); |
45 | 47 | preg_match( '/^(\d+)((\.|,)(\d+))?\s*(.*)?$/', $distance, $matches ); |
46 | 48 | |
— | — | @@ -90,6 +92,7 @@ |
91 | 93 | * @return boolean |
92 | 94 | */ |
93 | 95 | public static function isDistance( $distance ) { |
| 96 | + $distance = self::normalizeDistance( $distance ); |
94 | 97 | return preg_match( '/^(\d+)((\.|,)(\d+))?\s*(.*)?$/', $distance ); |
95 | 98 | } |
96 | 99 | |
— | — | @@ -120,9 +123,10 @@ |
121 | 124 | global $egMapsDistanceUnit, $egMapsDistanceUnits; |
122 | 125 | |
123 | 126 | // This ensures the value for $egMapsDistanceUnit is correct, and caches the result. |
124 | | - if ( !self::$validatedDistanceUnit ) { |
| 127 | + if ( self::$validatedDistanceUnit === false ) { |
125 | 128 | if ( !array_key_exists( $egMapsDistanceUnit, $egMapsDistanceUnits ) ) { |
126 | | - $egMapsDistanceUnit = $egMapsDistanceUnits[0]; |
| 129 | + $units = array_keys( $egMapsDistanceUnits ); |
| 130 | + $egMapsDistanceUnit = $units[0]; |
127 | 131 | } |
128 | 132 | |
129 | 133 | self::$validatedDistanceUnit = true; |
— | — | @@ -131,7 +135,7 @@ |
132 | 136 | if ( $unit == null || !array_key_exists( $unit, $egMapsDistanceUnits ) ) { |
133 | 137 | $unit = $egMapsDistanceUnit; |
134 | 138 | } |
135 | | - |
| 139 | + |
136 | 140 | return $unit; |
137 | 141 | } |
138 | 142 | |
— | — | @@ -147,4 +151,19 @@ |
148 | 152 | return array_keys( $egMapsDistanceUnits ); |
149 | 153 | } |
150 | 154 | |
| 155 | + /** |
| 156 | + * Normalizes a potential distance by removing spaces and truning comma's into dots. |
| 157 | + * |
| 158 | + * @since 0.6.5 |
| 159 | + * |
| 160 | + * @param $distance String |
| 161 | + * |
| 162 | + * @return string |
| 163 | + */ |
| 164 | + protected static function normalizeDistance( $distance ) { |
| 165 | + $distance = str_replace( ' ', '', $distance ); |
| 166 | + $distance = str_replace( ',', '.', $distance ); |
| 167 | + return $distance; |
| 168 | + } |
| 169 | + |
151 | 170 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -170,7 +170,7 @@ |
171 | 171 | ); |
172 | 172 | |
173 | 173 | # String. The default unit for distances. |
174 | | - $egMapsDistanceUnit = 'km'; |
| 174 | + $egMapsDistanceUnit = 'm'; |
175 | 175 | |
176 | 176 | # Integer. The default limit of fractal digits in a distance. |
177 | 177 | $egMapsDistanceDecimals = 2; |