PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.32
Post Grid Gutenberg Blocks – PostX v5.0.32
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_2.php

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

335 lines 14.3 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 $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 $is_visible = false;
176 if ( isset( $attr['blockPubDate'] ) && $attr['blockPubDate'] != 'empty' ) {
177 $is_visible = ultimate_post()->is_pro_feature_visible( $attr['blockPubDate'] );
178 }
179
180 $is_active = ultimate_post()->is_lc_active();
181
182 if ( $is_active || $is_visible ) {
183 $block_name = 'post-slider-2';
184 $wraper_before = $wraper_after = $post_loop = '';
185 $attr['queryNumber'] = ultimate_post()->get_post_number( 5, $attr['queryNumber'], $attr['queryNumPosts'] );
186 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
187 $pageNum = ultimate_post()->get_page_number( $attr, $recent_posts->found_posts );
188 // Dummy Img Url
189 $dummy_url = ULTP_URL . 'assets/img/ultp-fallback-img.png';
190
191 $slides = is_object( $attr['slidesToShow'] ) ? json_decode( wp_json_encode( $attr['slidesToShow'] ), true ) : $attr['slidesToShow'];
192
193 $centerPadd = is_object( $attr['slidesCenterPadding'] ) ? json_decode( wp_json_encode( $attr['slidesCenterPadding'] ), true ) : $attr['slidesCenterPadding'];
194 if ( $recent_posts->have_posts() ) {
195 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
196 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
197 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
198 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
199 $attr['contentTag'] = in_array( $attr['contentTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['contentTag'] : 'div';
200 $attr['layout'] = sanitize_html_class( $attr['layout'] );
201 $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] );
202 $attr['slideSpeed'] = sanitize_html_class( $attr['slideSpeed'] );
203 $attr['arrows'] = $attr['arrows'] == true;
204 $attr['dots'] = $attr['dots'] == true;
205 $attr['autoPlay'] = $attr['autoPlay'] == true;
206 $attr['fade'] = $attr['fade'] == true;
207 $attr['readMoreText'] = wp_kses( $attr['readMoreText'], ultimate_post()->ultp_allowed_html_tags() );
208 $attr['contentVerticalPosition'] = sanitize_html_class( $attr['contentVerticalPosition'] );
209 $attr['contentHorizontalPosition'] = sanitize_html_class( $attr['contentHorizontalPosition'] );
210
211 $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'] : '' ) . '">';
212 $wraper_before .= '<div class="ultp-block-wrapper">';
213 if ( $attr['headingShow'] ) {
214 $wraper_before .= '<div class="ultp-heading-filter">';
215 $wraper_before .= '<div class="ultp-heading-filter-in">';
216 include ULTP_PATH . 'blocks/template/heading.php';
217 $wraper_before .= '</div>';
218 $wraper_before .= '</div>';
219 }
220 $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 ) . '"
221 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 ) . '">';
222 $idx = $noAjax ? 1 : 0;
223 while ( $recent_posts->have_posts() ) :
224 $recent_posts->the_post();
225
226 $dcContent = array_fill( 0, $attr['dcSize'], '' );
227
228 if ( ultimate_post()->is_dc_active( $attr ) ) {
229 $dcContent = \ULTP\DCService::get_dc_content_for_block( $attr, $dcContent );
230 }
231
232 include ULTP_PATH . 'blocks/template/data.php';
233
234 if ( $attr['queryUnique'] ) {
235 $unique_ID[ $attr['queryUnique'] ][] = $post_id;
236 }
237
238 $post_loop .= '<' . $attr['contentTag'] . ' class="ultp-block-item post-id-' . $post_id . '">';
239 if ( $attr['preLoader'] ) {
240 $post_loop .= '<div class="ultp-post-slider-loader-container">';
241 $post_loop .= ultimate_post()->postx_loading();
242 $post_loop .= '</div>';
243 }
244 $post_loop .= '<div>';
245 $post_loop .= '<div class="ultp-block-slider-wrap">';
246
247 $post_loop .= '<div class="ultp-block-image-inner">';
248 if ( $post_thumb_id || $attr['fallbackEnable'] ) {
249 $post_loop .= '<div class="ultp-block-image ' . ( $attr['imgOverlay'] ? ' ultp-block-image-overlay ultp-block-image-' . $attr['imgOverlayType'] . ' ultp-block-image-' . $attr['imgOverlayType'] . $idx : '' ) . '">';
250 $post_loop .= '<a href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>';
251 // Post Image Id
252 $block_img_id = $post_thumb_id ? $post_thumb_id : ( $attr['fallbackEnable'] && isset( $attr['fallbackImg']['id'] ) ? $attr['fallbackImg']['id'] : '' );
253 // Post Image
254 if ( $post_thumb_id || ( $attr['fallbackEnable'] && $block_img_id ) ) {
255 $post_loop .= ultimate_post()->get_image( $block_img_id, $attr['imgCrop'], '', $title, $attr['imgSrcset'], $attr['imgLazy'] );
256 } else {
257 $post_loop .= '<img src="' . $dummy_url . '" alt="dummy-img" />';
258 }
259 $post_loop .= '</a></div>'; // .ultp-block-image
260 }
261 $post_loop .= '</div>'; // .ultp-block-image-inner
262 $post_loop .= '<div class="ultp-block-content ultp-block-content-' . $attr['contentVerticalPosition'] . ' ultp-block-content-' . $attr['contentHorizontalPosition'] . '">';
263 $post_loop .= '<div class="ultp-block-content-inner">';
264
265 $post_loop .= $dcContent[7];
266
267 include ULTP_PATH . 'blocks/template/category.php';
268 $post_loop .= $category;
269
270 $post_loop .= $dcContent[6];
271
272 if ( $title && $attr['titleShow'] && $attr['titlePosition'] ) {
273 include ULTP_PATH . 'blocks/template/title.php';
274 }
275
276 $post_loop .= $dcContent[5];
277
278 if ( $attr['metaPosition'] == 'top' ) {
279 include ULTP_PATH . 'blocks/template/meta.php';
280 }
281
282 $post_loop .= $dcContent[4];
283
284 if ( $title && $attr['titleShow'] && ! $attr['titlePosition'] ) {
285 include ULTP_PATH . 'blocks/template/title.php';
286 }
287
288 $post_loop .= $dcContent[3];
289
290 if ( $attr['excerptShow'] ) {
291 $post_loop .= '<div class="ultp-block-excerpt">' . ultimate_post()->get_excerpt( $post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $attr['excerptLimit'] ) . '</div>';
292 }
293
294 $post_loop .= $dcContent[2];
295
296 if ( $attr['readMore'] ) {
297 $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>';
298 }
299
300 $post_loop .= $dcContent[1];
301
302 if ( $attr['metaPosition'] == 'bottom' ) {
303 include ULTP_PATH . 'blocks/template/meta.php';
304 }
305
306 $post_loop .= $dcContent[0];
307
308 $post_loop .= '</div>';
309 $post_loop .= '</div>';
310
311 $post_loop .= '</div>';
312 $post_loop .= '</div>';
313 $post_loop .= '</' . $attr['contentTag'] . '>';
314 endwhile;
315 $wraper_after .= '</div>';
316
317 if ( $attr['arrows'] ) {
318 $wraper_after .= '<div class="ultp-slick-nav" style="display:none">';
319 $nav = explode( '#', $attr['arrowStyle'] );
320 $wraper_after .= '<div class="ultp-slick-prev"><div class="slick-arrow slick-prev">' . ultimate_post()->get_svg_icon( $nav[0] ) . '</div></div>';
321 $wraper_after .= '<div class="ultp-slick-next"><div class="slick-arrow slick-next">' . ultimate_post()->get_svg_icon( $nav[1] ) . '</div></div>';
322 $wraper_after .= '</div>';
323 }
324 $wraper_after .= '</div>';
325 $wraper_after .= '</div>';
326 wp_reset_query();
327 } else {
328 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
329 }
330
331 return $noAjax ? $post_loop : $wraper_before . $post_loop . $wraper_after;
332 }
333 }
334 }
335