File: //home/parhudrw/roflma.it/wp-content/plugins/lesya-plugin/elementor/widgets/services-grid.php
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Lesya Services Grid Widget.
*
* @since 1.0
*/
class Lesya_Services_Grid_Widget extends Widget_Base {
public function get_name() {
return 'lesya-services-grid';
}
public function get_title() {
return esc_html__( 'Services Grid', 'lesya-plugin' );
}
public function get_icon() {
return 'eicon-parallax';
}
public function get_categories() {
return [ 'lesya-category' ];
}
/**
* Register widget controls.
*
* @since 1.0
*/
protected function register_controls() {
$this->start_controls_section(
'heading_tab',
[
'label' => esc_html__( 'Heading', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'heading',
[
'label' => esc_html__( 'Heading', 'lesya-plugin' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => __( 'Show', 'lesya-plugin' ),
'label_off' => __( 'Hide', 'lesya-plugin' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'title',
[
'label' => esc_html__( 'Title', 'lesya-plugin' ),
'type' => Controls_Manager::TEXTAREA,
'placeholder' => esc_html__( 'Enter title', 'lesya-plugin' ),
'default' => esc_html__( 'Title', 'lesya-plugin' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'subtitle',
[
'label' => esc_html__( 'Subtitle', 'lesya-plugin' ),
'type' => Controls_Manager::TEXTAREA,
'placeholder' => esc_html__( 'Enter subtitle', 'lesya-plugin' ),
'default' => esc_html__( 'Subtitle', 'lesya-plugin' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'bg_image',
[
'label' => esc_html__( 'BG Image', 'lesya-plugin' ),
'type' => Controls_Manager::MEDIA,
'default' => [
'url' => \Elementor\Utils::get_placeholder_image_src(),
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'items_tab',
[
'label' => esc_html__( 'Items', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'source',
[
'label' => esc_html__( 'Source', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'all',
'options' => [
'all' => __( 'All', 'lesya-plugin' ),
'categories' => __( 'Categories', 'lesya-plugin' ),
],
]
);
$this->add_control(
'source_categories',
[
'label' => esc_html__( 'Source', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT2,
'label_block' => true,
'multiple' => true,
'options' => $this->get_services_categories(),
'condition' => [
'source' => 'categories'
],
]
);
$this->add_control(
'limit',
[
'label' => esc_html__( 'Number of Items', 'lesya-plugin' ),
'type' => Controls_Manager::NUMBER,
'placeholder' => 8,
'default' => 8,
]
);
$this->add_control(
'sort',
[
'label' => esc_html__( 'Sorting By', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'menu_order',
'options' => [
'date' => __( 'Date', 'lesya-plugin' ),
'title' => __( 'Title', 'lesya-plugin' ),
'rand' => __( 'Random', 'lesya-plugin' ),
'menu_order' => __( 'Order', 'lesya-plugin' ),
],
]
);
$this->add_control(
'order',
[
'label' => esc_html__( 'Order', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'asc',
'options' => [
'asc' => __( 'ASC', 'lesya-plugin' ),
'desc' => __( 'DESC', 'lesya-plugin' ),
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'settings_tab',
[
'label' => esc_html__( 'Settings', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'layout',
[
'label' => esc_html__( 'Layout', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'columns-3',
'options' => [
'columns-2' => __( 'Columns 2', 'lesya-plugin' ),
'columns-3' => __( 'Columns 3', 'lesya-plugin' ),
'columns-4' => __( 'Columns 4', 'lesya-plugin' ),
],
]
);
$this->add_control(
'pagination',
[
'label' => esc_html__( 'Pagination', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'no',
'options' => [
'no' => __( 'No', 'lesya-plugin' ),
'pages' => __( 'Pages', 'lesya-plugin' ),
],
]
);
$this->add_control(
'show_title',
[
'label' => esc_html__( 'Show Title?', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'yes',
'options' => [
'no' => __( 'No', 'lesya-plugin' ),
'yes' => __( 'Yes', 'lesya-plugin' ),
],
]
);
$this->add_control(
'show_button',
[
'label' => esc_html__( 'Show Button?', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'yes',
'options' => [
'no' => __( 'No', 'lesya-plugin' ),
'yes' => __( 'Yes', 'lesya-plugin' ),
],
]
);
$this->add_control(
'show_icon',
[
'label' => esc_html__( 'Show Icon?', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'yes',
'options' => [
'no' => __( 'No', 'lesya-plugin' ),
'yes' => __( 'Yes', 'lesya-plugin' ),
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'heading_styling',
[
'label' => esc_html__( 'Heading Styling', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .section-title h3' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .section-title h3',
]
);
$this->add_control(
'subtitle_color',
[
'label' => esc_html__( 'Subtitle Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .section-title .sub-title' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'subtitle_typography',
'label' => esc_html__( 'Subtitle Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .section-title .sub-title',
]
);
$this->end_controls_section();
$this->start_controls_section(
'items_styling',
[
'label' => esc_html__( 'Items', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'item_bg_color',
[
'label' => esc_html__( 'BG Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .service-item .service-content' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'item_title_color',
[
'label' => esc_html__( 'Title Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .service-item .service-content h5' => 'color: {{VALUE}};',
'{{WRAPPER}} .service-item .service-content h5 a' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_title_typography',
'label' => esc_html__( 'Title Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .service-item .service-content h5',
]
);
$this->add_control(
'item_more_color',
[
'label' => esc_html__( 'More Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .service-item .service-content .read-more' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_more_typography',
'label' => esc_html__( 'More Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .service-item .service-content .read-more',
]
);
$this->end_controls_section();
}
/**
* Render Categories List.
*
* @since 1.0
*/
protected function get_services_categories() {
$categories = [];
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'services_categories',
'pad_counts' => false
);
$services_categories = get_categories( $args );
foreach ( $services_categories as $category ) {
$categories[$category->term_id] = $category->name;
}
return $categories;
}
/**
* Render widget output on the frontend.
*
* @since 1.0
*/
protected function render() {
$settings = $this->get_settings_for_display();
$this->add_inline_editing_attributes( 'title', 'basic' );
$this->add_inline_editing_attributes( 'subtitle', 'basic' );
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$page_id = get_the_ID();
if ( $settings['source'] == 'all' ) {
$cat_ids = '';
} else {
$cat_ids = $settings['source_categories'];
}
$cat_args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'DESC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'services_categories',
'pad_counts' => false,
'include' => $cat_ids
);
$pf_categories = get_categories( $cat_args );
$args = array(
'post_type' => 'services',
'post_status' => 'publish',
'orderby' => $settings['sort'],
'order' => $settings['order'],
'posts_per_page' => $settings['limit'],
'paged' => $paged
);
if( $settings['source'] == 'categories' ) {
$tax_array = array(
array(
'taxonomy' => 'services_categories',
'field' => 'id',
'terms' => $cat_ids
)
);
$args += array('tax_query' => $tax_array);
}
$q = new \WP_Query( $args );
$temp = 'services';
$row_classes = 'col-lg-4 col-sm-6';
if ( $settings['layout'] == 'columns-2' ) :
$row_classes = 'col-lg-6 col-sm-6';
endif;
if ( $settings['layout'] == 'columns-4' ) :
$row_classes = 'col-lg-3 col-sm-6';
endif;
if ( $settings['show_title'] == 'no' ) :
$row_classes .= ' hide_title';
endif;
if ( $settings['show_button'] == 'no' ) :
$row_classes .= ' hide_button';
endif;
if ( $settings['show_icon'] == 'no' ) :
$row_classes .= ' hide_icon';
endif;
?>
<!-- Services Section Start -->
<section class="services-page pt-140 rpt-90 pb-90 rpb-40">
<div class="container">
<?php if ( $settings['heading'] == 'yes' && $settings['subtitle'] && $settings['title'] ) : ?>
<div class="row justify-content-center">
<div class="col-lg-10">
<div class="section-title text-center mb-65">
<?php if ( $settings['bg_image'] ) : $image = wp_get_attachment_image_url( $settings['bg_image']['id'], 'lesya_900xAuto' ); ?>
<img class="bg-image" src="<?php echo esc_url( $image ); ?>" alt="<?php echo esc_attr__( 'image', 'lesya-plugin' ); ?>">
<?php endif; ?>
<?php if ( $settings['subtitle'] ) : ?>
<span class="sub-title">
<span <?php echo $this->get_render_attribute_string( 'subtitle' ); ?>>
<?php echo wp_kses_post( $settings['subtitle'] ); ?>
</span>
</span>
<?php endif; ?>
<?php if ( $settings['title'] ) : ?>
<h3>
<span <?php echo $this->get_render_attribute_string( 'title' ); ?>>
<?php echo wp_kses_post( $settings['title'] ); ?>
</span>
</h3>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if ( $q->have_posts() ) : ?>
<div class="row justify-content-center">
<?php $i=0; while ( $q->have_posts() ) : $q->the_post(); $i+=2; ?>
<div class="<?php echo esc_attr( $row_classes ); ?>">
<?php
set_query_var( 'index', $i );
get_template_part( 'template-parts/content', $temp ); ?>
</div>
<?php endwhile; ?>
</div>
<?php if ( $settings['pagination'] == 'pages' ) : ?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $q->max_num_pages,
'prev_text' => esc_html__( 'Prev', 'lesya-plugin' ),
'next_text' => esc_html__( 'Next', 'lesya-plugin' ),
) );
?>
</div>
<?php endif; ?>
<?php else :
get_template_part( 'template-parts/content', 'none' );
endif; wp_reset_postdata(); ?>
</div>
</section>
<!-- Services Section End -->
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Lesya_Services_Grid_Widget() );