function __construct(Wunderground_Request $request) { $results = $request->get_results(); if (empty($results->response)) { Wunderground_Plugin::log_error('Response is empty.'); return NULL; } foreach ($results->response as $key => $value) { $this->{$key} = $value; } $this->date = empty($this->date) ? NULL : new Wunderground_Date($this->date); }
function __construct($request) { $results = $request->get_results(); if (empty($results->forecast)) { Wunderground_Plugin::log_error('Response is empty.'); return NULL; } foreach ($results->current_observation as $key => $value) { $this->{$key} = $value; } $this->station = new Wunderground_Station($this->station); $this->date = new Wunderground_Date($this->date); }
function __construct(Wunderground_Request $request) { $results = $request->get_results(); if (!empty($results->error)) { // TODO: Handle properly Wunderground_Plugin::log_error('Error loading results KWS_Wunderground', $results->error); return NULL; } $this->response = new Wunderground_Response($request); $this->forecast = new Wunderground_Forecast($request); $this->current_observation = new Wunderground_Current_Observation($request); $this->alerts = new Wunderground_Alerts($request); Wunderground_Plugin::log_debug('Wunderground_Forecast', $this); }
/** * Handle edgecases and validation for shortcode attributes. * * @link http://codex.wordpress.org/Formatting_Date_and_Time Date & Time formatting * @param array $passed_atts Array of values to parse * @param array $shortcode Name of shortcode being used (`wunderground`) * @return array [description] */ function wunderground_parse_atts($passed_atts, $shortcode = 'wunderground') { $defaults = array('title' => __('Weather Forecast', 'wunderground'), 'location_title' => NULL, 'location_data' => '', 'city' => '', 'location' => '', 'iconset' => 'Incredible', 'numdays' => 5, 'class' => 'wp_wunderground', 'layout' => 'table-vertical', 'measurement' => 'english', 'datelabel' => 'm/d', 'language' => wunderground_get_language(), 'showdata' => array('search', 'alerts', 'daynames', 'pop', 'icon', 'text', 'conditions', 'date'), 'hidedata' => array()); // Use previous settings as defaults to better support backward compatibility $defaults = wp_parse_args(get_option('wp_wunderground', array()), $defaults); if (!empty($shortcode)) { $atts = shortcode_atts($defaults, $passed_atts, $shortcode); } else { $atts = wp_parse_args((array) $passed_atts, $defaults); } $atts['datelabel'] = wunderground_get_date_format($atts['datelabel']); // If there was no numdays passed, // 4 is a better default for table-horizontal layout if (empty($passed_atts['numdays'])) { switch ($atts['layout']) { case 'table-horizontal': $atts['numdays'] = 4; break; } } // Convert comma-separated value to array $atts['showdata'] = is_string($atts['showdata']) ? explode(',', $atts['showdata']) : $atts['showdata']; if (!is_numeric($atts['numdays'])) { Wunderground_Plugin::log_error(sprintf('"numdays" was set not a number: %s. Changed to the default: %d. wunderground_shortcode', $atts['numdays'], $defaults['numdays'])); $atts['numdays'] = $defaults['numdays']; } else { if (absint($atts['numdays']) > 10) { Wunderground_Plugin::log_error(sprintf('"numdays" set too high in shortcode: %s. It was changed to the max: 10. wunderground_shortcode', $atts['numdays'])); $atts['numdays'] = 10; } } // What to show in the search bar if (empty($atts['location_title'])) { $atts['location_title'] = $atts['location']; } // Process hidedata/showdata if (!empty($atts['hidedata'])) { $hidedata = is_array($atts['hidedata']) ? $hidedata : explode(',', $atts['hidedata']); // For each hidedata, unset showdata. foreach ($hidedata as $value) { foreach ($atts['showdata'] as $k => $v) { if ($v === $value) { unset($atts['showdata'][$k]); } } } } return $atts; }
function __construct(Wunderground_Request $request) { $results = $request->get_results(); if (empty($results->forecast)) { Wunderground_Plugin::log_error('Response is empty.'); return NULL; } if (!empty($results->forecast) && !empty($results->forecast->days)) { $this->days = array(); foreach ($results->forecast->days as $key => $day) { $this->days[] = new Wunderground_Forecast_Summary($day); } } Wunderground_Plugin::log_debug('Wunderground_Forecast', $this); }