function widget_weathericon($args, $number = 1)
 {
     extract($args);
     $options = widget_weathericon_getoptions($number);
     $options = $options[$number];
     $title = $options['title'];
     if (empty($title)) {
         $title = ' ';
     }
     echo $before_widget . $before_title . $title . $after_title . "<ul class='weathericonwidget'>\n";
     WeatherIcon('location=' . $options['location'] . "&before=<li>&after=</li>\n");
     echo "</ul>\n" . $after_widget;
 }
Example #2
0
function WeatherIcon($arguments = 'before=<li>&after=</li>', $myoptions = '')
{
    global $WI, $wp_version, $l10n;
    // Check to see if display_errors are on, if so, disable them
    $WI->disableDisplayErrors();
    // Set blank $output (just in case behaviour changes in the future) -Garett
    $output = "";
    // We're using the 'var1=foo&var2=bar' input format now, so let's take care of it -Viper
    // Removed support for old style WeatherIcon call
    // Really doesn't work anymore
    // $WI->bool is required to translate from 'false' to FALSE and 'true' to TRUE.
    // -Garett
    parse_str($arguments, $new_args);
    // This function f'ing owns
    if (isset($new_args['location'])) {
        if (in_array($new_args['location'], array_keys($WI->settings['locations']))) {
            $location = $WI->settings['locations'][$new_args['location']];
            $location_name = $new_args['location'];
        }
    }
    if (empty($location)) {
        $location = $WI->settings['locations'][$WI->settings['default_location']];
        $location_name = $WI->settings['default_location'];
    }
    $station = $new_args['station'] ? $new_args['station'] : $location['station'];
    $latitude = isset($new_args['latitude']) && $new_args['latitude'] != '' ? $new_args['latitude'] : $location['latitude'];
    $longitude = isset($new_args['longitude']) && $new_args['longitude'] != '' ? $new_args['longitude'] : $location['longitude'];
    $gmt_offset = isset($new_args['gmt_offset']) && $new_args['gmt_offset'] != '' ? $new_args['gmt_offset'] : $location['gmt_offset'];
    $dst = isset($new_args['dst']) && $new_args['dst'] != '' ? $WI->bool($new_args['dst']) : $location['dst'];
    $lang = isset($new_args['lang']) && $new_args['lang'] != '' ? $new_args['lang'] : $location['language'];
    $before = isset($new_args['before']) ? $new_args['before'] : '<li>';
    $after = isset($new_args['after']) ? $new_args['after'] : '</li>';
    $h1b = isset($new_args['header_before']) ? $new_args['header_before'] : '<b>';
    $h1a = isset($new_args['header_after']) ? $new_args['header_after'] : '</b>';
    $debug = isset($new_args['debug']) && $new_args['debug'] != '' ? $WI->bool($new_args['debug']) : $WI->settings['debug'];
    $showall = isset($new_args['showall']) && $new_args['showall'] != '' ? $WI->bool($new_args['showall']) : FALSE;
    $myoptions = isset($myoptions) && is_array($myoptions) ? $myoptions : $WI->settings['display_options'];
    $display = isset($new_args['display']) && $new_args['display'] != '' ? $WI->bool($new_args['display']) : TRUE;
    if (isset($new_args['showAllLocations'])) {
        // Add the option to display location name to the top of
        // the display option array (assuming it isn't already there)
        if (!array_key_exists('display_locname', $myoptions)) {
            array_unshift($myoptions, 'display_locname');
        }
        foreach ($WI->settings['locations'] as $loc_name => $loc_info) {
            $output .= WeatherIcon("location={$loc_name}&display=false&before={$before}&after={$after}&debug={$debug}&header_before={$h1b}&header_after={$h1a}", $myoptions);
        }
        $WI->restoreDisplayErrors();
        if ($display) {
            echo $output;
            return "";
        } else {
            return $output;
        }
    }
    // Unset the current Text Domain
    unset($l10n['WI']);
    // Load the TextDomain
    load_textdomain('WI', WIi18ndir . $lang . ".mo");
    // Fetch the Metar Data for this Station
    //
    // While this is cludgy, we will pass commonly used variables here to clean up the
    // function definitions of the metar get functions below.   While most of this could
    // be done with Global variables like in the previous plugin, the matra that global
    // variables are bad has been hammered into my head.   At the moment, only the
    // WeatherIcon class is global ... and it is a collection of commonly used functions
    // and settings.   I'm not sure how compatible this will be in later version of PHP,
    // but it is acceptable at the moment in PHP5 (and, of course, PHP4).
    //
    // So while we could set these variables into WI, our global variable, these settings
    // are different between WeatherIcon plugin calls.   As such, we just pass them as
    // a function call.   I have already mentioned why we do this.
    //
    // For more information of WI variables, see WeatherIconCore.php
    //
    // -Garett
    //
    // Removed. -GH (r92)
    //$metar = $WI->get_metar($station, $latitude, $longitude, $gmt_offset, $dst, $before, $after);
    // This new method is a little cludgy, but better IMO.
    $raw = $WI->fetch_metar($station);
    // If no metar ...
    if (!$raw) {
        $output .= "<!-- " . print_r($WI->status, true) . " -->";
        $output .= $before . __('Unable to retrieve metar from NOAA IWS, NOAA ADDS or cache.   Ensure that your ICAO station is correct.  If you are unable to diagnose the problem, please report the problem to <a href="http://www.viper007bond.com/wordpress-plugins/forums/">the forums</a>.', 'WI') . $after;
        $WI->restoreDisplayErrors();
        if ($display) {
            echo $output;
            return;
        } else {
            return $output;
        }
    }
    $metar = new WeatherIconMetar($raw, $latitude, $longitude, $gmt_offset, $dst, $before, $after);
    // Get the output information from the metar decoder.
    // It is important to note the new format for internationalization.  Namely
    // #value# and #units# (and other #phrase# commands).   These are translated
    // by the Metar class into actual data.   This allows translators to shift
    // the placement around in their i18n files without instructing people to
    // alter lines of code.
    //
    // -Garett
    if (!$showall) {
        foreach ($myoptions as $value) {
            switch ($value) {
                case 'display_locname':
                    if ($location_name != '') {
                        $output .= $before . $h1b . $location_name . $h1a . $after;
                    }
                    break;
                case 'display_icon':
                    $output .= $metar->get_icon();
                    break;
                case 'display_temp':
                    $output .= $metar->get_temp();
                    break;
                case 'display_heatindex':
                    $output .= $metar->get_heatindex();
                    break;
                case 'display_windchill':
                    $output .= $metar->get_windchill();
                    break;
                case 'display_humidex':
                    $output .= $metar->get_humidex();
                    break;
                case 'display_dewpt':
                    $output .= $metar->get_dewpoint();
                    break;
                case 'display_wind':
                    $output .= $metar->get_wind();
                    break;
                case 'display_humidity':
                    $output .= $metar->get_humidity();
                    break;
                case 'display_barometer':
                    $output .= $metar->get_altimeter();
                    break;
                case 'display_conditions':
                    $output .= $metar->get_conditions();
                    break;
                case 'display_clouds':
                    $output .= $metar->get_simple_clouds();
                    break;
                case 'display_cloudsdetailed':
                    $output .= $metar->get_detailed_clouds();
                    break;
                case 'display_visibility':
                    $output .= $metar->get_visibility();
                    break;
                case 'display_updatetime':
                    $output .= $metar->get_updatetime();
                    break;
                case 'display_sunrise':
                    $output .= $metar->get_sunrise();
                    break;
                case 'display_sunset':
                    $output .= $metar->get_sunset();
                    break;
            }
        }
    } else {
        if ($location_name != '') {
            $output .= $before . $h1b . $location_name . $h1a . $after;
        }
        $output .= $metar->get_icon();
        $output .= $metar->get_temp();
        $output .= $metar->get_windchill();
        $output .= $metar->get_heatindex();
        $output .= $metar->get_humidex();
        $output .= $metar->get_dewpoint();
        $output .= $metar->get_wind();
        $output .= $metar->get_humidity();
        $output .= $metar->get_altimeter();
        $output .= $metar->get_conditions();
        $output .= $metar->get_simple_clouds();
        $output .= $metar->get_detailed_clouds();
        $output .= $metar->get_visibility();
        $output .= $metar->get_sunrise();
        $output .= $metar->get_sunset();
        $output .= $metar->get_updatetime();
    }
    // restore the error displaying
    $WI->restoreDisplayErrors();
    // Display Debug Data
    if ($debug) {
        $output .= "<br/><br/>";
        $output .= $before . "Debug Information:";
        $output .= "<ul>";
        $output .= "<li>Version Information:<ul>";
        $output .= "<li>Current PHP version: " . phpversion() . "</li>";
        $output .= "<li>Wordpress version: " . $wp_version . "</li>";
        $output .= "<li>WeatherIcon version: " . WIversion . "</li>";
        $output .= "</ul></li>";
        $output .= "<li>Location: {$location_name}<pre>";
        $output .= print_r($location, true);
        $output .= "</pre></li>";
        $output .= "<li>Status Log:<pre>";
        $output .= print_r($WI->status, true);
        $output .= "</pre></li>";
        $output .= "<li>METAR Debug:";
        $output .= "<pre>\$metar->decoded_metar\n";
        $output .= print_r($metar->decoded_metar, true);
        $output .= "</pre></li>";
        $output .= "<li><pre>\$WI->settings\n";
        $output .= print_r($WI->settings, true);
        $output .= "</pre></li>";
        $output .= "<li><pre>\$WI->icon_packs\n";
        $output .= print_r($WI->icon_packs, true);
        $output .= "</pre></li>";
        $output .= "</ul>";
        $output .= $after;
    }
    $output .= "\n<!-- Powered by WeatherIcon v" . WIversion . " | http://www.viper007bond.com/wordpress-plugins/weathericon/ -->\n";
    $output = apply_filters('WeatherIcon', $output);
    if ($display) {
        echo $output;
    } else {
        return $output;
    }
}
function weathericon_wpdash_content($ID)
{
    $options = get_option("weathericon_wpdashwidget{$ID}");
    return WeatherIcon('location=' . $options['location'] . '&before=&after=<br />&debug=FALSE&display=FALSE');
}
Example #4
0
<html>
<head>
	<title><?php 
if (!empty($location)) {
    echo $location;
} else {
    echo "Debug Page";
}
?>
</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1><?php 
if (!empty($location)) {
    echo $location;
} else {
    echo "Debug Page";
}
?>
</h1>
<?php 
if (isset($location)) {
    WeatherIcon("location={$location}&before={$before}&after={$after}&showall={$showall}&debug={$debug}");
} else {
    WeatherIcon("station={$station}&debug={$debug}&gmt_offset={$gmt}&longitude={$long}&latitude={$lat}&before={$before}&after={$after}&showall={$showall}");
}
?>
</body>
</html>