widget_icon_classes('weather');
}
/**
* Get widget categories.
*
* Retrieve the list of categories the Weather widget belongs to.
*
* @since 1.0.0
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return [ 'ai-elements' ];
}
/**
* Retrieve the list of scripts the Weather widget depended on.
*
* Used to set scripts dependencies required to run the widget.
*
* @since 1.3.0
* @access public
*
* @return array Widget scripts dependencies.
*/
public function get_script_depends() {
return [ 'ai-front-end' ];
}
/**
* Get widget keywords.
* @return array widget keywords.
*/
public function get_keywords() {
return [ 'weather', 'google weather', 'cloud', 'rain', 'open weather' ];
}
public function get_help_url() {
return 'https://aiaddons.ai/weather-demo/';
}
/**
* Register Weather widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
* @access protected
*/
protected function register_controls() {
$openaiea_api_key = aiea_addon_base()->aiea_options('open-weather-api');
if( !empty( $openaiea_api_key ) ){
//General Section
$this->start_controls_section(
'general_section',
[
'label' => esc_html__( 'General', 'ai-addons' ),
'tab' => Controls_Manager::TAB_CONTENT,
'description' => esc_html__( 'Default contact form options.', 'ai-addons' ),
]
);
$this->add_control(
'api_version',
[
'type' => Controls_Manager::SELECT,
'label' => esc_html__( 'Open Weather Map API Version', 'ai-addons' ),
'default' => '2.5',
'options' => [
'2.5' => esc_html__( 'Free(API 2.5)', 'ai-addons' ),
'3.0' => esc_html__( 'One Call API 3.0', 'ai-addons' ),
],
'description' => __( 'Check Open Weather Map API here Open Weather Map API', 'ai-addons'),
]
);
$this->add_control(
'city',
[
'type' => Controls_Manager::TEXT,
'label' => esc_html__( 'City Name', 'ai-addons' ),
'description' => __( 'Enter your city name or click this auto deduct City Auto Deduct.
*Note: Example city name like London,UK', 'ai-addons'),
'default' => '',
]
);
$this->add_control(
'update_cycle',
[
'type' => Controls_Manager::SELECT,
'label' => esc_html__( 'Update Once In', 'ai-addons' ),
'default' => '60',
'options' => [
'60' => esc_html__( '1 Hour', 'ai-addons' ),
'30' => esc_html__( '30 Minutes', 'ai-addons' ),
'20' => esc_html__( '20 Minutes', 'ai-addons' ),
'10' => esc_html__( '10 Minutes', 'ai-addons' ),
'5' => esc_html__( '5 Minutes', 'ai-addons' ),
],
'description' => __( 'Update weather report once in a hour or 10 minute once. Default will be 1 hour.', 'ai-addons'),
]
);
$this->add_control(
'weather_reset',
[
'type' => Controls_Manager::RAW_HTML,
'raw' => __( 'Reset weather data. Reset', 'ai-addons' ),
]
);
$this->end_controls_section();
//Title Section
$this->start_controls_section(
'weather_title_section',
[
'label' => esc_html__( 'Title', 'ai-addons' ),
'tab' => Controls_Manager::TAB_CONTENT,
'description' => esc_html__( 'Weather title options.', 'ai-addons' ),
]
);
$this->add_control(
'enable_title',
[
'label' => esc_html__( 'Enable Title', 'ai-addons' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes'
]
);
$this->add_control(
'prefix_title',
[
'type' => Controls_Manager::TEXT,
'label' => esc_html__( 'Title Prefix', 'ai-addons' ),
'description' => esc_html__( 'Enter some text to show on title prefix', 'ai-addons' ),
'default' => esc_html__( 'Weather in', 'ai-addons' ),
'condition' => [
'enable_title' => 'yes'
],
]
);
$this->add_control(
'enable_custom_title',
[
'label' => esc_html__( 'Enable Title Show Custom Title', 'ai-addons' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'no'
]
);
$this->add_control(
'custom_title',
[
'type' => Controls_Manager::TEXT,
'label' => esc_html__( 'Custom Title', 'ai-addons' ),
'description' => esc_html__( 'Enter some text to show as a custom title', 'ai-addons' ),
'default' => '',
'condition' => [
'enable_custom_title' => 'yes'
],
]
);
$this->add_control(
'suffix_title',
[
'type' => Controls_Manager::TEXT,
'label' => esc_html__( 'Title Suffix', 'ai-addons' ),
'description' => esc_html__( 'Enter some text to show on title suffix', 'ai-addons' ),
'default' => '',
'condition' => [
'enable_title' => 'yes'
],
]
);
$this->end_controls_section();
}else{
//Weather Section
$this->start_controls_section(
'general_section',
[
'label' => esc_html__( 'Weather', 'ai-addons' ),
'tab' => Controls_Manager::TAB_CONTENT
]
);
$this->add_control(
'weather_api_msg',
[
'type' => Controls_Manager::RAW_HTML,
'raw' => sprintf( 'You should put Open Weather Map API key on plugin settings. %s', __( 'AI addons -> settings -> Open Weather API Key', 'ai-addons' ) ),
'content_classes' => 'ai-elementor-warning'
]
);
$this->end_controls_section();
}
}
/**
* Render Weather widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
* @access protected
*/
protected function render() {
$settings = $this->get_settings_for_display();
extract( $settings );
$api_key = aiea_addon_base()->aiea_options('open-weather-api');
$api_version = $settings['api_version'];
$city = $settings['city'];
$update_cycle = isset( $settings['update_cycle'] ) ? $settings['update_cycle'] : 60;
$is_edit_mode = \Elementor\Plugin::$instance->editor->is_edit_mode();
echo '