PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.31
Post Grid Gutenberg Blocks – PostX v5.0.31
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / blocks / Post_Slider_1.php

Post_Slider_1.php in Post Grid Gutenberg Blocks – PostX 5.0.31, at blocks/Post_Slider_1.php

344 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Post_Slider_1 {
7
8 public function __construct() {
9 add_action( 'init', array( $this, 'register' ) );
10 }
11
12 public function get_attributes() {
13
14 return array(
15 'blockId' => '',
16 'previewImg' => '',
17 // --------------------------
18 // Query Setting
19 // --------------------------
20 'queryQuick' => '',
21 'queryNumPosts' => (object) array( 'lg' => 5 ),
22 'queryNumber' => 5,
23 'queryType' => 'post',
24 'queryTax' => 'category',
25 'queryTaxValue' => '[]',
26 'queryRelation' => 'OR',
27 'queryOrderBy' => 'date',
28 'metaKey' => 'custom_meta_key',
29 'queryOrder' => 'desc',
30 // Include Remove from Version 2.5.4
31 'queryInclude' => '',
32 'queryExclude' => '[]',
33 'queryAuthor' => '[]',
34 'queryOffset' => '0',
35 'queryExcludeTerm' => '[]',
36 'queryExcludeAuthor' => '[]',
37 'querySticky' => true,
38 'queryUnique' => '',
39 'queryPosts' => '[]',
40 'queryCustomPosts' => '[]',
41 // --------------------------
42 // General Setting
43 // --------------------------
44 'slidesToShow' => (object) array(
45 'lg' => '1',
46 'sm' => '1',
47 'xs' => '1',
48 ),
49 'autoPlay' => true,
50 'height' => (object) array(
51 'lg' => '550',
52 'unit' => 'px',
53 ),
54 'slideSpeed' => '3000',
55 'sliderGap' => '10',
56 'dots' => true,
57 'arrows' => true,
58 'preLoader' => false,
59 'fade' => true,
60 'titleShow' => true,
61 'titleStyle' => 'none',
62 'headingShow' => false,
63 'excerptShow' => true,
64 'catShow' => true,
65 'metaShow' => true,
66 'readMore' => true,
67 'contentTag' => 'div',
68 'openInTab' => false,
69 'notFoundMessage' => 'No Post Found',
70
71 // --------------------------
72 // Heading Setting/Style
73 // --------------------------
74 'headingText' => 'Post Slider #1',
75 'headingURL' => '',
76 'headingBtnText' => 'View More',
77 'headingStyle' => 'style1',
78 'headingTag' => 'h2',
79 'headingAlign' => 'left',
80 'subHeadingShow' => false,
81 'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.',
82
83 // --------------------------
84 // Title Setting/Style
85 // --------------------------
86 'titleTag' => 'h3',
87 'titlePosition' => true,
88 'titleLength' => 0,
89 // 'titleBackground' => '',
90
91 // --------------------------
92 // Content Setting/Style
93 // --------------------------
94 'showSeoMeta' => false,
95 'showFullExcerpt' => false,
96 'excerptLimit' => 40,
97
98 // --------------------------
99 // Content Wrap Setting/Style
100 // --------------------------
101 'contentVerticalPosition' => 'middlePosition',
102 'contentHorizontalPosition' => 'centerPosition',
103
104 // --------------------------
105 // Arrow Setting/Style
106 // --------------------------
107 'arrowStyle' => 'leftAngle2#rightAngle2',
108
109 // --------------------------
110 // Category Setting/Style
111 // --------------------------
112 'maxTaxonomy' => '30',
113 'taxonomy' => 'category',
114 'catStyle' => 'classic',
115 'catPosition' => 'aboveTitle',
116 'customCatColor' => false,
117 'seperatorLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
118 'onlyCatColor' => false,
119
120 // --------------------------
121 // Image Style
122 // --------------------------
123 'imageShow' => true,
124 'imgCrop' => 'full',
125 'imgOverlay' => false,
126 'imgOverlayType' => 'default',
127 'fallbackEnable' => true,
128 'fallbackImg' => '',
129 'imgSrcset' => false,
130 'imgLazy' => false,
131
132 // --------------------------
133 // Read more Setting/Style
134 // --------------------------
135 'readMoreText' => '',
136 'readMoreIcon' => 'rightArrowLg',
137
138 // --------------------------
139 // Meta Setting/Style
140 // --------------------------
141 'metaPosition' => 'top',
142 'metaStyle' => 'icon',
143 'authorLink' => true,
144 'metaSeparator' => 'dash',
145 'metaList' => '["metaAuthor","metaDate","metaRead"]',
146 'metaMinText' => 'min read',
147 'metaAuthorPrefix' => 'By',
148 'metaDateFormat' => 'M j, Y',
149
150 // --------------------------
151 // Wrapper Style
152 // --------------------------
153 'advanceId' => '',
154 'advanceZindex' => '',
155 'hideExtraLarge' => false,
156 'hideTablet' => false,
157 'hideMobile' => false,
158 'advanceCss' => '',
159
160 /*
161 ============================
162 Dynamic Content
163 ============================*/
164 'dcEnabled' => false,
165 'dcFields' => array(),
166 'dcSize' => 7,
167 );
168 }
169
170 public function register() {
171 register_block_type(
172 'ultimate-post/post-slider-1',
173 array(
174 'editor_script' => 'ultp-blocks-editor-script',
175 'editor_style' => 'ultp-blocks-editor-css',
176 'render_callback' => array( $this, 'content' ),
177 )
178 );
179 }
180
181 public function content( $attr, $noAjax ) {
182 $attr = wp_parse_args( $attr, $this->get_attributes() );
183 global $unique_ID;
184
185 if ( ! $noAjax ) {
186 $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
187 $attr['paged'] = $paged ? $paged : 1;
188 }
189
190 $block_name = 'post-slider-1';
191 $wraper_before = $wraper_after = $post_loop = '';
192 $attr['queryNumber'] = ultimate_post()->get_post_number( 5, $attr['queryNumber'], $attr['queryNumPosts'] );
193 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
194 $pageNum = ultimate_post()->get_page_number( $attr, $recent_posts->found_posts );
195 // Dummy Img Url
196 $dummy_url = ULTP_URL . 'assets/img/ultp-fallback-img.png';
197
198 $slides = is_object( $attr['slidesToShow'] ) ? json_decode( wp_json_encode( $attr['slidesToShow'] ), true ) : $attr['slidesToShow'];
199
200 if ( $recent_posts->have_posts() ) {
201
202 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
203 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
204 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
205 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
206 $attr['contentTag'] = in_array( $attr['contentTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['contentTag'] : 'div';
207 $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] );
208 $attr['slideSpeed'] = sanitize_html_class( $attr['slideSpeed'] );
209 $attr['arrows'] = $attr['arrows'] == true;
210 $attr['dots'] = $attr['dots'] == true;
211 $attr['autoPlay'] = $attr['autoPlay'] == true;
212 $attr['fade'] = $attr['fade'] == true;
213 $attr['readMoreText'] = wp_kses( $attr['readMoreText'], ultimate_post()->ultp_allowed_html_tags() );
214 $attr['contentVerticalPosition'] = sanitize_html_class( $attr['contentVerticalPosition'] );
215 $attr['contentHorizontalPosition'] = sanitize_html_class( $attr['contentHorizontalPosition'] );
216
217 $wraper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '' . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '">';
218 $wraper_before .= '<div class="ultp-block-wrapper">';
219 if ( $attr['headingShow'] ) {
220 $wraper_before .= '<div class="ultp-heading-filter">';
221 $wraper_before .= '<div class="ultp-heading-filter-in">';
222 include ULTP_PATH . 'blocks/template/heading.php';
223 $wraper_before .= '</div>';
224 $wraper_before .= '</div>';
225 }
226
227 $wraper_before .= '<div class="ultp-block-items-wrap" data-arrows="' . $attr['arrows'] . '" data-dots="' . $attr['dots'] . '" data-autoplay="' . $attr['autoPlay'] . '" data-slidespeed="' . $attr['slideSpeed'] . '" data-fade="' . $attr['fade'] . '" data-slidelg="' . ( isset( $slides['lg'] ) ? sanitize_html_class( $slides['lg'] ) : 1 ) . '" data-slidesm="' . ( isset( $slides['sm'] ) ? sanitize_html_class( $slides['sm'] ) : 1 ) . '" data-slidexs="' . ( isset( $slides['xs'] ) ? sanitize_html_class( $slides['xs'] ) : 1 ) . '">';
228 $idx = $noAjax ? 1 : 0;
229 while ( $recent_posts->have_posts() ) :
230 $recent_posts->the_post();
231
232 $dcContent = array_fill( 0, $attr['dcSize'], '' );
233
234 if ( ultimate_post()->is_dc_active( $attr ) ) {
235 $dcContent = \ULTP\DCService::get_dc_content_for_block( $attr, $dcContent );
236 }
237
238 include ULTP_PATH . 'blocks/template/data.php';
239
240 if ( $attr['queryUnique'] ) {
241 $unique_ID[ $attr['queryUnique'] ][] = $post_id;
242 }
243
244 $post_loop .= '<' . $attr['contentTag'] . ' class="ultp-block-item post-id-' . $post_id . '">';
245 if ( $attr['preLoader'] ) {
246 $post_loop .= '<div class="ultp-post-slider-loader-container">';
247 $post_loop .= ultimate_post()->postx_loading();
248 $post_loop .= '</div>';
249 }
250
251 $post_loop .= '<div>';
252 $post_loop .= '<div class="ultp-block-slider-wrap">';
253
254 $post_loop .= '<div class="ultp-block-image-inner">';
255 if ( ( $post_thumb_id || $attr['fallbackEnable'] ) && $attr['imageShow'] ) {
256 $post_loop .= '<div class="ultp-block-image ' . ( $attr['imgOverlay'] ? ' ultp-block-image-overlay ultp-block-image-' . $attr['imgOverlayType'] . ' ultp-block-image-' . $attr['imgOverlayType'] . $idx : '' ) . '">';
257 $post_loop .= '<a href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>';
258 // Post Image Id
259 $block_img_id = $post_thumb_id ? $post_thumb_id : ( $attr['fallbackEnable'] && isset( $attr['fallbackImg']['id'] ) ? $attr['fallbackImg']['id'] : '' );
260 // Post Image
261 if ( $post_thumb_id || ( $attr['fallbackEnable'] && $block_img_id ) ) {
262 $post_loop .= ultimate_post()->get_image( $block_img_id, $attr['imgCrop'], '', $title, $attr['imgSrcset'], $attr['imgLazy'] );
263 } else {
264 $post_loop .= '<img src="' . $dummy_url . '" alt="dummy-img" />';
265 }
266 $post_loop .= '</a></div>'; // .ultp-block-image
267 }
268 $post_loop .= '</div>'; // .ultp-block-image-inner
269
270 $post_loop .= '<div class="ultp-block-content ultp-block-content-' . $attr['contentVerticalPosition'] . ' ultp-block-content-' . $attr['contentHorizontalPosition'] . '">';
271 $post_loop .= '<div class="ultp-block-content-inner">';
272
273 include ULTP_PATH . 'blocks/template/category.php';
274 $post_loop .= $category;
275
276 $post_loop .= $dcContent[6];
277
278 if ( $title && $attr['titleShow'] && $attr['titlePosition'] ) {
279 include ULTP_PATH . 'blocks/template/title.php';
280 }
281
282 $post_loop .= $dcContent[5];
283
284 if ( $attr['metaPosition'] == 'top' ) {
285 include ULTP_PATH . 'blocks/template/meta.php';
286 }
287
288 $post_loop .= $dcContent[4];
289
290 if ( $title && $attr['titleShow'] && ! $attr['titlePosition'] ) {
291 include ULTP_PATH . 'blocks/template/title.php';
292 }
293
294 $post_loop .= $dcContent[3];
295
296 if ( $attr['excerptShow'] ) {
297 $post_loop .= '<div class="ultp-block-excerpt">' . ultimate_post()->get_excerpt( $post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $attr['excerptLimit'] ) . '</div>';
298 }
299
300 $post_loop .= $dcContent[2];
301
302 if ( $attr['readMore'] ) {
303 $post_loop .= '<div class="ultp-block-readmore"><a aria-label="' . $title . '" href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>' . ( $attr['readMoreText'] ? $attr['readMoreText'] : esc_html__( 'Read More', 'ultimate-post' ) ) . ultimate_post()->get_svg_icon( $attr['readMoreIcon'] ) . '</a></div>';
304 }
305
306 $post_loop .= $dcContent[1];
307
308 if ( $attr['metaPosition'] == 'bottom' ) {
309 include ULTP_PATH . 'blocks/template/meta.php';
310 }
311
312 $post_loop .= $dcContent[0];
313
314 $post_loop .= '</div>'; // .ultp-block-content-inner
315 $post_loop .= '</div>'; // .ultp-block-content
316
317 $post_loop .= '</div>'; // .ultp-block-slider-wrap
318 $post_loop .= '</div>'; // div
319 $post_loop .= '</' . $attr['contentTag'] . '>'; // .ultp-block-item
320
321 endwhile;
322
323 $wraper_after .= '</div>'; // .ultp-block-items-wrap
324
325 if ( $attr['arrows'] ) {
326 $wraper_after .= '<div class="ultp-slick-nav" style="display:none">';
327 $nav = explode( '#', $attr['arrowStyle'] );
328 $wraper_after .= '<div class="ultp-slick-prev"><div class="slick-arrow slick-prev">' . ultimate_post()->get_svg_icon( $nav[0] ) . '</div></div>';
329 $wraper_after .= '<div class="ultp-slick-next"><div class="slick-arrow slick-next">' . ultimate_post()->get_svg_icon( $nav[1] ) . '</div></div>';
330 $wraper_after .= '</div>';
331 }
332
333 $wraper_after .= '</div>'; // .ultp-block-wrapper
334 $wraper_after .= '</div>'; // .wp-block-ultimate-post-post-slider-1
335
336 wp_reset_query();
337 } else {
338 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
339 }
340
341 return $noAjax ? $post_loop : $wraper_before . $post_loop . $wraper_after;
342 }
343 }
344