PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.17
Post Grid Gutenberg Blocks – PostX v4.1.17
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 / classes / Blocks.php

Blocks.php in Post Grid Gutenberg Blocks – PostX 4.1.17, at classes/Blocks.php

564 lines 31.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Require All Blocks and handle block ajax action
4 * @package ULTP\Blocks
5 * @since 4.1.11
6 */
7
8 namespace ULTP;
9 defined('ABSPATH') || exit;
10
11 /*
12 * Blocks class.
13 */
14 class Blocks {
15
16 /*
17 * Setup class.
18 * @since 4.1.11
19 */
20 public function __construct() {
21 $this->include_all_blocks(); // Include Blocks
22 add_action( 'wp_ajax_ultp_next_prev', array( $this, 'ultp_next_prev_callback' )); // Next Previous AJAX Call
23 add_action( 'wp_ajax_nopriv_ultp_next_prev', array( $this, 'ultp_next_prev_callback' )); // Next Previous AJAX Call Logout User
24
25 add_action( 'wp_ajax_ultp_filter', array( $this, 'ultp_filter_callback' )); // Next Previous AJAX Call
26 add_action( 'wp_ajax_nopriv_ultp_filter', array( $this, 'ultp_filter_callback' )); // Next Previous AJAX Call Logout User
27
28 add_action( 'wp_ajax_ultp_adv_filter', array( $this, 'ultp_adv_filter_callback' ) );
29 add_action( 'wp_ajax_nopriv_ultp_adv_filter', array( $this, 'ultp_adv_filter_callback' ) );
30
31 add_action( 'wp_ajax_ultp_pagination', array( $this, 'ultp_pagination_callback' )); // Page Number AJAX Call
32 add_action( 'wp_ajax_nopriv_ultp_pagination', array( $this, 'ultp_pagination_callback' )); // Page Number AJAX Call Logout User
33
34 add_action( 'wp_ajax_ultp_share_count', array( $this, 'ultp_shareCount_callback' )); // share Count save
35 add_action( 'wp_ajax_nopriv_ultp_share_count', array( $this, 'ultp_shareCount_callback' )); // share Count save
36 }
37
38 /**
39 * Require Blocks
40 *
41 * @since v.1.0.0
42 * @return NULL
43 */
44 public function include_all_blocks() {
45 spl_autoload_register( function ( $class ) {
46 if ( strpos( $class, 'ULTP\blocks' ) === 0 ) {
47 $source = ULTP_PATH . 'blocks/' . explode( '\\', $class )[2] . '.php';
48 if ( file_exists( $source ) ) {
49 include_once $source;
50 } else {
51 $source = ULTP_PATH . 'addons/builder/blocks/' . explode( '\\', $class )[2] . '.php';
52 if ( file_exists( $source ) ) {
53 include_once $source;
54 }
55 }
56 }
57 } );
58
59
60 $request = isset( $_POST['action'] ) ? sanitize_text_field( $_POST['action'] ) : '';
61 $get_action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
62
63 if (
64 is_admin() &&
65 $request != 'et_fb_ajax_render_shortcode' && // Divi Module Check
66 $get_action != 'elementor' && // Elementor Widget Check
67 $request != 'elementor_ajax' // Elementor Widget Check
68 ) {
69 return ;
70 }
71
72
73 $settings = ultimate_post()->get_setting();
74 $blocks = array(
75 'post_list_1' => 'Post_List_1',
76 'post_list_2' => 'Post_List_2',
77 'post_list_3' => 'Post_List_3',
78 'post_list_4' => 'Post_List_4',
79 'post_grid_1' => 'Post_Grid_1',
80 'post_grid_2' => 'Post_Grid_2',
81 'post_grid_3' => 'Post_Grid_3',
82 'post_grid_4' => 'Post_Grid_4',
83 'post_grid_5' => 'Post_Grid_5',
84 'post_grid_6' => 'Post_Grid_6',
85 'post_grid_7' => 'Post_Grid_7',
86 'post_slider_1' => 'Post_Slider_1',
87 'post_slider_2' => 'Post_Slider_2',
88 'post_module_1' => 'Post_Module_1',
89 'post_module_2' => 'Post_Module_2',
90 'heading' => 'Heading',
91 'image' => 'Image',
92 'taxonomy' => 'Taxonomy',
93 'news_ticker' => 'News_Ticker',
94 'advanced_search' => 'Advanced_Search',
95 'advanced_filter' => 'Advanced_Filter',
96 'dark_Light' => 'Dark_Light',
97 'advanced_list' => 'Advanced_List',
98 'button' => 'Button'
99 );
100
101 foreach ( $blocks as $id => $block ) {
102 if ( isset($settings[$id]) && $settings[$id] != 'yes' ) {
103 } else {
104 $obj = '\ULTP\blocks\\' . $block;
105 new $obj();
106 }
107 }
108
109 if ( isset($settings['ultp_builder']) && $settings['ultp_builder'] == 'true' ) {
110 $builder_blocks = array(
111 'builder_archive_title' => 'Archive_Title',
112 'builder_post_title' => 'Post_Title',
113 'builder_post_content' => 'Post_Content',
114 'builder_post_featured_image' => 'Post_Featured_Image',
115 'builder_post_breadcrumb' => 'Post_Breadcrumb',
116 'builder_post_tag' => 'Post_Tag',
117 'builder_post_category' => 'Post_Category',
118 'builder_post_next_previous' => 'Next_Previous',
119 'builder_post_excerpt' => 'Post_Excerpt',
120 'builder_author_box' => 'Author_Box',
121 'builder_post_comments' => 'Post_Comments',
122 'builder_post_view_count' => 'Post_View_Count',
123 'builder_post_reading_time' => 'Post_Reading_Time',
124 'builder_post_comment_count' => 'Post_Comment_Count',
125 'builder_post_author_meta' => 'Post_Author_Meta',
126 'builder_post_date_meta' => 'Post_Date_Meta',
127 'builder_post_social_share' => 'Post_Social_Share',
128 'builder_advance_post_meta' => 'Advance_Post_Meta',
129 );
130 foreach ( $builder_blocks as $id => $block ) {
131 if ( isset($settings[$id]) && $settings[$id] != 'yes' ) {
132 } else {
133 $obj = '\ULTP\blocks\\' . $block;
134 new $obj();
135 }
136 }
137 }
138 }
139
140
141 /**
142 * Blocks Content Start
143 *
144 * @since v.1.0.0
145 * @return STRING
146 */
147 public function pagination_content_return( $blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds=[], $ultp_current_unique_posts=[] , $widgetBlockId='', $exclude_post_id = '', $adv_filter_data=[] ) {
148 foreach ( $blocks as $key => $value ) {
149 if ($blockName == $value['blockName']) {
150 if ( $value['attrs']['blockId'] == $blockId ) {
151 $objName = str_replace(' ', '_', ucwords(str_replace( ["ultimate-post/", "-"], ['', ' '], $blockName)) );
152 $new_obj = '\ULTP\blocks\\' . $objName;
153 $objectBlock = new $new_obj();
154 $attr = $objectBlock->get_attributes(true);
155
156 // Fix for grid blocks that do not support load more by default (pagination block)
157 if (isset($adv_filter_data['notFirstLoad']) && $adv_filter_data['notFirstLoad']) {
158 $attr['notFirstLoad'] = $adv_filter_data['notFirstLoad'];
159 }
160
161 $value['attrs']['paged'] = $paged;
162 if ( $builder ) {
163 $value['attrs']['builder'] = $builder;
164 }
165 if ( $postId ) {
166 $attr['current_post'] = $postId;
167 if( get_post_type($postId) == 'ultp_builder' && !$builder ){
168 $attr['current_post'] = $exclude_post_id;
169 }
170 }
171 if ( isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] ) {
172 $value['attrs']['loadMoreQueryUnique'] = $ultp_uniqueIds;
173 $ultp_uniqueIds[$value['attrs']['queryUnique']] = array_diff( $ultp_uniqueIds[$value['attrs']['queryUnique']], $ultp_current_unique_posts );
174 $value['attrs']['savedQueryUnique'] = $ultp_uniqueIds;
175 $value['attrs']['ultp_current_unique_posts'] = $ultp_current_unique_posts;
176 }
177 if( isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] && ( $value['attrs']['paginationType'] == 'loadMore' || $value['attrs']['paginationType'] == 'navigation') && isset($ultp_uniqueIds) && !isset($ultp_current_unique_posts) ) {
178 die();
179 }
180
181 if( $filterValue ) {
182 $value['attrs']['queryTaxValue'] = $adv_filter_data["is_adv"] ? wp_json_encode($filterValue) : wp_json_encode(array($filterValue));
183 $value['attrs']['queryTax'] = $filterType;
184 $value['attrs']['checkFilter'] = true;
185 $value['attrs']['filterShow'] = $adv_filter_data["filterShow"];
186 $value['attrs']['queryAuthor'] = $adv_filter_data["author"];
187 $value['attrs']['queryOrderBy'] = $adv_filter_data["orderby"];
188 $value['attrs']['queryOrder'] = $adv_filter_data["order"];
189 $value['attrs']['querySearch'] = $adv_filter_data["search"];
190 $value['attrs']['queryQuick'] = $adv_filter_data["adv_sort"];
191
192 if ($adv_filter_data["is_adv"]) {
193 $value['attrs']['queryRelation'] = 'AND';
194 }
195 }
196 // Exclude Current Post From Pagination
197 if( $exclude_post_id ){
198 $queryArr = json_decode( $value['attrs']['queryExclude']);
199 $queryArr[] = array(
200 'value' => $exclude_post_id,
201 'title' => ''
202 );
203 $value['attrs']['queryExclude'] = wp_json_encode($queryArr);
204 }
205 $attr = array_merge($attr, $value['attrs']);
206 echo $objectBlock->content($attr, true); //phpcs:ignore
207 die();
208 }
209 }
210 if ( !empty($value['innerBlocks']) ) {
211 $this->pagination_content_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, $exclude_post_id, $adv_filter_data);
212 }
213 }
214 }
215
216
217 /**
218 * Next Preview Callback of the Blocks
219 *
220 * @since v.1.0.0
221 * @return STRING
222 */
223 public function ultp_next_prev_callback() {
224 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
225 return ;
226 }
227
228 $paged = isset($_POST['paged'])?sanitize_text_field($_POST['paged']):'';
229 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
230 $postId = isset($_POST['postId'])? sanitize_text_field($_POST['postId']):'';
231 $blockRaw = isset($_POST['blockName'])? sanitize_text_field($_POST['blockName']):'';
232 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
233 $blockName = str_replace('_','/', $blockRaw);
234 $widgetBlockId = isset($_POST['widgetBlockId'])?sanitize_text_field($_POST['widgetBlockId']):'';
235 $exclude_post_id = isset($_POST['exclude']) ? sanitize_text_field($_POST['exclude']) : '';
236
237 $is_adv = isset($_POST['isAdv'])? ultimate_post()->ultp_rest_sanitize_params($_POST['isAdv']) : false;
238 $filterValue = isset($_POST['filterValue']) ?
239 (
240 is_array($_POST['filterValue']) ?
241 ultimate_post()->ultp_rest_sanitize_params( $_POST['filterValue'] ) :
242 sanitize_text_field($_POST['filterValue'])
243 ) :
244 '';
245
246 $filterType = isset($_POST['filterType'])? sanitize_text_field($_POST['filterType']):'';
247 $filterShow = isset($_POST['filterShow']) ? sanitize_text_field($_POST['filterShow']) : false;
248 $checkFilter = isset($_POST['checkFilter']) ? sanitize_text_field($_POST['checkFilter']) : false;
249 $author = isset($_POST['author']) ? sanitize_text_field( $_POST['author'] ) : false;
250 $orderby = isset($_POST['orderby']) ? sanitize_text_field( $_POST['orderby'] ) : 'date';
251 $order = isset($_POST['order']) ? sanitize_text_field( $_POST['order'] ) : 'DESC';
252 $search = isset($_POST['search']) ? sanitize_text_field( $_POST['search'] ) : '';
253 $adv_sort = isset($_POST['adv_sort']) ? sanitize_text_field( $_POST['adv_sort'] ) : '';
254
255 $adv_filter_data = array(
256 "is_adv" => filter_var($is_adv, FILTER_VALIDATE_BOOLEAN),
257 "filterShow" => filter_var($filterShow, FILTER_VALIDATE_BOOLEAN),
258 "checkFilter" => filter_var($checkFilter, FILTER_VALIDATE_BOOLEAN),
259 "author" => $author ? wp_json_encode($author) : false,
260 "orderby" => $orderby,
261 "order" => $order,
262 "search" => $search,
263 "adv_sort" => $adv_sort,
264 "notFirstLoad" => true
265 );
266
267 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
268 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
269
270 if( $widgetBlockId ) {
271 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
272 $this->pagination_content_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, '', $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, '', $adv_filter_data);
273 }elseif ($paged && $blockId && $postId && $blockName ) {
274 $post = get_post($postId);
275 if( has_blocks($post->post_content) ) {
276 $blocks = parse_blocks($post->post_content);
277 $this->pagination_content_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, '', $exclude_post_id, $adv_filter_data);
278 }
279 }
280 }
281
282 /**
283 * Filter Callback of the Blocks
284 *
285 * @since v.1.0.0
286 * @return STRING
287 */
288 public function ultp_filter_callback() {
289 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
290 return ;
291 }
292
293 $taxtype = isset($_POST['taxtype'])? sanitize_text_field($_POST['taxtype']):'';
294 if ( $taxtype ) {
295 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
296 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
297 $taxonomy = isset($_POST['taxonomy'])?sanitize_text_field($_POST['taxonomy']):'';
298 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
299 $blockName = str_replace('_','/', $blockRaw);
300 $post = get_post($postId);
301 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
302 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
303 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
304 $toReturn = [];
305
306 if( $widgetBlockId ) {
307 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
308 $data = $this->filter_content_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, $widgetBlockId, [], $ultp_uniqueIds, $ultp_current_unique_posts);
309 }elseif ( has_blocks($post->post_content) ) {
310 $blocks = parse_blocks($post->post_content);
311 $data = $this->filter_content_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, '', [], $ultp_uniqueIds, $ultp_current_unique_posts);
312 }
313 return wp_send_json_success( [
314 'filteredData' => $data
315 ] );
316 }
317 }
318
319 /**
320 * Advanced Filter Callback of the Blocks
321 *
322 * @since v.3.2.4
323 * @return string
324 */
325 public function ultp_adv_filter_callback() {
326 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
327 return ;
328 }
329
330 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
331 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
332
333 $taxonomy = isset($_POST['taxonomy']) ? ultimate_post()->ultp_rest_sanitize_params( $_POST['taxonomy'] ) : '[]';
334
335 $author = isset($_POST['author']) ? ultimate_post()->ultp_rest_sanitize_params( $_POST['author'] ) : false;
336 $orderby = isset($_POST['orderby']) ? sanitize_text_field( $_POST['orderby'] ) : 'date';
337 $order = isset($_POST['order']) ? sanitize_text_field( $_POST['order'] ) : 'DESC';
338 $search = isset($_POST['search']) ? sanitize_text_field( $_POST['search'] ) : '';
339 $adv_sort = isset($_POST['adv_sort']) ? sanitize_text_field( $_POST['adv_sort'] ) : '';
340
341 $adv_filter_data = array(
342 "is_adv" => true,
343 "filterShow" => true,
344 "checkFilter" => true,
345 "author" => $author ? wp_json_encode($author) : false,
346 "orderby" => $orderby,
347 "order" => $order,
348 "search" => $search,
349 "adv_sort" => $adv_sort
350 );
351
352 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
353 $blockName = str_replace('_','/', $blockRaw);
354 $post = get_post($postId);
355 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
356 $toReturn = [];
357
358 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
359 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
360
361 if( $widgetBlockId ) {
362 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
363 $data = $this->filter_content_return($blocks, $blockId, $blockRaw, $blockName, 'multiTaxonomy', $taxonomy, $postId, $toReturn, $widgetBlockId, $adv_filter_data, $ultp_uniqueIds, $ultp_current_unique_posts);
364 }elseif ( has_blocks($post->post_content) ) {
365 $blocks = parse_blocks($post->post_content);
366 $data = $this->filter_content_return($blocks, $blockId, $blockRaw, $blockName, 'multiTaxonomy', $taxonomy, $postId, $toReturn, '', $adv_filter_data, $ultp_uniqueIds, $ultp_current_unique_posts);
367 }
368 return wp_send_json_success( [
369 'filteredData' => $data
370 ] );
371 }
372
373 /**
374 * Pagination of the Blocks
375 *
376 * @since v.1.0.0
377 * @return STRING
378 */
379 public function ultp_pagination_callback() {
380 if (! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce'))) {
381 return ;
382 }
383
384 $paged = isset($_POST['paged'])? sanitize_text_field($_POST['paged']):'';
385 if ( $paged ) {
386 $blockId = isset($_POST['blockId'])? sanitize_text_field($_POST['blockId']):'';
387 $postId = isset($_POST['postId'])?sanitize_text_field($_POST['postId']):'';
388 $blockRaw = isset($_POST['blockName'])?sanitize_text_field($_POST['blockName']):'';
389 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
390 $blockName = str_replace('_','/', $blockRaw);
391 $post = get_post($postId);
392 $widgetBlockId = isset($_POST['widgetBlockId'])? sanitize_text_field($_POST['widgetBlockId']):'';
393 $exclude_post_id = isset($_POST['exclude']) ? sanitize_text_field($_POST['exclude']) : '';
394
395 $is_adv = isset($_POST['isAdv'])? ultimate_post()->ultp_rest_sanitize_params($_POST['isAdv']) : false;
396 $filterValue = isset($_POST['filterValue']) ?
397 (
398 is_array($_POST['filterValue']) ?
399 ultimate_post()->ultp_rest_sanitize_params( $_POST['filterValue'] ) :
400 sanitize_text_field($_POST['filterValue'])
401 ) :
402 '';
403
404 $filterType = isset($_POST['filterType'])? sanitize_text_field($_POST['filterType']):'';
405 $filterShow = isset($_POST['filterShow']) ? sanitize_text_field($_POST['filterShow']) : false;
406 $checkFilter = isset($_POST['checkFilter']) ? sanitize_text_field($_POST['checkFilter']) : false;
407 $author = isset($_POST['author']) ? sanitize_text_field( $_POST['author'] ) : false;
408 $orderby = isset($_POST['orderby']) ? sanitize_text_field( $_POST['orderby'] ) : 'date';
409 $order = isset($_POST['order']) ? sanitize_text_field( $_POST['order'] ) : 'DESC';
410 $search = isset($_POST['search']) ? sanitize_text_field( $_POST['search'] ) : '';
411 $adv_sort = isset($_POST['adv_sort']) ? sanitize_text_field( $_POST['adv_sort'] ) : '';
412
413 $adv_filter_data = array(
414 "is_adv" => filter_var($is_adv, FILTER_VALIDATE_BOOLEAN),
415 "filterShow" => filter_var($filterShow, FILTER_VALIDATE_BOOLEAN),
416 "checkFilter" => filter_var($checkFilter, FILTER_VALIDATE_BOOLEAN),
417 "author" => $author ? wp_json_encode($author) : false,
418 "orderby" => $orderby,
419 "order" => $order,
420 "search" => $search,
421 "adv_sort" => $adv_sort,
422 );
423
424
425 $ultp_uniqueIds = isset($_POST['ultpUniqueIds']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpUniqueIds'])), true) : [];
426 $ultp_current_unique_posts = isset($_POST['ultpCurrentUniquePosts']) ? json_decode(stripslashes(sanitize_text_field($_POST['ultpCurrentUniquePosts'])), true) : [];
427
428 if( $widgetBlockId ) {
429 $blocks = parse_blocks(get_option('widget_block')[$widgetBlockId]['content']);
430 $this->pagination_content_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, '', $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, $widgetBlockId, '', $adv_filter_data);
431 }elseif( has_blocks($post->post_content) ) {
432 $blocks = parse_blocks($post->post_content);
433 $this->pagination_content_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId, $filterValue, $filterType, $ultp_uniqueIds, $ultp_current_unique_posts, '', $exclude_post_id, $adv_filter_data);
434 }
435 }
436 }
437
438 /**
439 * share Count callback
440 *
441 * @since v.1.0.0
442 * @return STRING
443 */
444 public function ultp_shareCount_callback() {
445 if ( ! (isset($_REQUEST['wpnonce']) && wp_verify_nonce(sanitize_key(wp_unslash($_REQUEST['wpnonce'])), 'ultp-nonce')) ) {
446 return ;
447 }
448 $id =isset($_POST['postId'])? sanitize_text_field($_POST['postId']):'';
449 $count = isset($_POST['shareCount'])? sanitize_text_field($_POST['shareCount']):'';
450 $post_id = $id;
451 $new_count = $count+1;
452 update_post_meta($post_id, 'share_count', $new_count);
453 }
454
455 /**
456 * Filter Callback of the Blocks
457 *
458 * @since v.1.0.0
459 * @return string
460 */
461 public function filter_content_return( $blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, &$toReturn, $widgetBlockId='', $adv_filter_data=[], $ultp_uniqueIds=[], $ultp_current_unique_posts=[] ) {
462 foreach ( $blocks as $key => $value ) {
463 if ( $blockName == $value['blockName'] ) {
464 if ( $value['attrs']['blockId'] == $blockId ) {
465 $objName = str_replace(' ', '_', ucwords(str_replace( ["ultimate-post/", "-"], ['', ' '], $blockName)) );
466 $new_obj = '\ULTP\blocks\\' . $objName;
467 $objectBlock = new $new_obj();
468 $attr = $objectBlock->get_attributes(true);
469 if ( $taxonomy ) {
470
471 if (isset($adv_filter_data['is_adv']) && $adv_filter_data['is_adv']) {
472 $value['attrs']['queryTaxValue'] = wp_json_encode($taxonomy);
473 $value['attrs']['queryRelation'] = 'AND';
474 $value['attrs']['queryAuthor'] = $adv_filter_data['author'];
475 $value['attrs']['queryOrderBy'] = $adv_filter_data['orderby'];
476 $value['attrs']['queryOrder'] = $adv_filter_data['order'];
477 $value['attrs']['querySearch'] = $adv_filter_data['search'];
478 $value['attrs']['queryQuick'] = $adv_filter_data['adv_sort'];
479 } else {
480 $value['attrs']['queryTaxValue'] = wp_json_encode(array($taxonomy));
481 }
482
483 $value['attrs']['queryTax'] = $taxtype;
484 $value['attrs']['ajaxCall'] = true;
485 }
486 if ( isset($value['attrs']['queryNumber']) ) {
487 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
488 }
489
490 if ( isset($value['attrs']['queryUnique']) && $value['attrs']['queryUnique'] ) {
491 $value['attrs']['loadMoreQueryUnique'] = $ultp_uniqueIds;
492 $ultp_uniqueIds[$value['attrs']['queryUnique']] = array_diff( $ultp_uniqueIds[$value['attrs']['queryUnique']], $ultp_current_unique_posts );
493 $value['attrs']['savedQueryUnique'] = $ultp_uniqueIds;
494 $value['attrs']['ultp_current_unique_posts'] = $ultp_current_unique_posts;
495 }
496
497 $attr = array_merge($attr, $value['attrs']);
498
499 $filter_attributes = [];
500
501 $filter_attributes['isAdv'] = isset($adv_filter_data['is_adv']) ? $adv_filter_data['is_adv'] : false;
502 $filter_attributes['queryTaxValue'] = $filter_attributes['isAdv'] ? wp_json_encode($taxonomy) : $taxonomy;
503 $filter_attributes['queryTax'] = $taxtype;
504
505 if ($filter_attributes['isAdv']) {
506 $filter_attributes['queryAuthor'] = $adv_filter_data['author'];
507 $filter_attributes['queryOrderBy'] = $adv_filter_data['orderby'];
508 $filter_attributes['queryOrder'] = $adv_filter_data['order'];
509 $filter_attributes['querySearch'] = $adv_filter_data['search'];
510 $filter_attributes['queryQuick'] = $adv_filter_data['adv_sort'];
511 }
512
513 $toReturn = [
514 'blocks' => $objectBlock->content($attr, true),
515 'pagination' => $this->pagination_for_filter($attr, $postId, $blockRaw, $filter_attributes),
516 'paginationType' => $attr['paginationType'],
517 'paginationShow' => $attr['paginationShow']
518 ];
519 }
520 }
521 if ( !empty($value['innerBlocks']) ) {
522 $this->filter_content_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy, $postId, $toReturn, $widgetBlockId, $adv_filter_data, $ultp_uniqueIds, $ultp_current_unique_posts);
523 }
524 }
525 return $toReturn;
526 }
527
528 /**
529 * Pagination for filter cal'back
530 *
531 * @since v.2.8.9
532 * @return STRING
533 */
534 public function pagination_for_filter( $attr, $postId, $blockRaw, $filter_attributes ) {
535 $attr['queryNumber'] = ultimate_post()->get_post_number(4, $attr['queryNumber'], $attr['queryNumPosts']);
536 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
537 $pageNum = ultimate_post()->get_page_number($attr, $recent_posts->found_posts);
538
539 $datasets = ultimate_post()->get_adv_data_attrs(null, $filter_attributes);
540 $datasets .= ' data-for="ultp-block-' . sanitize_html_class($attr['blockId']) . '" ';
541
542 $wraper_after = '';
543 $style = $pageNum == 1 ? 'style="display:none"' : '';
544
545 if( $attr['paginationType'] == 'loadMore' ) {
546 $wraper_after .= '<div '.$style.' class="ultp-loadmore "'.'>';
547 $wraper_after .= '<span class="ultp-loadmore-action" tabindex="0" role="button" data-pages="'.$pageNum.'" data-pagenum="1" data-blockid="'.$attr['blockId'].'" data-blockname="'.$blockRaw.'" data-postid="'.$postId.'" '.ultimate_post()->get_builder_attr($attr['queryType']). $datasets.'>'.( isset($attr['loadMoreText']) ? $attr['loadMoreText'] : 'Load More' ).' <span class="ultp-spin">'.ultimate_post()->get_svg_icon('refresh').'</span></span>';
548 $wraper_after .= '</div>';
549 }
550 else if( $attr['paginationType'] == 'navigation' ) {
551 $wraper_after .= '<div '.$style.' class="ultp-next-prev-wrap" data-pages="'.$pageNum.'" data-pagenum="1" data-blockid="'.$attr['blockId'].'" data-blockname="'.$blockRaw.'" data-postid="'.$postId.'" '.ultimate_post()->get_builder_attr($attr['queryType']). $datasets .'>';
552 $wraper_after .= ultimate_post()->next_prev();
553 $wraper_after .= '</div>';
554 }
555 else if( $attr['paginationType'] == 'pagination' ) {
556 $wraper_after .= '<div class="ultp-pagination-wrap'.($attr["paginationAjax"] ? " ultp-pagination-ajax-action" : "").'" data-paged="1" data-blockid="'.$attr['blockId'].'" data-postid="'.$postId.'" data-pages="'.$pageNum.'" data-blockname="'.$blockRaw.'" '.ultimate_post()->get_builder_attr($attr['queryType']). $datasets .'>';
557 $wraper_after .= ultimate_post()->pagination($pageNum, $attr['paginationNav'], $attr['paginationText'], $attr["paginationAjax"], isset($_SERVER['HTTP_REFERER'])?esc_url_raw($_SERVER['HTTP_REFERER']):'');
558 $wraper_after .= '</div>';
559 }
560 wp_reset_query();
561
562 return $wraper_after;
563 }
564 }