<?php /** * Funfacts Widget */ namespace Elementor; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } class Cyarb_Funfacts extends Widget_Base { public function get_name() { return 'Cyarb_Funfacts'; } public function get_title() { return __( 'Funfacts', 'cyarb-toolkit' ); } public function get_icon() { return 'eicon-counter'; } public function get_categories() { return [ 'cyarb-elements' ]; } protected function register_controls() { $this->start_controls_section( 'funfacts_section', [ 'label' => __( 'Funfacts Control', 'cyarb-toolkit' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'choose_style', [ 'label' => __( 'Choose Style', 'cyarb-toolkit' ), 'type' => Controls_Manager::SELECT, 'options' => [ '1' => __( 'Style One', 'cyarb-toolkit' ), '2' => __( 'Style Two', 'cyarb-toolkit' ), ], 'default' => '1', ] ); $repeater = new Repeater(); $repeater->add_control( 'image', [ 'label' => __( 'Image', 'cyarb-toolkit' ), 'type' => Controls_Manager::MEDIA, ] ); $repeater->add_control( 'number', [ 'type' => Controls_Manager::NUMBER, 'label' => esc_html__( 'Ending Number', 'cyarb-toolkit' ), ] ); $repeater->add_control( 'number_suffix', [ 'type' => Controls_Manager::TEXT, 'label' => esc_html__( 'Ending Number Suffix', 'cyarb-toolkit' ), ] ); $repeater->add_control( 'title', [ 'type' => Controls_Manager::TEXT, 'label' => esc_html__( 'Title', 'cyarb-toolkit' ), ] ); $this->add_control( 'items', [ 'label' => esc_html__( 'Add Counter Item', 'cyarb-toolkit' ), 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), ] ); //Shape Images $this->add_control( 'image_shape', [ 'label' => esc_html__( 'Hide Shapes?', 'cyarb-toolkit' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Show', 'cyarb-toolkit' ), 'label_off' => esc_html__( 'Hide', 'cyarb-toolkit' ), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->end_controls_section(); $this->start_controls_section( 'counter_style', [ 'label' => __( 'Style', 'cyarb-toolkit' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'counter_color', [ 'label' => __( 'Number Color', 'cyarb-toolkit' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .single-funfacts-item h3, .single-funfacts-box h3, .single-funfacts-item.fbox2 h3, .single-funfacts-box.fbox2 h3' => 'color: {{VALUE}}', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'counter_typography', 'label' => __( 'Number Typography', 'cyarb-toolkit' ), 'selector' => '{{WRAPPER}} .single-funfacts-item h3, .single-funfacts-box h3, .single-funfacts-item.fbox2 h3, .single-funfacts-box.fbox2 h3', ] ); $this->add_control( 'title_color', [ 'label' => __( 'Title Color', 'cyarb-toolkit' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .single-funfacts-item p, .single-funfacts-box p' => 'color: {{VALUE}}', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'label' => __( 'Title Typography', 'cyarb-toolkit' ), 'selector' => '{{WRAPPER}} .single-funfacts-item p, .single-funfacts-box p', ] ); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); ?> <?php if( $settings['choose_style'] == '1' ): ?> <div class="container-fluid"> <div class="row"> <?php foreach( $settings['items'] as $item ): ?> <div class="col-lg-3 col-sm-3 col-6 col-md-3"> <div class="single-funfacts-item"> <div class="icon"> <img src="<?php echo esc_url( $item['image']['url'] ); ?>" alt="<?php echo esc_attr__( 'funfacts-icon' ); ?>"> </div> <h3><span class="odometer" data-count="<?php echo esc_attr( $item['number'] ); ?>"><?php echo esc_attr__( '00' ); ?></span><span class="sign"><?php echo esc_html( $item['number_suffix'] ); ?></span></h3> <p><?php echo esc_html( $item['title'] ); ?></p> </div> </div> <?php endforeach; ?> </div> </div> <?php if ( 'yes' === $settings['image_shape'] ) : ?> <div class="shape12"><img src="<?php echo esc_url(get_template_directory_uri() .'/assets/img/shape/shape12.png' ); ?>" alt="<?php echo esc_attr__( 'Shape', 'cyarb-toolkit' ); ?>"></div> <?php endif; ?> <?php else: ?> <div class="container"> <div class="row"> <?php foreach( $settings['items'] as $item ): ?> <div class="col-lg-3 col-sm-3 col-6 col-md-3"> <div class="single-funfacts-box fbox2"> <div class="icon"> <img src="<?php echo esc_url( $item['image']['url'] ); ?>" alt="<?php echo esc_attr__( 'funfacts-icon' ); ?>"> </div> <h3><span class="odometer" data-count="<?php echo esc_attr( $item['number'] ); ?>"><?php echo esc_attr__( '00' ); ?></span><span class="sign"><?php echo esc_html( $item['number_suffix'] ); ?></span></h3> <p><?php echo esc_html( $item['title'] ); ?></p> </div> </div> <?php endforeach; ?> </div> </div> <?php endif; ?> <?php } } Plugin::instance()->widgets_manager->register_widget_type( new Cyarb_Funfacts );