PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.0.3
Post Grid Gutenberg Blocks – PostX v4.0.3
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 4.0.3, at blocks/Post_Slider_2.php

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