Changeset 2911702
- Timestamp:
- 05/12/2023 04:22:15 PM (3 years ago)
- Location:
- sf-autosuggest-product-search
- Files:
-
- 33 added
- 7 edited
-
tags/1.3 (added)
-
tags/1.3/README.txt (added)
-
tags/1.3/assets (added)
-
tags/1.3/assets/css (added)
-
tags/1.3/assets/css/sf_pa.css (added)
-
tags/1.3/assets/css/sf_pa_admin.css (added)
-
tags/1.3/assets/fonts (added)
-
tags/1.3/assets/fonts/Roboto (added)
-
tags/1.3/assets/fonts/Roboto/LICENSE.txt (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Black.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-BlackItalic.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Bold.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-BoldItalic.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Italic.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Light.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-LightItalic.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Medium.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-MediumItalic.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Regular.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-Thin.ttf (added)
-
tags/1.3/assets/fonts/Roboto/Roboto-ThinItalic.ttf (added)
-
tags/1.3/assets/img (added)
-
tags/1.3/assets/img/loading.gif (added)
-
tags/1.3/assets/img/search-example.png (added)
-
tags/1.3/assets/js (added)
-
tags/1.3/assets/js/sf_pa.js (added)
-
tags/1.3/assets/js/sf_pa_admin.js (added)
-
tags/1.3/classes (added)
-
tags/1.3/classes/AdminClass.php (added)
-
tags/1.3/classes/SearchClass.php (added)
-
tags/1.3/classes/ValidatorClass.php (added)
-
tags/1.3/sf_products_autosuggest.php (added)
-
trunk/README.txt (modified) (4 diffs)
-
trunk/assets/css/sf_pa.css (modified) (1 diff)
-
trunk/assets/img/loading.gif (added)
-
trunk/assets/js/sf_pa.js (modified) (3 diffs)
-
trunk/assets/js/sf_pa_admin.js (modified) (1 diff)
-
trunk/classes/AdminClass.php (modified) (4 diffs)
-
trunk/classes/SearchClass.php (modified) (1 diff)
-
trunk/sf_products_autosuggest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sf-autosuggest-product-search/trunk/README.txt
r2906136 r2911702 5 5 Requires PHP: 7.0 6 6 Tested up to: 6.2 7 Stable tag: 1.27 Stable tag: 1.3 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.txt … … 13 13 == Description == 14 14 15 SF Autosuggest Product Search is a plugin for add Woocommerce search Autosuggest to your ecommerce. 15 SF Autosuggest Product Search is a plugin for add Woocommerce search Autosuggest to your ecommerce. 16 With this Woocomerce search plugin you can improve products search and give a better experience to your users. 16 17 It's very simple to add Autosuggest Product into your ecommerce. 17 18 Choose your preference from SF Autosuggest Products settings. … … 54 55 55 56 == Changelog == 56 = 1.1 = 57 * Added sf_pa_autosuggest_results filter to filter results. 58 * Added wpml compatibility59 * Added ability to customize "Show all results" text57 58 = 1.3 = 59 * Added loader in input search 60 * Save search data in transients for better performance 60 61 61 62 = 1.2 = … … 64 65 * Fix bug incorrect permalink 65 66 67 = 1.1 = 68 * Added sf_pa_autosuggest_results filter to filter results. 69 * Added wpml compatibility 70 * Added ability to customize "Show all results" text 71 66 72 == Upgrade Notice == -
sf-autosuggest-product-search/trunk/assets/css/sf_pa.css
r2870187 r2911702 53 53 text-align: center; 54 54 } 55 56 img.sf_pa_loader { 57 display: none; 58 position: absolute; 59 top: 0px; 60 left: inherit; 61 right: 10px; 62 width: 30px; 63 top: 5px; 64 } -
sf-autosuggest-product-search/trunk/assets/js/sf_pa.js
r2906136 r2911702 3 3 function(){ 4 4 jQuery('#sf_pa_search_input').on('input', function(){ 5 var input_container = jQuery(this).closest('.sf_pa_search_input_container'); 5 6 if(jQuery(this).val().length > 2){ 6 7 if (postcall){ 7 8 postcall.abort(); 8 9 } 10 showLoader(); 9 11 jQuery('.sf_pa_autosuggest_response').remove(); 10 12 jQuery('.sf_pa_autosuggest_container').remove(); … … 16 18 17 19 postcall = jQuery.post(sf_pa_ajax_object.ajaxurl, data, function(response) { 18 jQuery('.sf_pa_search_input_container').append('<div class="sf_pa_autosuggest_container"></div>'); 20 hideLoader(); 21 jQuery(input_container).append('<div class="sf_pa_autosuggest_container"></div>'); 19 22 for (var i = 0; i < response.length; ++i) { 20 23 var to_append = '<div class="sf_pa_autosuggest_response"><div>'; … … 59 62 } 60 63 ); 64 65 function showLoader(){ 66 jQuery('.sf_pa_loader').show(); 67 } 68 69 function hideLoader(){ 70 jQuery('.sf_pa_loader').hide(); 71 } -
sf-autosuggest-product-search/trunk/assets/js/sf_pa_admin.js
r2870187 r2911702 1 1 jQuery(document).ready(function($){ 2 2 $('.sf_pa_color_picker').wpColorPicker(); 3 $('#sf_remove_transient').on('click', function(){ 4 /* TODO: fare ajax per cancellazione transients */ 5 var data = { 6 'action': 'delete_sf_pa_transient' 7 }; 8 jQuery.post(ajaxurl, data, function(response) { 9 location.reload(); 10 }); 11 12 }); 3 13 }); -
sf-autosuggest-product-search/trunk/classes/AdminClass.php
r2906136 r2911702 5 5 add_action( 'admin_init', [$this, 'register_settings'] ); 6 6 add_action( 'admin_menu', [$this, 'add_settings_page'] ); 7 add_action( 'wp_ajax_delete_sf_pa_transient', [$this, 'delete_sf_pa_transient'] ); 7 8 } 8 9 … … 23 24 <?php 24 25 settings_fields( 'sf_pa_autosuggest_plugin_options' ); 25 do_settings_sections( 'sf_pa_autosuggest_plugin' ); ?> 26 do_settings_sections( 'sf_pa_autosuggest_plugin' ); 27 ?> 28 <h3><?php _e('Delete Transient', 'sf_products_autosuggest'); ?></h3> 29 <p><?php echo $this->count_sf_pa_transient(); ?> <?php _e('Searches saved in transients.', 'sf_products_autosuggest'); ?></p> 30 <p><?php _e('Delete all transients and remove cache data:', 'sf_products_autosuggest'); ?> <button type="button" id="sf_remove_transient"><?php _e('Remove Transient', 'sf_products_autosuggest'); ?></button> 31 </p> 26 32 <input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Save', 'sf_products_autosuggest'); ?>" /> 27 33 </form> … … 164 170 165 171 public function taxonomies($params){ 166 /*TODO: multple choice*/167 172 $options = get_option( 'sf_pa_autosuggest_plugin_options' ); 168 173 $value = ''; … … 193 198 $newinput['all_bg'] = $validator->hexadecimal($input['all_bg'], '#000'); 194 199 $newinput['all_color'] = $validator->hexadecimal($input['all_color'], '#fff'); 195 $newinput['show_thumbnail'] = $validator->checkbox($input['show_thumbnail']); 196 $newinput['show_cat'] = $validator->checkbox($input['show_cat']); 200 if(isset($input['show_thumbnail']) && !empty($input['show_thumbnail'])){ 201 $newinput['show_thumbnail'] = $validator->checkbox($input['show_thumbnail']); 202 } 203 if(isset($input['show_cat']) && !empty($input['show_cat'])){ 204 $newinput['show_cat'] = $validator->checkbox($input['show_cat']); 205 } 197 206 $newinput['exclude_cat'] = $validator->ids($input['exclude_cat']); 198 207 $newinput['exclude_ids'] = $validator->ids($input['exclude_ids']); 199 208 $newinput['taxonomies_search'] = array(); 200 foreach($input['taxonomies_search'] as $single_tax){ 201 if( $single_tax != '') 202 $newinput['taxonomies_search'][] = $validator->plaintext($single_tax); 203 } 204 209 if(isset($input['taxonomies_search']) && !empty($input['taxonomies_search'])){ 210 foreach($input['taxonomies_search'] as $single_tax){ 211 if( $single_tax != '') 212 $newinput['taxonomies_search'][] = $validator->plaintext($single_tax); 213 } 214 } 205 215 206 216 return $newinput; 217 } 218 219 private function count_sf_pa_transient(){ 220 $transient_to_delete = get_transient('sf_pa_transient'); 221 if($transient_to_delete){ 222 return count($transient_to_delete); 223 } 224 return 0; 225 } 226 227 public function delete_sf_pa_transient(){ 228 $transient_to_delete = get_transient('sf_pa_transient'); 229 if($transient_to_delete){ 230 foreach($transient_to_delete as $single_transient){ 231 delete_transient('sf_pa_'.$single_transient); 232 } 233 } 234 delete_transient('sf_pa_transient'); 235 return 1; 207 236 } 208 237 } -
sf-autosuggest-product-search/trunk/classes/SearchClass.php
r2906136 r2911702 14 14 global $wpdb; 15 15 16 $ prepare = array($this->options['show_cat'], $this->options['show_thumbnail'], '%' . $wpdb->esc_like($sf_pa_search) .'%');17 $join = '';18 $where = '';16 $results = get_transient('sf_pa_'.$sf_pa_search); 17 /* IF NOT CACHED */ 18 if(!$results){ 19 19 20 //Check if site use wpml 21 if (class_exists('SitePress')) { 22 $lang = esc_sql(apply_filters( 'wpml_current_language', NULL )); 23 $join = " LEFT JOIN ".$wpdb->prefix."icl_translations ON ".$wpdb->prefix."icl_translations.element_id = ".$wpdb->prefix."posts.ID AND element_type = 'post_product'"; 24 $where = " AND ".$wpdb->prefix."icl_translations.language_code = %s"; 25 $prepare[] = $lang; 20 $prepare = array($this->options['show_cat'], $this->options['show_thumbnail'], '%' . $wpdb->esc_like($sf_pa_search) .'%'); 21 $join = ''; 22 $where = ''; 23 24 //Check if site use wpml 25 if (class_exists('SitePress')) { 26 $lang = esc_sql(apply_filters( 'wpml_current_language', NULL )); 27 $join = " LEFT JOIN ".$wpdb->prefix."icl_translations ON ".$wpdb->prefix."icl_translations.element_id = ".$wpdb->prefix."posts.ID AND element_type = 'post_product'"; 28 $where = " AND ".$wpdb->prefix."icl_translations.language_code = %s"; 29 $prepare[] = $lang; 30 } 31 32 $sql = "SELECT ".$wpdb->prefix."posts.ID, ".$wpdb->prefix."posts.post_title as title, img_postmeta.meta_value as img_url, ".$wpdb->prefix."terms.name as cat_title, %s as show_cat, %s as show_thumbnail, 'product' AS type 33 FROM ".$wpdb->prefix."posts 34 LEFT JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."postmeta.post_id = ".$wpdb->prefix."posts.ID AND ".$wpdb->prefix."postmeta.meta_key = '_thumbnail_id' 35 LEFT JOIN ".$wpdb->prefix."postmeta as img_postmeta ON img_postmeta.post_id = ".$wpdb->prefix."postmeta.meta_value AND img_postmeta.meta_key = '_wp_attachment_metadata' 36 LEFT JOIN ".$wpdb->prefix."term_relationships ON ".$wpdb->prefix."term_relationships.object_id = ".$wpdb->prefix."posts.ID 37 LEFT JOIN ".$wpdb->prefix."terms ON ".$wpdb->prefix."terms.term_id = ".$wpdb->prefix."term_relationships.term_taxonomy_id 38 LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."terms.term_id 39 ".$join." 40 WHERE ".$wpdb->prefix."posts.post_title LIKE %s AND ".$wpdb->prefix."posts.post_type = 'product' AND ".$wpdb->prefix."posts.post_status = 'publish' 41 AND ".$wpdb->prefix."term_taxonomy.taxonomy = 'product_cat'". $where; 42 43 44 if(isset($this->options['exclude_ids']) && !empty($this->options['exclude_ids'])){ 45 $sql .= "AND ".$wpdb->prefix."posts.id NOT IN (%s)"; 46 $prepare[] = $this->options['exclude_ids']; 47 } 48 if(isset($this->options['results_count']) && !empty($this->options['results_count'])){ 49 $this->count = $this->options['results_count']; 50 } 51 $sql .= " GROUP BY ".$wpdb->prefix."posts.ID LIMIT %d"; 52 53 $prepare[] = $this->count; 54 55 $results_prod = $wpdb->get_results($wpdb->prepare($sql, $prepare)); 56 57 $results_cat = array(); 58 if(isset($this->options['taxonomies_search']) && !empty($this->options['taxonomies_search']) && is_array($this->options['taxonomies_search'])){ 59 $results_cat = $this->get_taxonomies_search($sf_pa_search); 60 } 61 62 63 foreach($results_prod as $single_prod){ 64 $single_prod->img_url = $this->get_thumb_from_serialize($single_prod->img_url); 65 $single_prod->title = esc_html($single_prod->title); 66 $single_prod->cat_title = esc_html($single_prod->cat_title); 67 $single_prod->link = esc_url($this->build_link($single_prod->type, $single_prod->ID)); 68 $this->results[] = $single_prod; 69 } 70 71 foreach($results_cat as $single_cat){ 72 $single_cat->name = esc_html($single_cat->name); 73 $single_cat->link = esc_url($this->build_link($single_cat->type, false, $single_cat->taxonomy,$single_cat->slug )); 74 $this->results[] = $single_cat; 75 } 76 77 //LIMIT ARRAY TO MAX COUNT 78 if(is_int($this->count) && count($this->results) > $this->count){ 79 $this->results = array_slice($this->results, 0, $this->count); 80 } 81 82 $this->results = apply_filters('sf_pa_autosuggest_results', $this->results); 83 //Save data in transient for 24h 84 85 $transient_to_delete = get_transient('sf_pa_transient'); 86 if($transient_to_delete){ 87 $transient_to_delete[] = $sf_pa_search; 88 set_transient('sf_pa_transient', $transient_to_delete); 89 } 90 else{ 91 $transient_to_delete = array($sf_pa_search); 92 set_transient('sf_pa_transient', $transient_to_delete); 93 } 94 95 set_transient('sf_pa_'.$sf_pa_search, $this->results, 86400); 96 97 26 98 } 27 28 $sql = "SELECT ".$wpdb->prefix."posts.ID, ".$wpdb->prefix."posts.post_title as title, img_postmeta.meta_value as img_url, ".$wpdb->prefix."terms.name as cat_title, %s as show_cat, %s as show_thumbnail, 'product' AS type 29 FROM ".$wpdb->prefix."posts 30 LEFT JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."postmeta.post_id = ".$wpdb->prefix."posts.ID AND ".$wpdb->prefix."postmeta.meta_key = '_thumbnail_id' 31 LEFT JOIN ".$wpdb->prefix."postmeta as img_postmeta ON img_postmeta.post_id = ".$wpdb->prefix."postmeta.meta_value AND img_postmeta.meta_key = '_wp_attachment_metadata' 32 LEFT JOIN ".$wpdb->prefix."term_relationships ON ".$wpdb->prefix."term_relationships.object_id = ".$wpdb->prefix."posts.ID 33 LEFT JOIN ".$wpdb->prefix."terms ON ".$wpdb->prefix."terms.term_id = ".$wpdb->prefix."term_relationships.term_taxonomy_id 34 LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."terms.term_id 35 ".$join." 36 WHERE ".$wpdb->prefix."posts.post_title LIKE %s AND ".$wpdb->prefix."posts.post_type = 'product' AND ".$wpdb->prefix."posts.post_status = 'publish' 37 AND ".$wpdb->prefix."term_taxonomy.taxonomy = 'product_cat'". $where; 38 39 40 if(isset($this->options['exclude_ids']) && !empty($this->options['exclude_ids'])){ 41 $sql .= "AND ".$wpdb->prefix."posts.id NOT IN (%s)"; 42 $prepare[] = $this->options['exclude_ids']; 43 } 44 if(isset($this->options['results_count']) && !empty($this->options['results_count'])){ 45 $this->count = $this->options['results_count']; 46 } 47 $sql .= " GROUP BY ".$wpdb->prefix."posts.ID LIMIT %d"; 48 49 $prepare[] = $this->count; 50 51 $results_prod = $wpdb->get_results($wpdb->prepare($sql, $prepare)); 52 53 $results_cat = array(); 54 if(isset($this->options['taxonomies_search']) && !empty($this->options['taxonomies_search']) && is_array($this->options['taxonomies_search'])){ 55 $results_cat = $this->get_taxonomies_search($sf_pa_search); 99 else { 100 return $results; 56 101 } 57 102 58 59 foreach($results_prod as $single_prod){60 $single_prod->img_url = $this->get_thumb_from_serialize($single_prod->img_url);61 $single_prod->title = esc_html($single_prod->title);62 $single_prod->cat_title = esc_html($single_prod->cat_title);63 $single_prod->link = esc_url($this->build_link($single_prod->type, $single_prod->ID));64 $this->results[] = $single_prod;65 }66 67 foreach($results_cat as $single_cat){68 $single_cat->name = esc_html($single_cat->name);69 $single_cat->link = esc_url($this->build_link($single_cat->type, false, $single_cat->taxonomy,$single_cat->slug ));70 $this->results[] = $single_cat;71 }72 73 $this->results = apply_filters('sf_pa_autosuggest_results', $this->results);74 75 103 76 104 return $this->results; -
sf-autosuggest-product-search/trunk/sf_products_autosuggest.php
r2906136 r2911702 4 4 * Plugin URI: https://www.your-site.com/ 5 5 * Description: Autosuggest Product Search for Woocommerce 6 * Version: 1. 26 * Version: 1.3 7 7 * Author: Simone Fontana 8 8 * Author URI: https://www.simonefontana.net/ 9 * WC requires at least: 3.0.0 10 * WC tested up to: 7.7.0 9 11 **/ 10 12 … … 58 60 <form method="get" role="search" action="'.get_site_url().'"> 59 61 <input type="search" id="sf_pa_search_input" class="search-field" placeholder="'.esc_attr($placeholder).'" value="" name="s"> 62 <img class="sf_pa_loader" src="'.plugins_url().'/sf_products_autosuggest/assets/img/loading.gif"> 60 63 <input type="submit"> 61 64 </form>
Note: See TracChangeset
for help on using the changeset viewer.