1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20:
21: class Horde_Service_Weather_Current_WeatherUnderground extends Horde_Service_Weather_Current_Base
22: {
23: protected $_map = array(
24: 'condition' => 'weather',
25: 'humidity' => 'relative_humidity',
26: 'wind_direction' => 'wind_dir',
27: 'wind_degrees' => 'wind_degrees',
28: 'icon_url' => 'icon_url'
29: );
30:
31: 32: 33: 34: 35: 36: 37:
38: public function __isset($property)
39: {
40: return !empty($this->_properties[$property]);
41: }
42:
43: 44: 45: 46: 47: 48: 49:
50: public function __get($property)
51: {
52:
53:
54: switch ($property) {
55: case 'logo_url':
56: return $this->_properties['image']->url;
57: case 'time':
58: $time = $this->_properties['observation_time_rfc822'];
59: $time = new Horde_Date($time);
60: $time->setTimezone($this->_properties['local_tz_long']);
61: return $time;
62: case 'temp':
63: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
64: return round($this->_properties['temp_f']);
65: }
66: return round($this->_properties['temp_c']);
67: case 'wind_speed':
68: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
69: return $this->_properties['wind_mph'];
70: }
71: return round($this->_properties['wind_mph'] * Horde_Service_Weather::CONVERSION_MPH_TO_KPH);
72: case 'wind_gust':
73: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
74: return $this->_properties['wind_gust_mph'];
75: }
76: return round($this->_properties['wind_gust_mph'] * Horde_Service_Weather::CONVERSION_MPH_TO_KPH);
77:
78: case 'dewpoint':
79: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
80: return $this->_properties['dewpoint_f'];
81: }
82: return $this->_properties['dewpoint_c'];
83:
84: case 'heat_index':
85: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
86: return $this->_properties['heat_index_f'];
87: }
88: return $this->_properties['heat_index_c'];
89:
90: case 'wind_chill':
91: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
92: return $this->_properties['wind_chill_f'];
93: }
94: return $this->_properties['wind_chill_c'];
95:
96: case 'visibility':
97: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
98: return round($this->_properties['visibility_mi']);
99: }
100: return round($this->_properties['visibility_km']);
101:
102: case 'pressure':
103: if ($this->_weather->units == Horde_Service_Weather::UNITS_STANDARD) {
104: return $this->_properties['pressure_in'];
105: }
106: return $this->_properties['pressure_mb'];
107:
108: case 'pressure_trend':
109: switch ($this->_properties['pressure_trend']) {
110: case '0':
111: return Horde_Service_Weather_Translation::t('steady');
112: case '+':
113: return Horde_Service_Weather_Translation::t('rising');
114: case '-':
115: return Horde_Service_Weather_Translation::t('falling');
116: }
117: break;
118:
119: case 'icon':
120: return $this->_weather->iconMap[$this->_properties['icon']];
121:
122: default:
123: if (empty($this->_map[$property])) {
124: throw new Horde_Service_Weather_Exception_InvalidProperty();
125: }
126: if (strpos($this->_properties[$this->_map[$property]], '-999') !== false) {
127: return Horde_Service_Weather_Translation::t('N/A');
128: }
129: return Horde_Service_Weather_Translation::t($this->_properties[$this->_map[$property]]);
130: }
131: }
132:
133: }