navasena/wp-content/plugins/thinkai-plugin/elementor/button.php

442 lines
12 KiB
PHP
Raw Normal View History

2024-07-31 13:12:38 +07:00
<?php namespace THINKAIPLUGIN\Element;
use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Group_Control_Text_Shadow;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Text_Stroke;
use Elementor\Plugin;
/**
* Elementor button widget.
* Elementor widget that displays a button with the ability to control every
* aspect of the button design.
*
* @since 1.0.0
*/
class Button extends Widget_Base {
/**
* Get widget name.
* Retrieve button widget name.
*
* @since 1.0.0
* @access public
* @return string Widget name.
*/
public function get_name() {
return 'thinkai_button';
}
/**
* Get widget title.
* Retrieve button widget title.
*
* @since 1.0.0
* @access public
* @return string Widget title.
*/
public function get_title() {
return esc_html__( 'Thinkai Button', 'thinkai' );
}
/**
* Get widget icon.
* Retrieve button widget icon.
*
* @since 1.0.0
* @access public
* @return string Widget icon.
*/
public function get_icon() {
return 'eicon-button';
}
/**
* Get widget categories.
* Retrieve the list of categories the button widget belongs to.
* Used to determine where to display the widget in the editor.
*
* @since 2.0.0
* @access public
* @return array Widget categories.
*/
public function get_categories() {
return [ 'thinkai' ];
}
/**
* Register button 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() {
$this->start_controls_section(
'button',
[
'label' => esc_html__( 'Thinkai Button', 'thinkai' ),
]
);
$this->add_control(
'btn_style',
[
'label' => esc_html__( 'Choose Button Style', 'thinkai' ),
'label_block' => true,
'type' => Controls_Manager::SELECT,
'default' => '1',
'options' => array(
'1' => esc_html__( 'Style One ', 'thinkai'),
'2' => esc_html__( 'Style Two', 'thinkai' ),
'3' => esc_html__( 'Style Three', 'thinkai' ),
'4' => esc_html__( 'Style Four', 'thinkai' ),
),
]
);
$this->add_control(
'btn_title',
[
'label' => __( 'Button Title', 'thinkai' ),
'type' => Controls_Manager::TEXT,
'label_block' => true,
'dynamic' => [
'active' => true,
],
'placeholder' => __( 'Enter your Button Title Here', 'thinkai' ),
]
);
$this->add_control(
'link_option',
[
'label' => esc_html__( 'Select link Option', 'thinkai' ),
'label_block' => true,
'type' => Controls_Manager::SELECT,
'default' => 'extranal',
'options' => array(
'extranal' => esc_html__( 'Extranal ', 'thinkai'),
'page' => esc_html__( 'Page ', 'thinkai'),
),
]
);
$this->add_control(
'link',
[
'label' => __( 'External Link', 'thinkai' ),
'type' => Controls_Manager::URL,
'label_block' => true,
'placeholder' => __( 'https://your-link.com', 'thinkai' ),
'show_external' => true,
'default' => [
'url' => '',
'is_external' => true,
'nofollow' => true,
],
'condition' => [
'link_option' => 'extranal'
]
]
);
$this->add_control(
'page_select',
[
'label' => esc_html__( 'Select Page', 'thinkai' ),
'label_block' => true,
'type' => Controls_Manager::SELECT2,
'default' => 'extranal',
'options' => thinkai_page_list(),
'condition' => [
'link_option' => 'page'
]
]
);
$this->end_controls_section();
/**Button Style**/
$this->start_controls_section(
'button_style',
[
'label' => esc_html__('Button Style Setting', 'thinkai'),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_responsive_control(
'general_align',
[
'label' => esc_html__( 'Alignment', 'thinkai' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__( 'Left', 'thinkai' ),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'thinkai' ),
'icon' => 'eicon-text-align-center',
],
'right' => [
'title' => esc_html__( 'Right', 'thinkai' ),
'icon' => 'eicon-text-align-right',
],
],
'default' => '',
'selectors' => [
'{{WRAPPER}} .yt-btn' => 'text-align: {{VALUE}}',
],
]
);
$this->start_controls_tabs( 'thinkai_tabs_btn' );
$this->start_controls_tab(
'thinkai_tab_btn_normal',
[
'label' => __( 'Normal', 'thinkai' ),
]
);
$this->add_responsive_control(
'btn_width_size',
[
'label' => __( 'Width', 'thinkai' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', 'em', '%', 'custom' ],
'range' => [
'px' => [
'min' => 0,
'max' => 500,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .thinkai-btn' => 'width: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'btn_height_size',
[
'label' => __( 'Height', 'thinkai' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', 'em', '%', 'custom' ],
'range' => [
'px' => [
'min' => 0,
'max' => 500,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .thinkai-btn' => 'height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'btn_margin',
[
'label' => __( 'Margin', 'thinkai' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .thinkai-btn' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
],
'frontend_available' => true,
]
);
$this->add_responsive_control(
'btn_padding',
[
'label' => __( 'Padding', 'thinkai' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .thinkai-btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
],
'frontend_available' => true,
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'btn_border_type',
'selector' =>
'{{WRAPPER}} .thinkai-btn',
'separator' => 'before',
]
);
$this->add_group_control(
Group_Control_Box_Shadow::get_type(),
[
'name' => 'border_box_shadow',
'selector' =>
'{{WRAPPER}} .thinkai-btn',
'separator' => 'before',
]
);
$this->add_control(
'btn_border_radius',
[
'label' => esc_html__('Border Radius', 'thinkai'),
'type' => Controls_Manager::DIMENSIONS,
'separator' => 'before',
'size_units' => ['px'],
'selectors' => [
'{{WRAPPER}} .thinkai-btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'btn_title_typography',
'label' => __('Button Text Typography', 'thinkai'),
'selector' =>
'{{WRAPPER}} .thinkai-btn',
'separator' => 'before',
]
);
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'btn_title_bg_color',
'label' => __( 'Button Background Color', 'thinkai' ),
'types' => [ 'classic', 'gradient' ],
'selector' =>
'{{WRAPPER}} .thinkai-btn:before,
{{WRAPPER}} .thinkai-btn',
]
);
$this->add_control(
'btn_title_color',
[
'label' => __('Button Text Color', 'thinkai'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .thinkai-btn' => 'color: {{VALUE}}!important',
'{{WRAPPER}} .thinkai-btn span' => 'color: {{VALUE}}!important',
],
'separator' => 'before',
]
);
$this->end_controls_tab();
$this->start_controls_tab(
'thinkai_tab_btn_hover',
[
'label' => __( 'Hover', 'thinkai' ),
]
);
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'btn_hover_bg_bgtype',
'label' => __( 'Button Hover Background', 'thinkai' ),
'types' => [ 'classic', 'gradient' ],
'selector' =>
'{{WRAPPER}} .thinkai-btn:hover:before,
{{WRAPPER}} .thinkai-btn:hover',
]
);
$this->add_control(
'btn_border_color',
[
'label' => __('Button Border Color', 'thinkai'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .thinkai-btn:hover' => 'border-color: {{VALUE}}!important',
],
'separator' => 'before',
]
);
$this->add_control(
'btn_title_hover_color',
[
'label' => __('Button Text Hover Color', 'thinkai'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .thinkai-btn:hover' => 'color: {{VALUE}} !important',
'{{WRAPPER}} .thinkai-btn:hover span' => 'color: {{VALUE}} !important',
],
'separator' => 'before',
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->end_controls_section();
}
/**
* Render button 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();
$allowed_tags = wp_kses_allowed_html('post');
$btn_style = $settings[ 'btn_style' ];
$page = $settings['link_option'];
$page_select = $settings[ 'page_select' ];
$ext_url = $settings[ 'link' ];
if( $page == 'page' ){
$mount_link = get_page_link( $page_select );
}else{
$mount_link = $ext_url['url'];
$target = $ext_url['is_external'] ? ' target="_blank"' : '';
$nofollow = $ext_url['nofollow'] ? ' rel="nofollow"' : '';
}
?>
<?php if($btn_style == '4'): ?>
<div class="ai-voices-style1__top p-0 m-0">
<div class="btn-box yt-btn">
<a class="btn-one thinkai-btn" href="<?php echo esc_url( $mount_link );?>" <?php if( $page == 'extranal' ) echo esc_attr( $target );?> <?php if( $page == 'extranal' ) echo esc_attr( $nofollow );?>>
<span class="txt"><?php echo wp_kses($settings['btn_title'], true);?></span>
</a>
</div>
</div>
<?php elseif($btn_style == '3'): ?>
<div class="about-style3__right-content thinkai-br p-0 m-0">
<div class="btn-box yt-btn p-0 m-0">
<a href="<?php echo esc_url( $mount_link );?>" <?php if( $page == 'extranal' ) echo esc_attr( $target );?> <?php if( $page == 'extranal' ) echo esc_attr( $nofollow );?> class="thinkai-btn"><span class="icon-right-arrow1"></span> <?php echo wp_kses($settings['btn_title'], true);?></a>
</div>
</div>
<?php elseif($btn_style == '2'): ?>
<div class="project-style1__btn-box yt-btn">
<a class="btn-one thinkai-btn" href="<?php echo esc_url( $mount_link );?>" <?php if( $page == 'extranal' ) echo esc_attr( $target );?> <?php if( $page == 'extranal' ) echo esc_attr( $nofollow );?>>
<span class="txt"><?php echo wp_kses($settings['btn_title'], true);?></span>
</a>
</div>
<?php else: ?>
<div class="yt-btn about-style1__content-box-inner">
<div class="btn-box p-0 m-0">
<a class="thinkai-btn" href="<?php echo esc_url( $mount_link );?>" <?php if( $page == 'extranal' ) echo esc_attr( $target );?> <?php if( $page == 'extranal' ) echo esc_attr( $nofollow );?>><span class="icon-right-arrow1"></span> <?php echo wp_kses($settings['btn_title'], true);?></a>
</div>
</div>
<?php endif;
}
}