/**
  * Generate and output the widget
  *
  * @see Wunderground_Template in class-template.php to generate data
  *
  * @param  array $args     Widget args
  * @param  array $instance Widget settings
  */
 function widget($args, $instance)
 {
     $this->args = $args;
     $instance['location_data'] = json_decode($instance['location_data'], true);
     $this->instance = $instance;
     $title = apply_filters('widget_title', !isset($instance['title']) ? NULL : $instance['title'], $instance, $this->id_base);
     extract($args);
     $location = $this->getLocation();
     $request = new Wunderground_Request($location, null, $instance['language'], $instance['measurement']);
     $forecast = new Wunderground_Forecast($request);
     $data = $instance;
     $data['widget'] = $args;
     $data['class'] = isset($data['class']) ? $data['class'] : 'wp_wunderground';
     $language_details = wunderground_get_language($data['language'], true);
     if (!empty($language_details['rtl'])) {
         $data['class'] .= ' wu-rtl';
     }
     $data['forecast'] = $forecast;
     $data['location'] = $instance['city'];
     $data['location_title'] = empty($instance['location_title']) ? $data['location'] : $instance['location_title'];
     $data['wunderground'] = new KWS_Wunderground($request);
     $data['datelabel'] = isset($data['datelabel']) ? $data['datelabel'] : wunderground_get_date_format();
     // PWS is offline or something.
     if (!empty($data['wunderground']->response->error)) {
         $this->maybe_display_error($data['wunderground']->response->error);
         do_action('wunderground_log_debug', 'There was an error in the Wunderground response:', $data['wunderground']->response->error);
         return;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     /**
      * @see Wunderground_Template in class-template.php
      */
     do_action('wunderground_render_template', $instance['layout'], $data);
     echo $after_widget;
 }
Beispiel #2
0
/**
 * Get the subdomain for Wunderground on a per-language basis.
 *
 * The names of the languages passed by wunderground_get_languages() are
 * the subdomains, with a few exceptions. The subdomains have spaces and
 * hyphens removed.
 *
 * @filter wunderground_redirect_subdomain Change the subdomain used for a language key.
 * @param  string      $language_key Language key from wunderground_get_languages()
 * @return string                    Wunderground subdomain string
 */
function wunderground_get_subdomain($language_key = NULL)
{
    if (empty($language_key)) {
        $language_key = wunderground_get_language();
    }
    $language_key = strtoupper($language_key);
    switch ($language_key) {
        case 'EN':
            $subdomain = 'www';
            break;
        case 'DL':
            $subdomain = 'deutsch';
            break;
        case 'HT':
            $subdomain = 'haitian';
            break;
        case 'JP':
            $subdomain = 'nihongo';
            break;
        case 'CN':
            $subdomain = 'simplifiedchinese';
            break;
        case 'TW':
            $subdomain = 'traditionalchinese';
            break;
        default:
            // Convert "French Canadian" to "frenchcanadian" for subdomain
            $languages = wunderground_get_languages();
            if (isset($languages[$language_key]) && isset($languages[$language_key]['value'])) {
                // Get the name of the language
                $subdomain = $languages[$language_key]['value'];
                // Replace "-" and " " with nothing
                $subdomain = str_replace(array(' ', '-'), '', $subdomain);
                // Then lower-case it.
                $subdomain = strtolower($subdomain);
            } else {
                $subdomain = 'www';
            }
            break;
    }
    return apply_filters('wunderground_redirect_subdomain', $subdomain, $language_key);
}
Beispiel #3
0
 /**
  * Set the language for the forecast
  * @param string $language [description]
  */
 private function set_language($language = 'EN')
 {
     // If the helper function doesn't exist for some reason, don't use it
     if (function_exists('wunderground_get_language')) {
         $this->language = wunderground_get_language($language);
     } else {
         $this->language = $language;
     }
 }