/**
     * The form for the widget.
     * @param  array $instance Widget instance
     */
    function form($instance)
    {
        $instance = wunderground_parse_atts($instance);
        extract($instance);
        ?>
	<div class="wunderground-settings">

		<div class="setting-wrapper">
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
">
				<h3><?php 
        esc_html_e('Title', 'wunderground');
        ?>
</h3>
				<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo esc_attr($title);
        ?>
" placeholder="<?php 
        esc_attr_e('Leave empty to hide the widget title.', 'wunderground');
        ?>
" />
			</label>
		</div>

		<div class="setting-wrapper autocomplete" id="<?php 
        echo $this->get_field_id('autocomplete');
        ?>
">
			<label for="<?php 
        echo $this->get_field_id('city');
        ?>
">
				<h3><?php 
        esc_html_e('Location', 'wunderground');
        ?>
</h3>
				<p class="description"><?php 
        esc_html_e('Locations will autoload, but you may also define custom locations.', 'wunderground');
        ?>
</p>
				<input type="text" class="wu-autocomplete widefat" autocomplete="false" id="<?php 
        echo $this->get_field_id('city');
        ?>
" name="<?php 
        echo $this->get_field_name('city');
        ?>
" value="<?php 
        echo esc_attr($city);
        ?>
" placeholder="<?php 
        esc_attr_e('Enter the name of a location.', 'wunderground');
        ?>
" />
			</label>
			<input type="hidden" class="wu-location-data" id="<?php 
        echo $this->get_field_id('location_data');
        ?>
" name="<?php 
        echo $this->get_field_name('location_data');
        ?>
" value="<?php 
        esc_attr_e($location_data);
        ?>
" />
		</div>

		<div class="setting-wrapper">
			<label for="<?php 
        echo $this->get_field_id('location_title');
        ?>
">
				<h3><?php 
        esc_html_e('Location Title', 'wunderground');
        ?>
</h3>
				<p class="description"><?php 
        esc_attr_e('Change how the location is displayed in the widget search field.', 'wunderground');
        ?>
</p>
				<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('location_title');
        ?>
" name="<?php 
        echo $this->get_field_name('location_title');
        ?>
" value="<?php 
        esc_attr_e($location_title);
        ?>
" placeholder="<?php 
        esc_attr_e('Leave empty to use the location name.', 'wunderground');
        ?>
" />
				<span class="howto"><?php 
        esc_attr_e('Example: if the Location is set to "Denver, Colorado", you may prefer to set the Location Title as "Denver", which is simpler.', 'wunderground');
        ?>
</span>
			</label>
		</div>

		<div class="setting-wrapper">
		<?php 
        $days_select = wunderground_render_select($this->get_field_name('numdays'), $this->get_field_id('numdays'), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10), $numdays);
        echo sprintf('<label for="%s"><h3>%s</h3> %s</label>', $this->get_field_id('numdays'), __('# of Days in Forecast', 'wunderground'), $days_select);
        ?>
			<p>
				<label>
					<input type="checkbox" value="current" name="<?php 
        echo $this->get_field_name('showdata');
        ?>
[current]" <?php 
        checked(in_array('current', (array) $showdata), true);
        ?>
 />
					<span class="title"><?php 
        esc_html_e('Include Current Conditions', 'wunderground');
        ?>
</span>
					<span class="howto"><?php 
        esc_html_e('Add the current conditions to the forecast.', 'wunderground');
        ?>
</span>
				</label>
			</p>
			<p>
				<label>
					<input type="checkbox" value="night" name="<?php 
        echo $this->get_field_name('showdata');
        ?>
[night]" <?php 
        checked(in_array('night', (array) $showdata), true);
        ?>
 />
					<span class="title"><?php 
        esc_html_e('Include Night Forecasts', 'wunderground');
        ?>
</span>
					<span class="howto"><?php 
        esc_html_e('This will result in double the number of forecasts shown.', 'wunderground');
        ?>
</span>
				</label>
			</p>
		</div>

		<div class="setting-wrapper icons">
			<h3><?php 
        esc_html_e('Icon Set', 'wunderground');
        ?>
</h3>
			<p class="description"><?php 
        esc_html_e('Choose the look and feel of the images that will represent the weather.', 'wunderground');
        ?>
