PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / classes / modules / wpr-ajax-search.php
royal-elementor-addons / classes / modules Last commit date
forms 5 days ago wpr-ajax-search.php 5 days ago wpr-filter-grid-media.php 5 days ago wpr-form-handlers.php 5 days ago wpr-grid-helpers.php 5 days ago wpr-load-more-instagram-posts.php 5 days ago wpr-load-more-tweets.php 5 days ago wpr-post-likes.php 5 days ago wpr-woo-grid-helpers.php 5 days ago
wpr-ajax-search.php
248 lines
1 <?php
2 namespace WprAddons\Classes\Modules;
3
4 use Elementor\Utils;
5 use Elementor\Group_Control_Image_Size;
6 use WprAddons\Classes\Utilities;
7
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 /**
14 * WPR_Ajax_Search setup
15 *
16 * @since 3.4.6
17 */
18
19 class WPR_Ajax_Search {
20
21 public function __construct() {
22 add_action('wp_ajax_wpr_data_fetch' , [$this, 'data_fetch']);
23 add_action('wp_ajax_nopriv_wpr_data_fetch',[$this, 'data_fetch']);
24 }
25
26 public function data_fetch() {
27
28 $nonce = $_POST['nonce'];
29
30 if ( !wp_verify_nonce( $nonce, 'wpr-addons-js' ) ) {
31 return; // Get out of here, the nonce is rotten!
32 }
33
34 $all_post_types = [];
35
36 if ( sanitize_text_field($_POST['wpr_show_attachments']) == 'yes' ) {
37 $all_post_types = ['attachment'];
38 }
39
40 foreach( Utilities::get_custom_types_of( 'post', false ) as $key=>$value ) {
41 array_push($all_post_types, $key);
42 }
43
44 $tax_query = '';
45
46 if ( $_POST['wpr_category'] != false && $_POST['wpr_category'] != '' ) {
47 $tax_query = array(
48 array(
49 'taxonomy' => $_POST['wpr_option_post_type'],
50 'field' => 'term_id',
51 'terms' => sanitize_text_field($_POST['wpr_category']),
52 ),
53 );
54
55 // if ( isset($_POST['wpr_option_post_type']) && !empty($_POST['wpr_option_post_type']) ) {
56 // $tax_query = array(
57 // array(
58 // 'taxonomy' => $_POST['wpr_option_post_type'],
59 // 'field' => 'term_id',
60 // 'terms' => sanitize_text_field($_POST['wpr_category']),
61 // ),
62 // );
63 // } else {
64 // $tax_query = array(
65 // array(
66 // 'taxonomy' => $_POST['wpr_query_type'] == 'product' ? $_POST['wpr_query_type'] . '_cat' : 'category',
67 // 'field' => 'term_id',
68 // 'terms' => sanitize_text_field($_POST['wpr_category']),
69 // ),
70 // );
71 // }
72 } else if ( $_POST['wpr_category'] == 0 && $_POST['wpr_query_type'] != 'all' ) {
73 if ( !empty($_POST['wpr_option_post_type']) ) {
74 $tax_query = array(
75 array(
76 'taxonomy' => $_POST['wpr_option_post_type'],
77 'field' => 'term_id',
78 'terms' => sanitize_text_field($_POST['wpr_category']),
79 ),
80 );
81 } else {
82 // Get the string from the POST data
83 $taxonomy_type_string = $_POST['wpr_taxonomy_type'];
84
85 // Check if the string contains spaces
86 if (strpos($taxonomy_type_string, ' ') !== false) {
87 // Split the string into an array based on spaces
88 $taxonomy_types = explode(' ', $taxonomy_type_string);
89
90
91 $tax_query = [
92 'relation' => 'OR'
93 ];
94
95 foreach( $taxonomy_types as $taxonomy_type ) {
96 array_push($tax_query, [
97 'taxonomy' => $taxonomy_type,
98 'operator' => 'EXISTS'
99 ]);
100 }
101 } else {
102 // If there are no spaces, leave it as a single-item array
103 $taxonomy_types = $taxonomy_type_string;
104
105 $tax_query = array(
106 array(
107 'taxonomy' => $_POST['wpr_taxonomy_type'],
108 'operator' => 'EXISTS',
109 ),
110 );
111 }
112 }
113 }
114
115 $keyword = sanitize_text_field( $_POST['wpr_keyword'] );
116 $can_view_protected_posts = current_user_can('read_private_posts');
117 $meta_query = [];
118
119 if ( 'yes' === sanitize_text_field( $_POST['wpr_exclude_without_thumb'] ) ) {
120 $meta_query[] = [
121 'key' => '_thumbnail_id',
122 ];
123 }
124
125 if ( ( 'yes' !== sanitize_text_field($_POST['wpr_show_ps_pt'] ) ) || !$can_view_protected_posts ) {
126 $args =
127 [
128 'posts_per_page' => sanitize_text_field($_POST['wpr_number_of_results']),
129 's' => sanitize_text_field( $_POST['wpr_keyword'] ),
130 'post_type' => $_POST['wpr_query_type'] === 'all' || (!defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code()) ? $all_post_types : array( sanitize_text_field($_POST['wpr_query_type']) ),
131 'offset' => sanitize_text_field($_POST['wpr_search_results_offset']),
132 'meta_query' => $meta_query ?: '',
133 'tax_query' => $tax_query,
134 'post_status' => in_array('attachment', $all_post_types) ? ['publish', 'inherit'] : 'publish',
135 'post_password' => ''
136 ];
137 } else {
138 $args =
139 [
140 'posts_per_page' => sanitize_text_field($_POST['wpr_number_of_results']),
141 's' => sanitize_text_field( $_POST['wpr_keyword'] ),
142 'post_type' => $_POST['wpr_query_type'] === 'all' || (!defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code()) ? $all_post_types : array( sanitize_text_field($_POST['wpr_query_type']) ),
143 'offset' => sanitize_text_field($_POST['wpr_search_results_offset']),
144 'meta_query' => $meta_query ?: '',
145 'tax_query' => $tax_query,
146 'post_status' => in_array('attachment', $all_post_types) ? ['publish', 'inherit'] : 'publish',
147 ];
148 }
149
150 $the_query = new \WP_Query( $args );
151
152 if ( !$the_query->have_posts() && $keyword !== '' && 'yes' === sanitize_text_field( $_POST['wpr_meta_query'] ) ) {
153 $fallback_args = $args;
154 $fallback_args['s'] = ''; // disable default search
155 $fallback_args['meta_query'] = [
156 [
157 'value' => $keyword,
158 'compare' => 'LIKE'
159 ]
160 ];
161
162 $the_query = new \WP_Query($fallback_args);
163 }
164
165 if( $the_query->have_posts() ) :
166 $number_of_queried_posts = $the_query->found_posts;
167 $post_count = 0;
168
169 while( $the_query->have_posts() ) : $the_query->the_post();
170
171 // if ( ( !has_post_thumbnail() && 'yes' === sanitize_text_field($_POST['wpr_exclude_without_thumb'])) ) :
172 // continue;
173 // endif;
174
175 ob_start();
176 // the_post_thumbnail(sanitize_text_field($_POST['ajax_search_img_size']));
177 the_post_thumbnail('medium');
178 $post_thumb = ob_get_clean();
179 ?>
180
181 <li data-number-of-results="<?php echo esc_attr( (string) $the_query->found_posts ); ?>">
182
183 <?php if ( !post_password_required() || $can_view_protected_posts ) : ?>
184
185 <?php if ( 'yes' === sanitize_text_field($_POST['wpr_show_ajax_thumbnail']) ) :
186 if ( has_post_thumbnail() ) :
187 echo '<a class="wpr-ajax-img-wrap" target="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ) . '" href="' . esc_url( get_the_permalink() ) . '">' . wp_kses_post( $post_thumb ) . '</a>';
188 // echo '<a class="wpr-ajax-img-wrap" target="'. sanitize_text_field($_POST['ajax_search_link_target']) .'" href="'. esc_url( get_the_permalink() ) .'">'. '<img src="'. Group_Control_Image_Size::get_attachment_image_src( get_post_thumbnail_id(), 'ajax_search_image', [$_POST['ajax_search_image_size']] ) .'"/>' .'</a>';
189 else :
190 echo '<a class="wpr-ajax-img-wrap" target="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ) . '" href="' . esc_url( get_the_permalink() ) . '"><img src="' . esc_url( Utils::get_placeholder_image_src() ) . '" alt=""></a>';
191 endif ;
192 endif ; ?>
193
194 <div class="wpr-ajax-search-content">
195 <a target="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ); ?>" class="wpr-ajax-title" href="<?php echo esc_url( get_the_permalink() ); ?>"><?php the_title(); ?></a>
196
197 <?php if ( sanitize_text_field($_POST['wpr_show_description']) == 'yes' ) : ?>
198 <p class="wpr-ajax-desc"><a target="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ); ?>" href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( wp_trim_words( get_the_content(), (int) sanitize_text_field( wp_unslash( $_POST['wpr_number_of_words'] ) ) ) ); ?></a></p>
199 <?php endif; ?>
200
201 <?php if ( 'yes' === sanitize_text_field($_POST['wpr_show_product_price']) &&
202 get_post_type() === 'product' &&
203 class_exists('WooCommerce') ) :
204 $product = wc_get_product(get_the_ID());
205 if ($product) {
206 $price_html = '<div class="wpr-search-product-price">'. $product->get_price_html() .'</div>';
207
208 echo wp_kses_post( $price_html );
209 }
210 endif; ?>
211
212 <?php if ( sanitize_text_field($_POST['wpr_show_view_result_btn']) ) : ?>
213 <a target="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ); ?>" class="wpr-view-result" href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( sanitize_text_field( wp_unslash( $_POST['wpr_view_result_text'] ) ) ); ?></a>
214 <?php endif; ?>
215 </div>
216
217 <?php else: ?>
218
219 <?php if ( 'yes' === sanitize_text_field($_POST['wpr_show_ajax_thumbnail']) ) :
220 echo '<a class="wpr-ajax-img-wrap" target="' . esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ) . '" href="' . esc_url( get_the_permalink() ) . '"><img src="' . esc_url( Utils::get_placeholder_image_src() ) . '" alt=""></a>';
221 endif ; ?>
222
223 <div class="wpr-ajax-search-content">
224 <a target="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_POST['wpr_ajax_search_link_target'] ) ) ); ?>" class="wpr-ajax-title" href="<?php echo esc_url( get_the_permalink() ); ?>"><?php the_title(); ?></a>
225 </div>
226
227 <?php endif; ?>
228
229 </li>
230 <?php
231 $post_count++;
232 endwhile;
233
234 wp_reset_postdata();
235
236 else :
237 if (0 < sanitize_text_field($_POST['wpr_search_results_offset'])) {
238 } else {
239 echo '<p class="wpr-no-results">' . esc_html( sanitize_text_field( wp_unslash( $_POST['wpr_no_results'] ) ) ) . '</p>';
240 }
241
242 endif;
243
244 die();
245 }
246 }
247
248 new WPR_Ajax_Search();