File: /home/parhudrw/roflma.it/wp-content/plugins/lesya-plugin/elementor/widgets/portfolio-module.php
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Lesya Portfolio Module Widget.
*
* @since 1.0
*/
class Lesya_Portfolio_Module_Widget extends Widget_Base {
public function get_name() {
return 'lesya-portfolio-module';
}
public function get_title() {
return esc_html__( 'Portfolio (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(
'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' => 'custom',
'options' => [
'custom' => __( 'Custom', 'lesya-plugin' ),
],
]
);
$this->add_control(
'source_custom',
[
'label' => esc_html__( 'Custom Menu Items', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT2,
'label_block' => true,
'multiple' => true,
'options' => $this->get_portfolio_items_custom(),
'condition' => [
'source' => 'custom'
],
]
);
$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(
'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->end_controls_section();
$this->start_controls_section(
'buttons_tab',
[
'label' => esc_html__( 'Buttons', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'button',
[
'label' => esc_html__( 'Button (text)', 'lesya-plugin' ),
'label_block' => true,
'type' => Controls_Manager::TEXT,
'placeholder' => esc_html__( 'Enter text', 'lesya-plugin' ),
]
);
$this->add_control(
'link',
[
'label' => esc_html__( 'Button (link)', 'lesya-plugin' ),
'type' => Controls_Manager::URL,
'show_external' => true,
]
);
$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}} .project-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}} .project-content > h5',
]
);
$this->add_control(
'item_title_bgcolor',
[
'label' => esc_html__( 'Title BG Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .project-content' => 'background-color: {{VALUE}};',
],
]
);
$this->end_controls_section();
}
/**
* Render Portfolio List.
*
* @since 1.0
*/
protected function get_portfolio_items_custom() {
$items = [];
$args = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'posts_per_page' => -1
);
$menu_items = new \WP_Query( $args );
while ( $menu_items->have_posts() ) : $menu_items->the_post();
$items[get_the_ID()] = get_the_title();
endwhile; wp_reset_postdata();
return $items;
}
/**
* Render widget output on the frontend.
*
* @since 1.0
*/
protected function render() {
$settings = $this->get_settings_for_display();
$this->add_inline_editing_attributes( 'button', 'none' );
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$page_id = get_the_ID();
if ( $settings['source'] == 'all' ) {
$cat_ids = '';
} else {
$ids = $settings['source_custom'];
}
$args = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'orderby' => $settings['sort'],
'order' => $settings['order'],
'posts_per_page' => 6,
'paged' => $paged
);
if( $settings['source'] == 'custom' ) {
$args += array( 'post__in' => $ids );
}
$q = new \WP_Query( $args );
$temp = 'portfolio-module';
$item_classes = '';
if ( $settings['show_title'] == 'no' ) :
$item_classes .= ' hide_title';
endif;
?>
<!-- Project Section Start -->
<section class="project-section pb-150 rpb-100">
<div class="container">
<div class="row align-items-end project-active <?php echo esc_html( $item_classes ); ?>">
<?php if ( $q->have_posts() ) : ?>
<?php $i=0; while ( $q->have_posts() ) : $q->the_post(); $i++;
set_query_var( 'index', $i );
get_template_part( 'template-parts/content', $temp );
endwhile; ?>
<?php endif; ?>
<?php if ( $settings['button'] ) : ?>
<div class="item col-lg-12">
<div class="project-btn text-center">
<a<?php if ( $settings['link'] ) : ?><?php if ( $settings['link']['is_external'] ) : ?> target="_blank"<?php endif; ?><?php if ( $settings['link']['nofollow'] ) : ?> rel="nofollow"<?php endif; ?> href="<?php echo esc_url( $settings['link']['url'] ); ?>"<?php endif; ?> class="theme-btn">
<span <?php echo $this->get_render_attribute_string( 'button' ); ?>>
<?php echo esc_html( $settings['button'] ); ?>
</span>
<i class="fas fa-long-arrow-alt-right"></i>
</a>
</div>
</div>
<?php endif; ?>
</div>
</div>
</section>
<!-- Project Section End -->
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Lesya_Portfolio_Module_Widget() );