__('Display weather and forecast', 'AnyWP')); parent::WP_Widget(false, __('AnyWP Weather', 'AnyWP'), $widget_ops); } function form($instance) { $title = if_var_isset($instance['title'], ''); $place = if_var_isset($instance['place'], ''); $unit = if_var_isset($instance['unit'], ''); echo '


'; echo '


'; echo '


get_field_id('unit') . '" value="Fahrenheit"' . ($unit != 'Celsius' ? ' checked' : '') . ' />   get_field_id('unit') . '" value="Celsius"' . ($unit == 'Celsius' ? ' checked' : '') . ' />

'; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = $new_instance['title']; $instance['place'] = $new_instance['place']; $instance['unit'] = $new_instance['unit']; return $instance; } function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $title = if_var_isset($instance['title'], ''); if ($title != '') echo $before_title . $title . $after_title; $request = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22' . urlencode(if_var_isset($instance['place'], '')) . '%22&format=xml'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $xml = curl_exec($ch); curl_close($ch); if (strpos($xml, 'xml ')) { $xml = simplexml_load_string($xml); $woeid = $xml->results->place->woeid; if ($woeid != '') { $unit = ''; if (if_var_isset($instance['unit'], '') == 'Celsius') $unit = '&u=c'; $request = 'http://weather.yahooapis.com/forecastrss?w=' . $woeid . $unit; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $xml = curl_exec($ch); curl_close($ch); if (strpos($xml, '[CDATA[')) { $xml = substr($xml, strpos($xml, '[CDATA[') + 7); $xml = substr($xml, 0, strpos($xml, ']')); $xml = str_ireplace('
', '
', $xml); $xml = str_ireplace('
\n
', '

', $xml); $xml = str_ireplace('

', '
', $xml); $xml = str_ireplace("
Forecast:", '
Forecast:', $xml); $xml = str_ireplace(')
', ')
', $xml); $xml = str_ireplace("
\n