PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.0
Post Grid Gutenberg Blocks – PostX v5.1.0
5.1.1 5.1.0 5.0.41 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 All 240 releases
ultimate-post / blocks / Post_Slider_2.php

Post_Slider_2.php in Post Grid Gutenberg Blocks – PostX 5.1.0, at blocks/Post_Slider_2.php

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