PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.16.2
Shortcodes and extra features for Phlox theme v2.16.2
2.17.22 2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / public / includes / frontend-ajax.php
auxin-elements / public / includes Last commit date
class-auxels-frontend-assets.php 2 years ago frontend-ajax.php 3 years ago index.php 9 years ago templates-post.php 9 years ago
frontend-ajax.php
349 lines
1 <?php
2
3 /**
4 * Load more ajax handler for "Recent Posts Grid" element
5 *
6 * @return void
7 */
8 function auxels_ajax_handler_element_load_more(){
9 if( ! defined( 'AUXIN_INC' ) ){
10 wp_send_json_success("Phlox theme is required.");
11 }
12 if( empty( $_POST["handler"] ) ){
13 wp_send_json_success("Please specify a handler.");
14 }
15 // Direct call is not alloweded
16 if( empty( $_POST['action'] ) ){
17 wp_send_json_error( __( 'Ajax action not found.', 'auxin-elements' ) );
18 }
19 if( empty( $_POST['args'] ) ){
20 wp_send_json_error( __( 'Ajax args is required.', 'auxin-elements' ) );
21 }
22 // Authorize the call
23 if( ! wp_verify_nonce( $_POST['nonce'], 'auxin_front_load_more' ) ){
24 wp_send_json_error( __( 'Authorization failed.', 'auxin-elements' ) );
25 }
26
27 $ajax_args = auxin_sanitize_input( $_POST['args'] );
28 $element_markup = '';
29
30 // include the required resources
31 require_once( AUXELS_INC_DIR . '/general-functions.php' );
32 require_once( THEME_DIR . AUXIN_INC . 'include/functions.php' );
33 require_once( THEME_DIR . AUXIN_INC . 'include/templates/templates-post.php' );
34
35 // take required actions based on custom handler (element base name)
36 switch( $_POST['handler'] ) {
37
38 case 'aux_recent_posts':
39 require_once( AUXELS_INC_DIR . '/elements/recent-posts-grid-carousel.php' );
40
41 // Get the element markup
42 $element_markup = auxin_widget_recent_posts_callback( $ajax_args );
43 break;
44
45 case 'aux_recent_posts_land_style':
46 require_once( AUXELS_INC_DIR . '/elements/recent-posts-land-style.php' );
47
48 // Get the element markup
49 $element_markup = auxin_widget_recent_posts_land_style_callback( $ajax_args );
50 break;
51
52 case 'aux_recent_posts_masonry':
53 require_once( AUXELS_INC_DIR . '/elements/recent-posts-masonry.php' );
54
55 // Get the element markup
56 $element_markup = auxin_widget_recent_posts_masonry_callback( $ajax_args );
57 break;
58
59 case 'aux_recent_posts_tiles':
60 require_once( AUXELS_INC_DIR . '/elements/recent-posts-tiles.php' );
61
62 // Get the element markup
63 $element_markup = auxin_widget_recent_posts_tiles_callback( $ajax_args );
64 break;
65
66 case 'aux_recent_posts_timeline':
67 require_once( AUXELS_INC_DIR . '/elements/recent-posts-timeline.php' );
68
69 // Get the element markup
70 $element_markup = auxin_widget_recent_posts_timeline_callback( $ajax_args );
71 break;
72
73 case 'aux_recent_news':
74 require_once( AUXNEW_INC_DIR . '/elements/recent-news.php' );
75
76 // Get the element markup
77 $element_markup = auxin_widget_recent_news_callback( $ajax_args );
78 break;
79
80 case 'aux_recent_news_grid':
81 require_once( AUXNEW_INC_DIR . '/elements/recent-news-grid.php' );
82
83 // Get the element markup
84 $element_markup = auxin_widget_recent_news_grid_callback( $ajax_args );
85 break;
86
87 case 'aux_recent_news_big_grid':
88 require_once( AUXNEW_INC_DIR . '/elements/recent-news-big-grid.php' );
89
90 // Get the element markup
91 $element_markup = auxin_widget_recent_news_big_grid_callback( $ajax_args );
92 break;
93
94 case 'aux_recent_portfolios_grid':
95 require_once( AUXPFO_INC_DIR . '/elements/recent-portfolios.php' );
96
97 // Get the element markup
98 $element_markup = auxin_widget_recent_portfolios_grid_callback( $ajax_args );
99 break;
100
101 case 'aux_flexible_recent_posts':
102 require_once( AUXPRO_INC_DIR . '/elements/flexible-recent-posts.php' );
103
104 // Get the element markup
105 $element_markup = auxin_widget_flexible_recent_posts_callback( $ajax_args );
106 break;
107
108 default:
109 wp_send_json_error( __( 'Not a valid handler.', 'auxin-elements' ) );
110 break;
111 }
112
113 // if the output is empty
114 if( empty( $element_markup ) ){
115 wp_send_json_error( __( 'No data received.', 'auxin-elements' ) );
116 }
117
118 wp_send_json_success( $element_markup );
119 }
120
121 add_action( 'wp_ajax_load_more_element', 'auxels_ajax_handler_element_load_more' );
122 add_action( 'wp_ajax_nopriv_load_more_element', 'auxels_ajax_handler_element_load_more' );
123
124 /**
125 * Remove Product from Cart via Ajax
126 *
127 * @return void
128 */
129 function auxels_remove_product_from_cart() {
130
131 if ( !class_exists( 'WooCommerce' ) )
132 return;
133
134 global $woocommerce;
135
136 try {
137
138 $nonce = sanitize_text_field( $_POST['verify_nonce'] );
139 $id = absint( $_POST['product_id'] );
140 $cart_item_key = sanitize_text_field( $_POST['cart_item_key'] );
141
142 if( ! isset( $_POST['product_id'] ) || ! wp_verify_nonce( $nonce, 'remove_cart-' . $id ) ){
143 wp_send_json_error( sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-error">%s</div>', __('Verification failed!', 'auxin-elements') ) );
144 }
145
146 $cart = $woocommerce->cart;
147 $cart->remove_cart_item( $cart_item_key );
148
149 $cart->calculate_totals();
150
151 $args = !empty( $_POST['args'] ) ? auxin_sanitize_input( $_POST['args'] ) : array(
152 'title' => '',
153 'css_class' => '',
154 'dropdown_class' => '',
155 'color_class' => 'aux-black',
156 'action_on' => 'click',
157 'cart_url' => '#',
158 'dropdown_skin' => '',
159 );
160
161 $count = (int) $cart->cart_contents_count;
162 if ( $count > 0 ) {
163 $items = auxin_get_cart_items( $args );
164 } else {
165 $items = '<div class="aux-card-box aux-empty-cart"><img src="'. esc_url( AUXIN_URL . 'images/other/empty-cart.svg' ) . '">' . esc_html__( 'Cart is empty', 'auxin-elements' ) . '</div>';
166 }
167
168
169 $response = array(
170 'fragments' => apply_filters(
171 'woocommerce_add_to_cart_fragments',
172 array(
173 '.aux-cart-wrapper .aux-card-dropdown' => '<div class="aux-card-dropdown aux-phone-off">' . $items . '</div>' ,
174 )
175 ),
176 'cart_hash' => WC()->cart->get_cart_hash(),
177 'items' => $items,
178 'total' => $woocommerce->cart->get_cart_subtotal(),
179 'count' => $count,
180 'empty' => sprintf( '<div class="aux-card-box">%s</div>', __( 'Your cart is currently empty.', 'auxin-elements' ) ),
181 'notif' => sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-message">%s</div>', __('Item has been removed from your shopping cart.', 'auxin-elements') )
182 );
183
184 wp_send_json_success( $response );
185
186 } catch (Exception $e) {
187 wp_send_json_error( sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-error">%s</div>', __('An Error Occurred!', 'auxin-elements') ) );
188 }
189
190 }
191 add_action( 'wp_ajax_auxels_remove_from_cart', 'auxels_remove_product_from_cart' );
192 add_action( 'wp_ajax_nopriv_auxels_remove_from_cart', 'auxels_remove_product_from_cart' );
193
194
195 /**
196 * Add to Cart via Ajax
197 */
198 function auxels_add_product_to_cart() {
199
200 if ( ! class_exists( 'WooCommerce' ) )
201 return;
202
203 global $woocommerce;
204
205 try {
206
207 $product_id = isset( $_POST['product_id'] ) ? absint( $_POST['product_id'] ) : '';
208 $quantity = empty( $_POST['quantity'] ) ? 1 : wc_stock_amount( absint( $_POST['quantity'] ) );
209 $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
210
211 if( empty( $product_id ) ){
212 wp_send_json_error( sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-error">%s</div>', __('Verification failed!', 'auxin-elements') ) );
213 } else {
214 // Add item to cart
215 if( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity ) ) {
216 $args = !empty( $_POST['args'] ) ? auxin_sanitize_input( $_POST['args'] ) : array(
217 'title' => '',
218 'css_class' => '',
219 'dropdown_class' => '',
220 'color_class' => 'aux-black',
221 'action_on' => 'click',
222 'cart_url' => '#',
223 'dropdown_skin' => '',
224 'size' => 'thumbnail',
225 'icon' => auxin_get_option( 'product_cart_icon', 'auxicon-shopping-cart-1-1' )
226 );
227 $items = auxin_get_cart_items( $args );
228 $count = $woocommerce->cart->cart_contents_count;
229 $total = auxin_get_cart_basket( $args, $count );
230
231 $data = array(
232 'fragments' => apply_filters(
233 'woocommerce_add_to_cart_fragments',
234 array(
235 '.aux-cart-wrapper .aux-card-dropdown' => '<div class="aux-card-dropdown aux-phone-off">' . $items . '</div>' ,
236 )
237 ),
238 'cart_hash' => WC()->cart->get_cart_hash(),
239 'items' => $items,
240 'total' => $total,
241 'notif' => sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-message"><a href="%s" class="button wc-forward">%s</a> "%s" %s</div>', esc_url( wc_get_cart_url() ) , __( 'View cart', 'auxin-elements' ), get_the_title( $product_id ) , __('has been added to your cart.', 'auxin-elements') )
242 );
243 // Send json success
244 wp_send_json_success( $data );
245 } else {
246 wp_send_json_error( sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-error">%s</div>', __('Sorry, this product cannot be purchased.', 'auxin-elements') ) );
247 }
248
249 }
250
251 } catch( Exception $e ){
252 wp_send_json_error( sprintf( '<div class="aux-woocommerce-ajax-notification woocommerce-error">%s</div>', __('An Error Occurred!', 'auxin-elements') ) );
253 }
254
255 }
256 add_action( 'wp_ajax_auxels_add_to_cart', 'auxels_add_product_to_cart' );
257 add_action( 'wp_ajax_nopriv_auxels_add_to_cart', 'auxels_add_product_to_cart' );
258
259 /**
260 * Get refreshed cart fragments
261 */
262 function auxels_get_refreshed_fragments() {
263 global $woocommerce;
264
265 $args = isset( $_POST['args'] ) ? auxin_sanitize_input( $_POST['args'] ) : array(
266 'title' => '',
267 'css_class' => '',
268 'dropdown_class' => '',
269 'color_class' => 'aux-black',
270 'action_on' => 'click',
271 'cart_url' => '#',
272 'dropdown_skin' => '',
273 'size' => 'thumbnail',
274 'icon' => auxin_get_option( 'product_cart_icon', 'auxicon-shopping-cart-1-1' )
275 );
276
277 $count = (int) $woocommerce->cart->cart_contents_count;
278 if ( $count > 0 ) {
279 $items = auxin_get_cart_items( $args );
280 } else {
281 $items = '<div class="aux-card-box aux-empty-cart"><img src="'. esc_url( AUXIN_URL . 'images/other/empty-cart.svg' ) . '">' . esc_html__( 'Cart is empty', 'auxin-elements' ) . '</div>';
282 }
283
284 $total = auxin_get_cart_basket( $args, $count );
285
286 $data = array(
287 'cart_hash' => WC()->cart->get_cart_hash(),
288 'items' => $items,
289 'total' => $total,
290 );
291
292 // Send json success
293 wp_send_json_success( $data );
294 }
295 add_action( 'wp_ajax_auxels_get_refreshed_fragments', 'auxels_get_refreshed_fragments' );
296 add_action( 'wp_ajax_nopriv_auxels_get_refreshed_fragments', 'auxels_get_refreshed_fragments' );
297
298 /**
299 * Ajax Search Handler
300 *
301 * @return void
302 */
303 function auxels_ajax_search() {
304
305 $available_search_post_types = auxin_get_available_post_types_for_search();
306
307 if ( ! empty( $_GET['post_types'] ) ) {
308 $post_types = auxin_sanitize_input( $_GET['post_types'] );
309 } else {
310 $post_types = array_keys( $available_search_post_types );
311 }
312
313 $s = trim( sanitize_text_field( $_GET['s'] ) );
314 if ( "0" == $cat = trim( sanitize_text_field( $_GET['cat'] ) ) ) {
315 $cat = '';
316 }
317
318 // Start Searching First Post type
319 $search_instance = new Auxels_Search_Post_Type($s,$cat,$post_types[0],'');
320
321 if ( ! empty( $_GET['per_page'] ) && is_numeric( $_GET['per_page'] ) ) {
322 $search_instance->set_query_args( array( 'posts_per_page' => sanitize_text_field( $_GET['per_page'] ) ) );
323 }
324
325 $results = array();
326 foreach( $post_types as $key => $post_type ) {
327 $search_instance->set_query_args( array( 'post_type' => $post_type ) );
328 switch ($post_type) {
329 case 'product':
330 $result = $search_instance->search_products();
331 break;
332 case 'portfolio':
333 $result = $search_instance->search_portfolio();
334 break;
335 default:
336 $result = $search_instance->search_general_post_types();
337 break;
338 }
339 $result['fromTitle'] = sprintf( esc_html__( 'From %s', 'auxin-elements' ), esc_html( $available_search_post_types[ $post_type ] ) );
340 $result['noResultMessage'] = sprintf( esc_html__( "Nothing found in %s", 'auxin-elements' ), esc_html( $available_search_post_types[ $post_type ] ) );
341 $results[] = $result;
342
343 }
344
345 wp_send_json_success( $results );
346 }
347
348 add_action( 'wp_ajax_aux_modern_search_handler', 'auxels_ajax_search' );
349 add_action( 'wp_ajax_nopriv_aux_modern_search_handler', 'auxels_ajax_search');