Index: trunk/extensions/Maps/Includes/Maps_DistanceParser.php |
— | — | @@ -26,6 +26,8 @@ |
27 | 27 | */ |
28 | 28 | class MapsDistanceParser { |
29 | 29 | |
| 30 | + private static $validatedDistanceUnit = false; |
| 31 | + |
30 | 32 | /** |
31 | 33 | * Parses a distance optionaly containing a unit to a float value in meters. |
32 | 34 | * |
— | — | @@ -81,17 +83,27 @@ |
82 | 84 | return $egMapsDistanceUnits[self::getValidUnit( $unit )]; |
83 | 85 | } |
84 | 86 | |
| 87 | + /** |
| 88 | + * Returns a valid unit. If the provided one is invalid, the default will be used. |
| 89 | + * |
| 90 | + * @param string $unit |
| 91 | + */ |
85 | 92 | public static function getValidUnit( $unit = null ) { |
86 | 93 | global $egMapsDistanceUnit, $egMapsDistanceUnits; |
87 | 94 | |
88 | | - if ( $unit == null ) { |
| 95 | + // This ensures the value for $egMapsDistanceUnit is correct, and caches the result. |
| 96 | + if ( !self::$validatedDistanceUnit ) { |
| 97 | + if ( !array_key_exists( $egMapsDistanceUnit, $egMapsDistanceUnits ) ) { |
| 98 | + $egMapsDistanceUnit = $egMapsDistanceUnits[0]; |
| 99 | + } |
| 100 | + |
| 101 | + self::$validatedDistanceUnit = true; |
| 102 | + } |
| 103 | + |
| 104 | + if ( $unit == null || !array_key_exists( $unit, $egMapsDistanceUnits ) ) { |
89 | 105 | $unit = $egMapsDistanceUnit; |
90 | 106 | } |
91 | 107 | |
92 | | - if ( !array_key_exists( $unit, $egMapsDistanceUnits ) ) { |
93 | | - $unit = $egMapsDistanceUnits[0]; |
94 | | - } |
95 | | - |
96 | 108 | return $unit; |
97 | 109 | } |
98 | 110 | |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | |
100 | 100 | // Remove all hooked in services that should not be available. |
101 | 101 | foreach ( $egMapsServices as $service => $data ) { |
102 | | - if ( ! in_array( $service, $egMapsAvailableServices ) ) unset( $egMapsServices[$service] ); |
| 102 | + if ( !in_array( $service, $egMapsAvailableServices ) ) unset( $egMapsServices[$service] ); |
103 | 103 | } |
104 | 104 | $egMapsAvailableServices = array_keys( $egMapsServices ); |
105 | 105 | |