File: /home/parhudrw/roflma.it/wp-content/plugins/lesya-plugin/elementor/widgets/portfolio.php
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Lesya Portfolio Widget.
*
* @since 1.0
*/
class Lesya_Portfolio_Widget extends Widget_Base {
public function get_name() {
return 'lesya-portfolio';
}
public function get_title() {
return esc_html__( 'Portfolio', '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(
'filters_tab',
[
'label' => esc_html__( 'Filters', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'filters_note',
[
'type' => \Elementor\Controls_Manager::RAW_HTML,
'raw' => esc_html__( 'Filters show only with pagination "Infinite Scrolling", "Button" or "No"', 'lesya-plugin' ),
'content_classes' => 'elementor-descriptor',
]
);
$this->add_control(
'filters',
[
'label' => esc_html__( 'Show Filters', 'lesya-plugin' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => __( 'Show', 'lesya-plugin' ),
'label_off' => __( 'Hide', 'lesya-plugin' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$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_portfolio_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-4',
'options' => [
'columns-2' => __( 'Columns 2', 'lesya-plugin' ),
'columns-3' => __( 'Columns 3', 'lesya-plugin' ),
'columns-4' => __( 'Columns 4', 'lesya-plugin' ),
],
]
);
$this->add_control(
'portfolio-variant',
[
'label' => esc_html__( 'Portfolio Type', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'grid',
'options' => [
'grid' => __( 'Grid', 'lesya-plugin' ),
'masonry' => __( 'Masonry', '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_subtitle',
[
'label' => esc_html__( 'Show Subtitle?', '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 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(
'filters_styling',
[
'label' => esc_html__( 'Filters', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'filters_color',
[
'label' => esc_html__( 'Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-filter li' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'filters_bgcolor',
[
'label' => esc_html__( 'BG Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-filter li' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'filters_active_color',
[
'label' => esc_html__( 'Active Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-filter li:hover, {{WRAPPER}} .portfolio-filter li.current' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'filters_active_bgcolor',
[
'label' => esc_html__( 'Active BG Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-filter li:hover, {{WRAPPER}} .portfolio-filter li.current' => 'background-color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'filters_typography',
'selector' => '{{WRAPPER}} .portfolio-filter li',
]
);
$this->end_controls_section();
$this->start_controls_section(
'items_styling',
[
'label' => esc_html__( 'Items Styling', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'item_title_color',
[
'label' => esc_html__( 'Title Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-item .portfolio-content h6' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'item_title_bgcolor',
[
'label' => esc_html__( 'Title BG Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-item .portfolio-content h6' => 'background-color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_title_typography',
'label' => esc_html__( 'Title Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .portfolio-item .portfolio-content h6',
]
);
$this->add_control(
'item_subtitle_color',
[
'label' => esc_html__( 'Subtitle Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-item .portfolio-content b' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'item_subtitle_bgcolor',
[
'label' => esc_html__( 'Subtitle BG Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .portfolio-item .portfolio-content b' => 'background-color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_subtitle_typography',
'label' => esc_html__( 'Subtitle Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .portfolio-item .portfolio-content b',
]
);
$this->end_controls_section();
}
/**
* Render Categories List.
*
* @since 1.0
*/
protected function get_portfolio_categories() {
$categories = [];
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'DESC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'portfolio_categories',
'pad_counts' => false
);
$portfolio_categories = get_categories( $args );
foreach ( $portfolio_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( 'description', 'advanced' );
$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' => 'portfolio_categories',
'pad_counts' => false,
'include' => $cat_ids
);
$pf_categories = get_categories( $cat_args );
$args = array(
'post_type' => 'portfolio',
'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' => 'portfolio_categories',
'field' => 'id',
'terms' => $cat_ids
)
);
$args += array('tax_query' => $tax_array);
}
$q = new \WP_Query( $args );
$temp = 'portfolio';
$item_classes = '';
if ( $settings['show_title'] == 'no' ) :
$item_classes .= ' hide_title';
endif;
if ( $settings['show_subtitle'] == 'no' ) :
$item_classes .= ' hide_subtitle';
endif;
if ( $settings['show_title'] == 'no' && $settings['show_category'] == 'no' ) :
$item_classes .= ' hide_description';
endif;
?>
<!-- Portfolio Section Start -->
<section class="portfolio-section pt-140 rpt-90 pb-120 rpb-80">
<div class="container-fluid">
<?php if ( $settings['bg_text'] || $settings['subtitle'] || $settings['title'] ) : ?>
<div class="section-title text-center mb-45">
<?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>
<?php endif; ?>
<?php if ( $settings['filters'] && $pf_categories && $settings['pagination'] != 'pages' ) : ?>
<ul class="portfolio-filter mb-55">
<li data-filter="*" class="current"><?php echo esc_html__( 'Show All', 'lesya-plugin' ); ?></li>
<?php foreach ( $pf_categories as $category ) : ?>
<li data-filter=".sorting-<?php echo esc_attr( $category->slug ); ?>"><?php echo esc_html( $category->name ); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if ( $q->have_posts() ) : ?>
<div class="row portfolio-active <?php echo esc_html( $item_classes ); ?>">
<?php while ( $q->have_posts() ) : $q->the_post();
set_query_var( 'layout', $settings['layout'] );
set_query_var( 'portfolio-variant', $settings['portfolio-variant'] );
get_template_part( 'template-parts/content', $temp );
endwhile; ?>
</div>
<?php if ( $settings['pagination'] == 'pages' ) : ?>
<!-- pagination -->
<nav>
<ul class="pagination flex-wrap justify-content-center wow fadeInUp delay-0-8s">
<?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' => wp_kses_post( '<i class="fas fa-arrow-left"></i>', 'lesya-plugin' ),
'next_text' => wp_kses_post( '<i class="fas fa-arrow-right"></i>', 'lesya-plugin' ),
) );
?>
</ul>
</nav>
<?php endif; ?>
<?php else :
get_template_part( 'template-parts/content', 'none' );
endif; wp_reset_postdata(); ?>
</div>
</section>
<!-- Portfolio Section End -->
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Lesya_Portfolio_Widget() );