HEX
Server: LiteSpeed
System: Linux dune179.sitesanctuary.org 5.14.0-427.40.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 16 07:08:17 EDT 2024 x86_64
User: h278792 (1197)
PHP: 8.1.29
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/h278792/public_html/wp-content/plugins/ecademy-toolkit/widgets/blog-posts.php
<?php
/**
 * Posts Widget
 */

namespace Elementor;

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class eCademy_Posts extends Widget_Base {

	public function get_name() {
        return 'eCademy_Posts';
    }

	public function get_title() {
        return __( 'پست ها', 'ecademy-toolkit' );
    }

	public function get_icon() {
        return 'eicon-post-slider';
    }

	public function get_categories() {
        return [ 'ecademy-elements' ];
	}
	protected function register_controls() {

        $this->start_controls_section(
			'eCademy_Posts',
			[
				'label' => __( 'eCademy پست های', 'ecademy-toolkit' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
        );

            $this->add_control(
                'style',
                [
                    'label' => __( 'سبک', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::SELECT,
                    'options' => [
                        '1'         => __( 'سبک 1', 'ecademy-toolkit' ),
                        '2'         => __( 'سبک', 'ecademy-toolkit' ),
                        '3'         => __( '  سبک 3', 'ecademy-toolkit' ),
                        '4'         => __( '  سبک 4', 'ecademy-toolkit' ),
                    ],
                    'default' => '1',
                ]
            );

            $this->add_control(
                'cat_name', [
                    'label' => esc_html__( 'دسته بندی', 'ecademy-toolkit' ),
                    'description' => esc_html__( 'دسته راب را وارد کنید که با کاما از هم جدا شده اند (Eg. cat1, cat2)', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::TEXT,
                    'label_block' => true,
                ]
            );

            $this->add_control(
                'order',
                [
                    'label' => __( 'ارسال ها به ترتیب', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::SELECT,
                    'options' => [
                        'DESC'      => __( 'DESC', 'ecademy-toolkit' ),
                        'ASC'       => __( 'ASC', 'ecademy-toolkit' ),
                    ],
                    'default' => 'DESC',
                ]
            );

            $this->add_control(
                'count',
                [
                    'label' => __( 'آیتم', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::NUMBER,
                    'default' => 3,
                ]
            );

            $this->add_control(
                'bottom_title',
                [
                    'label' => __( 'متن دکمه', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::TEXT,
                    'default' => __('اکنون وارد جزئیات شوید؟', 'ecademy-toolkit'),
                ]
            );
            $this->add_control(
                'bottom_link_title',
                [
                    'label' => __( 'عنوان لینک پایین', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::TEXT,
                    'default' => __('نمایش تمام پست ها', 'ecademy-toolkit'),
                ]
            );

            $this->add_control(
                'link_type',
                [
                    'label' 		=> esc_html__( ' نوع پیوند ', 'ecademy-toolkit' ),
                    'type' 			=> Controls_Manager::SELECT,
                    'label_block' 	=> true,
                    'options' => [
                        '1'  	=> esc_html__( 'پیوند به صفحه', 'ecademy-toolkit' ),
                        '2' 	=> esc_html__( 'لینک خارجی', 'ecademy-toolkit' ),
                    ],
                ]
            );

            $this->add_control(
                'link_to_page',
                [
                    'label' 		=> esc_html__( 'پیوند صفحه  ', 'ecademy-toolkit' ),
                    'type' 			=> Controls_Manager::SELECT,
                    'label_block' 	=> true,
                    'options' 		=> ecademy_toolkit_get_page_as_list(),
                    'condition' => [
                        'link_type' => '1',
                    ]
                ]
            );

            $this->add_control(
                'ex_link',
                [
                    'label'		=> esc_html__('لینک خارجی', 'ecademy-toolkit'),
                    'type'		=> Controls_Manager:: TEXT,
                    'condition' => [
                        'link_type' => '2',
                    ]
                ]
            );


        $this->end_controls_section();

        $this->start_controls_section(
			'blog_style',
			[
				'label' => __( 'کنترل های رنگ', 'ecademy-toolkit' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
        );

            $this->add_control(
                'tag_color',
                [
                    'label' => esc_html__( 'رنگ برچسب', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .single-blog-post .post-content .category, .single-blog-post-item .post-content .category, .single-blog-item .post-content .category' => 'color: {{VALUE}}',
                    ],
                ]
            );
            $this->add_control(
                'tag_color_hover',
                [
                    'label' => esc_html__( 'رنگ شناور برچسب', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .single-blog-post .post-content .category:hover, .single-blog-post-item .post-content .category:hover:hover, .single-blog-item .post-content .category' => 'color: {{VALUE}}',
                    ],
                ]
            );

            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'name' => 'tag_typography',
                    'label' => __( 'تایپوگرافی برچسب', 'ecademy-toolkit' ),
                    'scheme' => Core\Schemes\Typography::TYPOGRAPHY_1,
                    'selector' => '{{WRAPPER}} .single-blog-post .post-content .category, .single-blog-post-item .post-content .category, .single-blog-item .post-content .category',
                ]
            );
            $this->add_control(
                'title_color',
                [
                    'label' => esc_html__( 'رنگ عنوان', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .single-blog-post .post-content h3 a, .single-blog-post-item .post-content h3 a, .single-blog-post-box .post-content h3 a, .single-blog-item .post-content h3 a' => 'color: {{VALUE}}',
                    ],
                ]
            );
            $this->add_control(
                'title_color_hover',
                [
                    'label' => esc_html__( 'عنوان رنگ شناور', 'ecademy-toolkit' ),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .single-blog-post .post-content h3 a:hover, .single-blog-post-item .post-content h3 a:hover, .single-blog-post-box .post-content h3 a:hover, .single-blog-item .post-content h3 a:hover' => 'color: {{VALUE}}',
                    ],
                ]
            );

            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'name' => 'title_typography',
                    'label' => __( ' عنوان تایپوگرافی', 'ecademy-toolkit' ),
                    'scheme' => Core\Schemes\Typography::TYPOGRAPHY_1,
                    'selector' => '{{WRAPPER}} .single-blog-post .post-content h3 a, .single-blog-post-item .post-content h3 a, .single-blog-post-box .post-content h3, .single-blog-item .post-content h3',
                ]
            );

        $this->end_controls_section();

    }

	protected function render() {

        $settings = $this->get_settings_for_display();

        global $ecademy_opt;
		if( isset( $ecademy_opt['enable_lazyloader'] ) ):
			$is_lazyloader = $ecademy_opt['enable_lazyloader'];
		else:
			$is_lazyloader = true;
		endif;

         // Post Query
         if( $settings['cat_name'] != '' ) {
            $args = array(
                'post_type'     => 'post',
                'posts_per_page'=> $settings['count'],
                'order'         => $settings['order'],
                'tax_query'     => array(
                    array(
                        'taxonomy'      => 'category',
                        'field'         => 'slug',
                        'terms'         => $settings['cat_name'],
                        'hide_empty'    => false
                    )
                )
            );
        } else {
            $args = array(
                'post_type'         => 'post',
                'posts_per_page'    => $settings['count'],
                'order'             => $settings['order'],
                'meta_key'          => '_thumbnail_id',
            );
        }
        $post_array = new \WP_Query( $args );

        // Get Button Link
        if($settings['link_type'] == 1){
            $link = get_page_link( $settings['link_to_page'] );
        } else {
            $link = $settings['ex_link'];
        }
		?>
            <?php if( $settings['style'] == '1' ): ?>
                <div class="container">
                    <div class="row">
                        <?php while($post_array->have_posts()): $post_array->the_post(); ?>
                            <div class="col-lg-4 col-md-6">
                                <div class="single-blog-post">
                                    <div class="post-image">
                                        <a href="<?php the_permalink(); ?>" class="d-block">
                                            <?php if( $is_lazyloader == true ): ?>
                                                <img sm-src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                            <?php else: ?>
                                                <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                            <?php endif; ?>
                                        </a>
                                    </div>
                                    <div class="post-content">
                                        <?php
                                        $posttags = get_the_tags();
                                        $count = 0; $sep = '';
                                        if ( $posttags ) {
                                            foreach( $posttags as $tag ) {
                                                $count++;
                                                echo '<a class="category" href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
                                                if( $count > 0 ) break;
                                            }
                                        }
                                        ?>
                                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                        <ul class="post-content-footer d-flex justify-content-between align-items-center">
                                            <li>
                                                <?php
                                                    $user       = get_the_author_meta('ID');
                                                    $user_image = get_avatar_url($user, ['size' => '51']);
                                                ?>
                                                <div class="post-author d-flex align-items-center">
                                                    <?php if( $is_lazyloader == true ): ?>
                                                        <img sm-src="<?php echo esc_url( $user_image ); ?>" class="rounded-circle" alt="<?php echo esc_attr( get_the_author() ); ?>">
                                                    <?php else: ?>
                                                        <img src="<?php echo esc_url( $user_image ); ?>" class="rounded-circle" alt="<?php echo esc_attr( get_the_author() ); ?>">
                                                    <?php endif; ?>
                                                    <span><?php echo esc_html( get_the_author() ); ?></span>
                                                </div>
                                            </li>
                                            <li>
                                                <i class='flaticon-calendar'></i> <?php echo get_the_date( 'Y-m-d' ); ?>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile; ?>
                        <?php wp_reset_postdata(); ?>
                    </div>
                </div>
            <?php elseif( $settings['style'] == '2' ): ?>
                <div class="container">
                    <div class="row">
                        <?php $i = 0; while($post_array->have_posts()): $post_array->the_post(); ?>
                            <?php if( $i == 0 ): ?>
                                <div class="col-lg-8 col-md-12">
                                    <div class="single-blog-post-item">
                                        <div class="post-image">
                                            <a href="<?php the_permalink(); ?>" class="d-block">
                                                <?php if( $is_lazyloader == true ): ?>
                                                    <img sm-src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_810x545' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                                <?php else: ?>
                                                    <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_810x545' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                                <?php endif; ?>
                                            </a>
                                        </div>
                                        <div class="post-content">
                                            <?php
                                                $posttags = get_the_tags();
                                                $count = 0; $sep = '';
                                                if ( $posttags ) {
                                                    foreach( $posttags as $tag ) {
                                                        $count++;
                                                        echo '<a class="category" href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
                                                        if( $count > 0 ) break;
                                                    }
                                                }
                                                ?>
                                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                            <p><?php the_excerpt(); ?></p>
                                            <ul class="post-content-footer d-flex align-items-center">
                                                <li>
                                                    <?php
                                                        $user       = get_the_author_meta('ID');
                                                        $user_image = get_avatar_url($user, ['size' => '51']);
                                                    ?>
                                                    <div class="post-author d-flex align-items-center">
                                                        <?php if( $is_lazyloader == true ): ?>
                                                            <img sm-src="<?php echo esc_url( $user_image ); ?>" class="rounded-circle" alt="<?php echo esc_attr( get_the_author() ); ?>">
                                                        <?php else: ?>
                                                            <img src="<?php echo esc_url( $user_image ); ?>" class="rounded-circle" alt="<?php echo esc_attr( get_the_author() ); ?>">
                                                        <?php endif; ?>
                                                        <span><?php echo esc_html( get_the_author() ); ?></span>
                                                    </div>
                                                </li>
                                                <li>
                                                    <i class='flaticon-calendar'></i> <?php echo get_the_date( 'Y-m-d' ); ?>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            <?php endif; ?>
                        <?php $i++; endwhile; ?>
                        <?php wp_reset_postdata(); ?>

                        <div class="col-lg-4 col-md-12">
                            <div class="blog-post-list">
                                <div class="row">
                                    <?php $count = 0; while($post_array->have_posts()): $post_array->the_post();  ?>
                                        <?php if( $count != 0 ): ?>
                                            <div class="col-lg-12 col-sm-6 col-md-6">
                                                <div class="single-blog-post-item">
                                                    <div class="post-image">
                                                        <a href="<?php the_permalink(); ?>" class="d-block">
                                                            <?php if( $is_lazyloader == true ): ?>
                                                                <img sm-src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                                            <?php else: ?>
                                                                <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                                            <?php endif; ?>
                                                        </a>
                                                    </div>
                                                    <div class="post-content">
                                                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endif; ?>
                                    <?php $count++; endwhile; ?>
                                    <?php wp_reset_postdata(); ?>
                                </div>
                            </div>
                        </div>

                        <?php if( $settings['bottom_title'] != '' || $settings['bottom_link_title'] != '' ): ?>
                            <div class="col-lg-12 col-md-12">
                                <div class="blog-post-info">
                                    <p><?php echo esc_html( $settings['bottom_title'] ); ?>​ <a href="<?php echo esc_url( $link ); ?>"><?php echo esc_html( $settings['bottom_link_title'] ); ?></a></p>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            <?php elseif( $settings['style'] == '3' ): ?>
                <div class="container">
                <?php if( $settings['count'] == 1 ): ?>
                    <div class="col-lg-6 offset-lg-3">
                <?php else: ?>
                    <div class="blog-slides owl-carousel owl-theme">
                <?php endif; ?>
                        <?php while($post_array->have_posts()): $post_array->the_post(); ?>
                            <div class="single-blog-post-box">
                                <div class="post-image">
                                    <a href="<?php the_permalink(); ?>" class="d-block">
                                        <?php if( $is_lazyloader == true ): ?>
                                            <img sm-src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                        <?php else: ?>
                                            <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                        <?php endif; ?>
                                    </a>
                                </div>

                                <div class="post-content">
                                    <?php
                                    $posttags = get_the_tags();
                                    $count = 0; $sep = '';
                                    if ( $posttags ) {
                                        foreach( $posttags as $tag ) {
                                            $count++;
                                            echo '<a class="category" href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
                                            if( $count > 0 ) break;
                                        }
                                    }
                                    ?>
                                    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                    <ul class="post-content-footer d-flex justify-content-between align-items-center">
                                        <li>
                                            <?php
                                                $user       = get_the_author_meta('ID');
                                                $user_image = get_avatar_url($user, ['size' => '51']);
                                            ?>
                                            <div class="post-author d-flex align-items-center">
                                                <?php if( $is_lazyloader == true ): ?>
                                                    <img sm-src="<?php echo esc_url( $user_image ); ?>" class="rounded-circle" alt="<?php echo esc_attr( get_the_author() ); ?>">
                                                <?php else: ?>
                                                    <img src="<?php echo esc_url( $user_image ); ?>" class="rounded-circle" alt="<?php echo esc_attr( get_the_author() ); ?>">
                                                <?php endif; ?>
                                                <span><?php echo esc_html( get_the_author() ); ?></span>
                                            </div>
                                        </li>
                                        <li>
                                            <i class='flaticon-calendar'></i> <?php echo get_the_date( 'Y-m-d' ); ?>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        <?php endwhile; ?>
                        <?php wp_reset_postdata(); ?>
                    </div>
                    <?php if( $settings['bottom_title'] != '' || $settings['bottom_link_title'] != '' ): ?>
                        <div class="blog-post-info">
                            <p><?php echo esc_html( $settings['bottom_title'] ); ?>​ <a href="<?php echo esc_url( $link ); ?>"><?php echo esc_html( $settings['bottom_link_title'] ); ?></a></p>
                        </div>
                    <?php endif; ?>
                </div>
            <?php elseif( $settings['style'] == '4' ): ?>
                <div class="container">
                    <div class="row">
                        <?php while($post_array->have_posts()): $post_array->the_post(); ?>
                            <div class="col-lg-4 col-md-6 col-sm-6">
                                <div class="single-blog-item">
                                    <div class="post-image">
                                        <a href="<?php the_permalink(); ?>" class="d-block">
                                            <?php if( $is_lazyloader == true ): ?>
                                                <img sm-src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                            <?php else: ?>
                                                <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'ecademy_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption();  ?>">
                                            <?php endif; ?>
                                        </a>

                                        <a href="<?php the_permalink(); ?>" class="link-btn"></a>
                                    </div>

                                    <div class="post-content">
                                        <?php
                                            $posttags = get_the_tags();
                                            $count = 0; $sep = '';
                                            if ( $posttags ) {
                                                foreach( $posttags as $tag ) {
                                                    $count++;
                                                    echo '<a class="category" href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
                                                    if( $count > 0 ) break;
                                                }
                                            }
                                        ?>
                                        <h3 class="font-weight-black"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile; ?>
                        <?php wp_reset_postdata(); ?>
                    </div>
                </div>
            <?php endif; ?>
        <?php
	}


}

Plugin::instance()->widgets_manager->register( new eCademy_Posts );