'alfie_wp_weather', 'description' => __( 'Alfie WP Weather widget.', 'alfie_wp_weather' )
);
$this->WP_Widget( 'alfie-wp-weather', 'Alfie WP Weather', $widget_options );
$protocol = 'http';
if ( isset( $_SERVER[ 'HTTPS' ] ) ) {
if ( strtoupper( $_SERVER[ 'HTTPS' ] ) == 'ON' ) {
$protocol = 'https';
}
}
if ( !function_exists( 'has_shortcode' ) ) {
function has_shortcode( $content, $short_code = '' ) {
$is_short_code = false;
if ( stripos( $content, '[' . $short_code ) !== false ) {
$is_short_code = true;
}
return $is_short_code;
}
}
if ( is_active_widget( false, false, $this->id_base ) && !has_shortcode( $post->post_content, 'alfie_wp_weather' ) ) {
wp_enqueue_style( 'alfie-wp-weather', ALFIE_WEATHER_URL . 'css/widget.min.css' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'alfie-wp-weather', ALFIE_WEATHER_URL . 'js/alfie.weather.min.js' );
wp_localize_script( 'alfie-wp-weather', 'alfie', array( 'path' => str_replace( $protocol . '://' . $_SERVER[ 'HTTP_HOST' ], '', plugins_url() ) ) );
wp_enqueue_script( 'alfie-wp-admin', ALFIE_WEATHER_URL . 'js/alfie-weather.min.js' );
wp_localize_script( 'alfie-wp-admin', 'alfie', array( 'path' => str_replace( $protocol . '://' . $_SERVER[ 'HTTP_HOST' ], '', plugins_url() ) ) );
}
}
function widget( $args, $instance ) {
extract( $args );
$args = array(
'woeid' => intval( $instance[ 'woeid' ] ),
'alfie_wp_weather_image' => !empty( $instance[ 'alfie_wp_weather_image' ] ) ? 1 : 0,
'alfie_wp_weather_country' => !empty( $instance[ 'alfie_wp_weather_country' ] ) ? 1 : 0,
'alfie_wp_weather_condition' => !empty( $instance[ 'alfie_wp_weather_condition' ] ) ? 1 : 0,
'alfie_wp_weather_temperature' => $instance[ 'alfie_wp_weather_temperature' ],
'alfie_wp_weather_highlow' => !empty( $instance[ 'alfie_wp_weather_highlow' ] ) ? 1 : 0,
'alfie_wp_weather_wind' => !empty( $instance[ 'alfie_wp_weather_wind' ] ) ? 1 : 0,
'alfie_wp_weather_humidity' => !empty( $instance[ 'alfie_wp_weather_humidity' ] ) ? 1 : 0,
'alfie_wp_weather_visibility' => !empty( $instance[ 'alfie_wp_weather_visibility' ] ) ? 1 : 0,
'alfie_wp_weather_sunrise' => !empty( $instance[ 'alfie_wp_weather_sunrise' ] ) ? 1 : 0,
'alfie_wp_weather_sunset' => !empty( $instance[ 'alfie_wp_weather_sunset' ] ) ? 1 : 0,
'alfie_wp_weather_forecast' => !empty( $instance[ 'alfie_wp_weather_forecast' ] ) ? 1 : 0,
'alfie_wp_weather_forecast_image' => !empty( $instance[ 'alfie_wp_weather_forecast_image' ] ) ? 1 : 0,
'alfie_wp_weather_credits' => !empty( $instance[ 'alfie_wp_weather_credits' ] ) ? 1 : 0
);
echo $before_widget;
if ( !empty( $instance[ 'title' ] ) ) {
echo $before_title . apply_filters( 'widget_title', $instance[ 'title' ], $instance, $this->id_base ) . $after_title;
}
echo '';
alfie_wp_weather( $args );
echo '
';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance = $new_instance;
$instance[ 'woeid' ] = strip_tags( $new_instance[ 'woeid' ] );
$instance[ 'alfie_wp_weather_image' ] = ( isset( $new_instance[ 'alfie_wp_weather_image' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_country' ] = ( isset( $new_instance[ 'alfie_wp_weather_country' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_condition' ] = ( isset( $new_instance[ 'alfie_wp_weather_condition' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_temperature' ] = strip_tags( $new_instance[ 'alfie_wp_weather_temperature' ] );
$instance[ 'alfie_wp_weather_highlow' ] = ( isset( $new_instance[ 'alfie_wp_weather_highlow' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_wind' ] = ( isset( $new_instance[ 'alfie_wp_weather_wind' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_humidity' ] = ( isset( $new_instance[ 'alfie_wp_weather_humidity' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_visibility' ] = ( isset( $new_instance[ 'alfie_wp_weather_visibility' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_sunrise' ] = ( isset( $new_instance[ 'alfie_wp_weather_sunrise' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_sunset' ] = ( isset( $new_instance[ 'alfie_wp_weather_sunset' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_forecast' ] = ( isset( $new_instance[ 'alfie_wp_weather_forecast' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_forecast_image' ] = ( isset( $new_instance[ 'alfie_wp_weather_forecast_image' ] ) ? 1 : 0 );
$instance[ 'alfie_wp_weather_credits' ] = ( isset( $new_instance[ 'alfie_wp_weather_credits' ] ) ? 1 : 0 );
return $instance;
}
function form( $instance ) {
wp_enqueue_style( 'alfie_weatheroptions', ALFIE_WEATHER_URL . 'css/admin.min.css', false, 0.7, 'screen' );
wp_enqueue_script( 'alfie-wp-weather_admin', ALFIE_WEATHER_URL . 'js/alfie-weather.min.js' );
$defaults = array(
'title' => __( 'Local Weather', 'alfie_wp_weather' ),
'woeid' => '769293',
'alfie_wp_weather_image' => true,
'alfie_wp_weather_country' => true,
'alfie_wp_weather_condition' => true,
'alfie_wp_weather_temperature' => 'c',
'alfie_wp_weather_highlow' => true,
'alfie_wp_weather_wind' => true,
'alfie_wp_weather_humidity' => true,
'alfie_wp_weather_visibility' => true,
'alfie_wp_weather_sunrise' => true,
'alfie_wp_weather_sunset' => true,
'alfie_wp_weather_forecast' => true,
'alfie_wp_weather_forecast_image' => true,
'alfie_wp_weather_credits' => true
);
$instance = wp_parse_args( (array)$instance, $defaults );
$temperature = strip_tags( $instance[ 'alfie_wp_weather_temperature' ] );
$temperature_option = array(
'c' => __( 'Celsius', 'alfie_wp_weather' ), 'f' => __( 'Fahrenheit', 'alfie_wp_weather' )
);
?>