Plugin Directory

Changeset 2911702


Ignore:
Timestamp:
05/12/2023 04:22:15 PM (3 years ago)
Author:
simonefontana
Message:

Update plugin version 1.3

Location:
sf-autosuggest-product-search
Files:
33 added
7 edited

Legend:

Unmodified
Added
Removed
  • sf-autosuggest-product-search/trunk/README.txt

    r2906136 r2911702  
    55Requires PHP: 7.0
    66Tested up to: 6.2
    7 Stable tag:1.2
     7Stable tag: 1.3
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.txt
     
    1313== Description ==
    1414
    15 SF Autosuggest Product Search is a plugin for add Woocommerce search Autosuggest to your ecommerce.
     15SF Autosuggest Product Search is a plugin for add Woocommerce search Autosuggest to your ecommerce.
     16With this Woocomerce search plugin you can improve products search and give a better experience to your users.
    1617It's very simple to add Autosuggest Product into your ecommerce.
    1718Choose your preference from SF Autosuggest Products settings.
     
    5455
    5556== Changelog ==
    56 = 1.1 =
    57 * Added sf_pa_autosuggest_results filter to filter results.
    58 * Added wpml compatibility
    59 * Added ability to customize "Show all results" text
     57
     58= 1.3 =
     59* Added loader in input search
     60* Save search data in transients for better performance
    6061
    6162= 1.2 =
     
    6465* Fix bug incorrect permalink
    6566
     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
    6672== Upgrade Notice ==
  • sf-autosuggest-product-search/trunk/assets/css/sf_pa.css

    r2870187 r2911702  
    5353    text-align: center;
    5454}
     55
     56img.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  
    33    function(){
    44        jQuery('#sf_pa_search_input').on('input', function(){
     5            var input_container = jQuery(this).closest('.sf_pa_search_input_container');
    56            if(jQuery(this).val().length > 2){
    67                if (postcall){
    78                    postcall.abort();
    89                }
     10                showLoader();
    911                jQuery('.sf_pa_autosuggest_response').remove();
    1012                jQuery('.sf_pa_autosuggest_container').remove();
     
    1618
    1719                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>');
    1922                    for (var i = 0; i < response.length; ++i) {
    2023                        var to_append = '<div class="sf_pa_autosuggest_response"><div>';
     
    5962    }
    6063);
     64
     65function showLoader(){
     66    jQuery('.sf_pa_loader').show();
     67}
     68
     69function hideLoader(){
     70    jQuery('.sf_pa_loader').hide();
     71}
  • sf-autosuggest-product-search/trunk/assets/js/sf_pa_admin.js

    r2870187 r2911702  
    11jQuery(document).ready(function($){
    22    $('.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    });
    313});
  • sf-autosuggest-product-search/trunk/classes/AdminClass.php

    r2906136 r2911702  
    55        add_action( 'admin_init', [$this, 'register_settings'] );
    66        add_action( 'admin_menu', [$this, 'add_settings_page'] );
     7        add_action( 'wp_ajax_delete_sf_pa_transient', [$this, 'delete_sf_pa_transient'] );
    78   }
    89
     
    2324                        <?php
    2425                        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>
    2632                        <input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Save', 'sf_products_autosuggest'); ?>" />
    2733                    </form>
     
    164170
    165171    public function taxonomies($params){
    166         /*TODO: multple choice*/
    167172        $options = get_option( 'sf_pa_autosuggest_plugin_options' );
    168173        $value = '';
     
    193198        $newinput['all_bg'] =  $validator->hexadecimal($input['all_bg'], '#000');
    194199        $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        }
    197206        $newinput['exclude_cat'] = $validator->ids($input['exclude_cat']);
    198207        $newinput['exclude_ids'] =  $validator->ids($input['exclude_ids']);
    199208        $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        }
    205215   
    206216        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;
    207236    }
    208237}
  • sf-autosuggest-product-search/trunk/classes/SearchClass.php

    r2906136 r2911702  
    1414        global $wpdb;
    1515
    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){
    1919
    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           
    2698        }
    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;
    56101        }
    57102       
    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 
    75103       
    76104        return $this->results;
  • sf-autosuggest-product-search/trunk/sf_products_autosuggest.php

    r2906136 r2911702  
    44* Plugin URI: https://www.your-site.com/
    55* Description: Autosuggest Product Search for Woocommerce
    6 * Version: 1.2
     6* Version: 1.3
    77* Author: Simone Fontana
    88* Author URI: https://www.simonefontana.net/
     9* WC requires at least: 3.0.0
     10* WC tested up to: 7.7.0
    911**/
    1012
     
    5860                <form method="get" role="search" action="'.get_site_url().'">
    5961                    <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">
    6063                    <input type="submit">
    6164                </form>
Note: See TracChangeset for help on using the changeset viewer.