PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.1.16
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.1.16
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / modules / fanel-list / module.php

module.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.1.16, at modules/fanel-list/module.php

195 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\FanelList;
3 use UltimatePostKit\Traits\Global_Widget_Functions;
4
5 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
6 use UltimatePostKit\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Module extends Ultimate_Post_Kit_Module_Base {
11
12 use Global_Widget_Functions;
13
14 public function __construct() {
15 parent::__construct();
16
17 add_action( 'wp_ajax_nopriv_upk_fanel_list_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_fanel_list_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'fanel-list';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Fanel_List',
29 ];
30
31 return $widgets;
32 }
33
34 public function callback_ajax_loadmore_posts() {
35
36 $settings = [];
37
38 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
39 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
40 }
41
42 $settings = array_merge(
43 [
44 'posts_source' => 'post',
45 'posts_orderby' => 'date',
46 'posts_order' => 'DESC',
47 'posts_ignore_sticky_posts' => 'no',
48 'posts_only_with_featured_image' => 'no',
49 'posts_select_date' => '',
50 'posts_exclude_by' => [],
51 'posts_include_by' => [],
52 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
53 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
54 ],
55 $settings
56 );
57
58 $ajaxposts = $this->query_args( $settings );
59
60 ob_start();
61 $found_posts = false;
62
63 if ( $ajaxposts->have_posts() ) {
64 $placeholder = \Elementor\Utils::get_placeholder_image_src();
65
66 while ( $ajaxposts->have_posts() ) {
67 $ajaxposts->the_post();
68 $found_posts = true;
69
70 $title = get_the_title();
71 $post_link = esc_url( get_permalink() );
72 $post_id = get_the_ID();
73
74 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), $settings['primary_thumbnail_size'] ?? 'medium' );
75 $image_src = $image_src ? $image_src[0] : $placeholder;
76
77 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
78
79 $onclick = '';
80 if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) {
81 $onclick = 'onclick="window.open(\'' . esc_url( $post_link ) . '\', \'_self\')"';
82 }
83
84 $list_box_class = 'upk-content';
85 if ( $settings['show_readmore'] === 'yes' ) {
86 $list_box_class = 'upk-content upk-readmore--yes';
87 }
88
89 ?>
90 <div <?php echo $onclick; ?> class="upk-item">
91 <div class="upk-item-box">
92 <div class="upk-image-wrap">
93 <a href="<?php echo esc_url( $post_link ); ?>">
94 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
95 </a>
96
97 <?php if ( $settings['show_date'] === 'yes' ) : ?>
98 <div class="upk-fanel-date-wrap">
99 <span class="upk-fanel-date"><?php echo get_the_date('d'); ?></span>
100 <span class="upk-fanel-month"><?php echo get_the_date('M'); ?></span>
101 </div>
102 <?php endif; ?>
103 </div>
104
105 <div class="<?php echo esc_attr( $list_box_class ); ?>">
106 <?php if ( $settings['show_category'] === 'yes' ) : ?>
107 <div class="upk-category">
108 <?php
109 $categories = get_the_category();
110 if ( ! empty( $categories ) ) {
111 foreach ( $categories as $category ) {
112 echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
113 }
114 }
115 ?>
116 </div>
117 <?php endif; ?>
118
119 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
120 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
121 <a
122 href="<?php echo esc_url($post_link); ?>"
123 title="<?php echo esc_attr( $title ); ?>"
124 class="title-animation-<?php echo esc_attr( $settings['title_style'] ?? '' ); ?>"
125 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : '' ?>
126 >
127 <?php echo esc_html( $title ); ?>
128 </a>
129 </<?php echo esc_attr( $title_tag ); ?>>
130 <?php endif; ?>
131
132 <?php if ( $settings['show_excerpt'] === 'yes' ) : ?>
133 <div class="upk-text">
134 <?php
135 if ( has_excerpt() ) {
136 the_excerpt();
137 } else {
138 echo wp_trim_words( get_the_content(), $settings['excerpt_length'] ?? 15 );
139 }
140 ?>
141 </div>
142 <?php endif; ?>
143
144 <?php if ( $settings['show_author'] === 'yes' || $settings['show_comments'] === 'yes' || $settings['show_reading_time'] === 'yes' ) : ?>
145 <div class="upk-fanel-meta">
146 <?php if ( $settings['show_author'] === 'yes' ) : ?>
147 <div class="upk-author-name-wrap">
148 <span class="upk-by"><?php echo esc_html_x( 'by', 'Frontend', 'ultimate-post-kit' ); ?></span>
149 <a class="upk-author-name" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
150 <?php echo esc_html( get_the_author() ); ?>
151 </a>
152 </div>
153 <?php endif; ?>
154
155 <?php if ( $settings['show_comments'] === 'yes' ) : ?>
156 <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>">
157 <div class="upk-fanel-comments">
158 <?php echo esc_html( $this->upk_get_formatted_comments_count( $post_id ) ); ?>
159 </div>
160 </div>
161 <?php endif; ?>
162
163 <?php if ( _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes' ) : ?>
164 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>">
165 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
166 </div>
167 <?php endif; ?>
168 </div>
169 <?php endif; ?>
170 </div>
171
172 <?php if ( $settings['show_readmore'] === 'yes' ) : ?>
173 <a class="upk-fanel-read-more" href="<?php echo esc_url( $post_link ); ?>">
174 <i class="upk-icon-arrow-right-7" aria-hidden="true"></i>
175 </a>
176 <?php endif; ?>
177 </div>
178 </div>
179 <?php
180 }
181 }
182
183 wp_reset_postdata();
184 $markup = ob_get_clean();
185
186 wp_send_json(
187 [
188 'success' => $found_posts,
189 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
190 ]
191 );
192
193 }
194 }
195