File: //home/parhudrw/roflma.it/wp-content/plugins/lesya-plugin/elementor/widgets/blog-module.php
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Lesya Blog Module Widget.
*
* @since 1.0
*/
class Lesya_Blog_Module_Widget extends Widget_Base {
public function get_name() {
return 'lesya-blog-module';
}
public function get_title() {
return esc_html__( 'Blog Module', '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(
'content_tab',
[
'label' => esc_html__( 'Content', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$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_text',
[
'label' => esc_html__( 'Background Title', 'lesya-plugin' ),
'label_block' => true,
'type' => Controls_Manager::TEXT,
'placeholder' => esc_html__( 'Enter title', 'lesya-plugin' ),
'default' => esc_html__( 'Title', 'lesya-plugin' ),
]
);
$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_blog_categories(),
'condition' => [
'source' => 'categories'
],
]
);
$this->add_control(
'limit',
[
'label' => esc_html__( 'Number of Items', 'lesya-plugin' ),
'type' => Controls_Manager::NUMBER,
'placeholder' => 6,
'default' => 6,
]
);
$this->add_control(
'sort',
[
'label' => esc_html__( 'Sorting By', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'date',
'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' => 'desc',
'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(
'columns',
[
'label' => esc_html__( 'Columns', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'columns-3',
'options' => [
'columns-1' => __( 'Columns 1', 'lesya-plugin' ),
'columns-2' => __( 'Columns 2', 'lesya-plugin' ),
'columns-3' => __( 'Columns 3', 'lesya-plugin' ),
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'content_styling',
[
'label' => esc_html__( 'Content 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 h2' => '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 h2',
]
);
$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->add_control(
'bgtext_color',
[
'label' => esc_html__( 'BG Text Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .section-title .bg-text' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'bgtext_typography',
'label' => esc_html__( 'BG Text Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .section-title .bg-text',
]
);
$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_list_color',
[
'label' => esc_html__( 'List Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .news-item .news-header ul li' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_list_typography',
'label' => esc_html__( 'List Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .news-item .news-header ul li',
]
);
$this->add_control(
'item_title_color',
[
'label' => esc_html__( 'Title Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .news-item .news-header h4 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}} .news-item .news-header h4 a',
]
);
$this->add_control(
'item_text_color',
[
'label' => esc_html__( 'Text Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .news-item .news-header p' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_text_typography',
'label' => esc_html__( 'Text Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .news-item .news-header p',
]
);
$this->end_controls_section();
}
/**
* Render Categories List.
*
* @since 1.0
*/
protected function get_blog_categories() {
$categories = [];
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'DESC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'category',
'pad_counts' => false
);
$blog_categories = get_categories( $args );
foreach ( $blog_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' );
$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' => 'category',
'pad_counts' => false,
'include' => $cat_ids
);
$bp_categories = get_categories( $cat_args );
$args = array(
'post_type' => 'post',
'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' => 'category',
'field' => 'id',
'terms' => $cat_ids
)
);
$args += array('tax_query' => $tax_array);
}
$q = new \WP_Query( $args );
?>
<!-- Blog Section Start -->
<section class="blog-section rel z-1 pt-110 rpt-60 mb-105 rmb-55">
<div class="container">
<?php if ( $settings['bg_text'] || $settings['subtitle'] || $settings['title'] ) : ?>
<div class="row justify-content-center">
<div class="col-xl-8 col-lg-9 col-md-10">
<div class="section-title text-center mb-65">
<?php if ( $settings['bg_text'] ) : ?>
<span class="bg-text">
<span <?php echo $this->get_render_attribute_string( 'bg_text' ); ?>>
<?php echo wp_kses_post( $settings['bg_text'] ); ?>
</span>
</span>
<?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'] ) : ?>
<h2>
<span <?php echo $this->get_render_attribute_string( 'title' ); ?>>
<?php echo wp_kses_post( $settings['title'] ); ?>
</span>
</h2>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if ( $q->have_posts() ) : ?>
<div class="row">
<?php $i=0; while ( $q->have_posts() ) : $q->the_post(); $i++; ?>
<div class="col-xl-4 col-md-6">
<?php
set_query_var( 'index', $i );
get_template_part( 'template-parts/content', 'module' );
?>
</div>
<?php endwhile; ?>
</div>
<?php endif; wp_reset_postdata(); ?>
</div>
</section>
<!-- Blog Section End -->
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Lesya_Blog_Module_Widget() );