</p>

			<ul>
		<?php 
        $icons = wunderground_get_icons(true);
        foreach ($icons as $name => $key) {
            $checked = checked($iconset, $name, false);
            echo sprintf('
				<li class="alignleft">
					<label>
						<input class="alignleft" type="radio" value="%s" name="%s" id="%s" %s />
						<span class="title">%s</span>
						<span class="alignleft icon">
							<img src="%s/clear.gif" alt="" />
						</span>
					</label>
				</li>', $name, $this->get_field_name('iconset'), $this->get_field_id('iconset'), $checked, esc_html($name), wunderground_get_icon($name));
        }
        ?>
			</ul>
			<div class="clear"></div>
		</div>

		<div class="setting-wrapper layout">
			<h3 class="layout-title"><?php 
        esc_html_e('Widget Template', 'wunderground');
        ?>
</h3>
			<h4><?php 
        esc_html_e('Choose how you would like to display the forecast.', 'wunderground');
        ?>
</h4>
		<?php 
        echo $this->render_input_template($layout);
        ?>
		</div>

		<div class="setting-wrapper forecast">
			<h3><?php 
        esc_html_e('Show in Forecast', 'wunderground');
        ?>
</h3>
			<ul>
			<?php 
        $boxes = array('search' => array('label' => __('Search Form', 'wunderground'), 'description' => __('Allow searching weather forecasts.', 'wunderground')), 'daynames' => array('label' => __('Weekday Labels', 'wunderground'), 'description' => __('Show the names of the days of the week.', 'wunderground')), 'date' => array('label' => __('Date', 'wunderground'), 'description' => __('Display the date numerically ("09/14").', 'wunderground')), 'icon' => array('label' => __('Weather Icon', 'wunderground'), 'description' => __('Icon representing the forecast conditions.', 'wunderground')), 'pop' => array('label' => __('Chance of Rain', 'wunderground'), 'description' => __('Display the percent chance of rain.', 'wunderground')), 'highlow' => array('label' => __('High & Low Temp', 'wunderground'), 'description' => __('Show the high & low temperatures for forecast.', 'wunderground')), 'conditions' => array('label' => __('Condition Title', 'wunderground'), 'description' => __('Short summary of conditions ("Clear", "Partly Cloudy", etc.).', 'wunderground')), 'text' => array('label' => __('Forecast Text', 'wunderground'), 'description' => __('Display a description of the forecast, normally in sentence format.', 'wunderground')), 'alerts' => array('label' => __('Weather Alerts &amp; Warnings', 'wunderground'), 'description' => __('Display Severe Weather alerts and warnings.', 'wunderground')));
        foreach ($boxes as $value => $box) {
            $label = esc_html($box['label']);
            $description = esc_html($box['description']);
            printf('<li><label><input type="checkbox" value="%s" name="%s[%s]" %s /> <span class="title">%s</span>%s</label></li>', $value, $this->get_field_name('showdata'), $value, checked(in_array($value, (array) $showdata), true, false), $label, '<span class="howto">' . $description . '</span>');
        }
        ?>
			</ul>
		</div>

		<div class="setting-wrapper">
			<label for="<?php 
        echo $this->get_field_id('language');
        ?>
">
			<h3><?php 
        esc_html_e('Forecast Language', 'wunderground');
        ?>
</h3>
			<?php 
        $languages = wp_list_pluck(wunderground_get_languages(), 'label', 'key');
        echo wunderground_render_select($this->get_field_name('language'), $this->get_field_id('language'), $languages, $language);
        ?>
			</label>
		</div>

		<div class="setting-wrapper">
			<h3><?php 
        esc_html_e('Measurements', 'wunderground');
        ?>
</h3>
			<ul>
				<li>
					<label class="radio"><input type="radio" class="radio" id="<?php 
        echo $this->get_field_id('measurement_f');
        ?>
" name="<?php 
        echo $this->get_field_name('measurement');
        ?>
" value="english" <?php 
        checked('english', $measurement);
        ?>
 /> <span class="title"><?php 
        esc_html_e('Fahrenheit &amp; Inches', 'wunderground');
        ?>
</span></label>
				</li>
				<li>
					<label class="radio"><input type="radio" class="radio" id="<?php 
        echo $this->get_field_id('measurement_c');
        ?>
" name="<?php 
        echo $this->get_field_name('measurement');
        ?>
" value="metric" <?php 
        checked('metric', $measurement);
        ?>
 /> <span class="title"><?php 
        esc_html_e('Celsius &amp; Meters', 'wunderground');
        ?>
</span></label>
				</li>
			</ul>
		</div>

	</div>
<?php 
    }
Пример #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);
}