Plugin Directory

Changeset 2005209


Ignore:
Timestamp:
01/02/2019 02:58:02 PM (7 years ago)
Author:
recomendo
Message:

1.0.5

Location:
recomendo/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • recomendo/trunk/README.txt

    r1967374 r2005209  
    33Tags: artificial intelligence, machine learning, related posts, recommendations, personalization
    44Requires at least: 4.7
    5 Tested up to: 4.9
     5Tested up to: 5.0
    66Requires PHP: 5.2.4
    77Stable tag: trunk
     
    125125
    126126== Changelog ==
     127= 1.0.5 =
     128* WordPress 5 tested
     129
     130* Fixed race condition while sending train requests
     131
     132* Configuration to allow Main Search engines to receive predictions to improve SEO
     133
    127134= 1.0.4 =
    128135* WooCommerce 3.5 tested
  • recomendo/trunk/recomendo-client.php

    r1967374 r2005209  
    3434                'Content-Type' => 'application/json',
    3535                'User-Agent' =>  $this->user_agent,
    36                 'Accept-Encoding' => 'gzip',
     36                'Accept-Encoding' => 'gzip',
    3737                'Authorization' => 'Bearer ' . $this->get_token()
    3838        );
     
    4141
    4242
    43     public function get_token( $client_id=false, $client_secret=false ) {
    44 
    45         if (! $client_id )
    46             $client_id = $this->client_id;
    47 
    48         if (! $client_secret )
    49             $client_secret = $this->client_secret;
    50 
    51         if ( false === ( $token = get_transient( 'recomendo_token' ) ) ) {
    52             $base_auth = base64_encode( $client_id . ':' . $client_secret );
    53             $headers = array( 'Authorization' => 'Basic ' . $base_auth );
    54             $response = wp_remote_post( self::AUTH_URL,
    55                             array(
    56                               'timeout' => self::TIMEOUT,
    57                               'httpversion' => self::HTTPVERSION,
    58                               'headers' => $headers
    59                             )
    60                         );
    61 
    62             if ( ! is_wp_error( $response ) ) {
    63                 $body = json_decode( $response['body'] );
    64                 $token = $body->payload->token;
    65                 set_transient( 'recomendo_token', $token , 3500 );
    66             }
    67         }
     43    public function get_token( $client_id=false, $client_secret=false ) {
     44
     45        if (! $client_id )
     46            $client_id = $this->client_id;
     47
     48        if (! $client_secret )
     49            $client_secret = $this->client_secret;
     50
     51        if ( false === ( $token = get_transient( 'recomendo_token' ) ) ) {
     52            $base_auth = base64_encode( $client_id . ':' . $client_secret );
     53            $headers = array( 'Authorization' => 'Basic ' . $base_auth );
     54            $response = wp_remote_post( self::AUTH_URL,
     55                            array(
     56                              'timeout' => self::TIMEOUT,
     57                              'httpversion' => self::HTTPVERSION,
     58                              'headers' => $headers
     59                            )
     60                        );
     61
     62            if ( ! is_wp_error( $response ) ) {
     63                $body = json_decode( $response['body'] );
     64                $token = $body->payload->token;
     65                set_transient( 'recomendo_token', $token , 3500 );
     66            }
     67        }
    6868
    6969        return $token;
    70     }
     70    }
    7171
    7272
     
    412412        $url = self::EVENTS_URL . ".json";
    413413
    414         $query_params = array();
     414        $query_params = array();
    415415
    416416        if ( !is_null( $start_time ) )
     
    441441            $query_params['reversed'] = $reversed;
    442442
    443         if (! empty( $query_params) )
    444             $url .= '?' . http_build_query( $query_params );
     443        if (! empty( $query_params) )
     444            $url .= '?' . http_build_query( $query_params );
    445445
    446446
     
    453453                    );
    454454
    455         return $response;
     455        return $response;
    456456
    457457    }
     
    483483    public function send_train_request() {
    484484
    485         if ( ! get_transient( 'recomendo_train_request_sent' ) )  {
    486 
    487             $url = 'https://client.recomendo.ai/v1/train';
    488 
    489             $response = wp_remote_post( $url,
    490                                        array(
    491                                            'timeout' => self::TIMEOUT,
    492                                            'httpversion' => self::HTTPVERSION,
    493                                            'headers' => $this->get_header()
    494                                         )
    495                                       );
    496 
    497             // It wasn't there, so regenerate the data and save the transient
    498             if ( ! is_wp_error( $response )) {
    499                 set_transient( 'recomendo_train_request_sent', true, 1800 );
     485        if ( ! get_transient( 'recomendo_train_request_sent' ) )  {
     486
     487            //  to prevent race condition,
     488            set_transient( 'recomendo_train_request_sent', true, 1800 );
     489
     490            $url = 'https://client.recomendo.ai/v1/train';
     491
     492            $response = wp_remote_post( $url,
     493                                       array(
     494                                           'timeout' => self::TIMEOUT,
     495                                           'httpversion' => self::HTTPVERSION,
     496                                           'headers' => $this->get_header()
     497                                        )
     498                                      );
     499
     500            // delete the transient if train request fails
     501            if ( is_wp_error( $response )) {
     502                delete_transient( 'recomendo_train_request_sent' );
    500503            }
    501504
    502         } else {
    503             // if transient exists we ignore sending train request, but record it as OK
    504             $response = array( 'response' => array( 'code' => 200, 'message' => 'OK' ) );
    505         }
    506 
    507         // Here we return the raw response!
    508         return $response;
     505        } else {
     506            // if transient exists we ignore sending train request, but record it as OK
     507            $response = array( 'response' => array( 'code' => 200, 'message' => 'OK' ) );
     508        }
     509
     510        // Here we return the raw response!
     511        return $response;
    509512
    510513    }
  • recomendo/trunk/recomendo-plugin.php

    r1967376 r2005209  
    1010
    1111        $this->options = $options;
    12         $this->woo_options = get_option( 'recomendo_woo_options' );
    13         $this->general_options = get_option( 'recomendo_general_options');
     12        $this->woo_options = get_option( 'recomendo_woo_options' );
     13        $this->general_options = get_option( 'recomendo_general_options');
    1414        // set up the hooks, actions and register styles, scripts, etc.
    1515        $this->register();
    1616        $this->client = new Recomendo_Client();
    1717
    18         $this->bg_user_copy = new Recomendo_Background_User_Copy();
    19         $this->bg_item_copy = new Recomendo_Background_Item_Copy();
    20         $this->bg_order_copy = new Recomendo_Background_Order_Copy();
     18        $this->bg_user_copy = new Recomendo_Background_User_Copy();
     19        $this->bg_item_copy = new Recomendo_Background_Item_Copy();
     20        $this->bg_order_copy = new Recomendo_Background_Order_Copy();
    2121
    2222    } // end of method -> __construct
     
    2626    public static function is_event_server_up() {
    2727
    28         // static function - need to initialize client
     28        // static function - need to initialize client
    2929        $client = new Recomendo_Client();
    3030
     
    8585        // Record add_to_cart events
    8686        add_action('woocommerce_add_cart_item_data', array( $this, 'record_add_to_cart_event' ), 10, 2);
    87         // Record Buy Event
     87        // Record Buy Event
    8888        add_action( 'woocommerce_thankyou', array( $this, 'record_buy_event' ) );
    89         // Record category_pref
     89        // Record category_pref
    9090        add_action( 'wp', array( $this, 'record_category_pref' ) );
    9191        // Register and load the widget
     
    9393        // Creates the [recomendo] shortcode
    9494        add_shortcode( 'recomendo', array( $this, 'show_shortcode' ) );
    95         // Show recommendations in WooCommerce related products
    96         if ( isset( $this->woo_options['woo_show_related'] ) )
    97             add_filter( 'woocommerce_related_products', array( $this, 'show_related_products' ), 10, 1);
     95        // Show recommendations in WooCommerce related products
     96        if ( isset( $this->woo_options['woo_show_related'] ) )
     97            add_filter( 'woocommerce_related_products', array( $this, 'show_related_products' ), 10, 1);
    9898        // Show recommendations in the cart
    9999        if ( isset( $this->woo_options['woo_show_cart'] ) )
     
    101101        // UPDATE PRODUCT IS FEATURED on  Woocommerce admin panel
    102102        if ( isset( $this->options['post_type'] ) && $this->options['post_type'] == 'product' ) {
    103                 add_action( 'woocommerce_product_set_visibility', array( $this, 'add_item' ), 10, 1 );
    104         }
     103                add_action( 'woocommerce_product_set_visibility', array( $this, 'add_item' ), 10, 1 );
     104        }
    105105
    106106    } //end of method
     
    123123        #if ( $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR'] ) return TRUE;
    124124
    125         if( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
    126                 $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_X_FORWARDED_FOR'] ;
    127         } else {
    128             $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'];
    129         }
     125        if( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
     126                $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_X_FORWARDED_FOR'] ;
     127        } else {
     128            $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'];
     129        }
    130130
    131131        $cookies_generated = get_transient( $transient );
     
    141141                                'facebook',
    142142                                'fetch',
    143                                 'amazon',
    144                                 'wordpress',
     143                                'amazon',
     144                                'wordpress',
    145145                                'wget',
    146                                 'go-http-client',
     146                                'go-http-client',
    147147                                'trustpilot'
    148148                                );
     
    157157    }
    158158
     159    public function is_robot_allowed() {
     160
     161        if ( ! isset( $this->general_options['allow_seo'] ) ) return FALSE;
     162
     163        // User lowercase string for comparison.
     164        $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     165
     166        $allowed_robots = array(
     167            'google',
     168            'bing',
     169            'yahoo',
     170            'duckduck',
     171            'baidu',
     172            'yandex'
     173        );
     174
     175        foreach ($allowed_robots as $robot) {
     176            if (strpos($user_agent, $robot) !== FALSE) {
     177                return TRUE;
     178            }
     179        }
     180
     181        return FALSE;
     182    }
    159183
    160184
     
    169193
    170194                if( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
    171                     $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_X_FORWARDED_FOR'] ;
    172                 } else {
    173                     $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'];
    174                 }
     195                    $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_X_FORWARDED_FOR'] ;
     196                } else {
     197                    $transient = 'recomendo_' . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'];
     198                }
    175199
    176200                $cookies_generated = get_transient( $transient );
     
    195219        $a = shortcode_atts( array(
    196220         'number' => 16,
    197         'type' => 'personalized',
    198         'template' => 'content-' . $this->options['post_type']
     221        'type' => 'personalized',
     222        'template' => 'content-' . $this->options['post_type']
    199223        ), $atts );
    200224
    201         // get the slug and name from the shortcode template arg
    202         $template = explode( '-', basename( $a['template'], '.php') );
    203         $template_slug = $template[0];
    204         $template_name = implode( '-', array_slice( $template, 1) );
    205 
    206         switch (  strtolower( $a['type'] ) ) {
     225        // get the slug and name from the shortcode template arg
     226        $template = explode( '-', basename( $a['template'], '.php') );
     227        $template_slug = $template[0];
     228        $template_name = implode( '-', array_slice( $template, 1) );
     229
     230        switch (  strtolower( $a['type'] ) ) {
    207231            case 'personalized' :
    208232                $response = $this->get_user_recommendations( intval( $a['number']));
     
    226250                $itemset_products = array();
    227251                if ( class_exists( 'woocommerce' ) ) {
    228                     global $woocommerce;
     252                    global $woocommerce;
    229253                    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    230254
     
    257281                }
    258282                break;
    259             case 'trending' :
     283            case 'trending' :
    260284                $response = $this->get_trending_items( intval( $a['number']));
    261285                break;
     
    263287        }
    264288
    265         if ( $response != false and array_key_exists( 'itemScores', $response ) ) {
    266             ob_start();
    267             if ( class_exists( 'woocommerce' ) ) {
    268                 woocommerce_product_loop_start();
    269                 foreach ($response['itemScores'] as $i ) {
    270                     if ( get_post_status ( $i['item'] ) == 'publish' ) {
    271                         $post_object = get_post( $i['item'] );
    272                         setup_postdata( $GLOBALS['post'] =& $post_object );
    273                         wc_get_template_part( $template_slug, $template_name );
    274                     }
    275                 }
    276                 woocommerce_product_loop_end();
    277             } else {
    278 
    279                 foreach ($response['itemScores'] as $i ) {
    280                     if ( get_post_status ( $i['item'] ) == 'publish' ) {
    281                         $post_object = get_post( $i['item'] );
    282                         setup_postdata( $GLOBALS['post'] =& $post_object );
    283                         // REPLACE by custom parameter
    284                         get_template_part( $template_slug, $template_name );
    285                     }
    286                 }
    287 
    288             }
    289 
    290             wp_reset_postdata();
    291             $output = ob_get_clean();
    292             return $output;
    293         }
     289        if ( $response != false and array_key_exists( 'itemScores', $response ) ) {
     290            ob_start();
     291            if ( class_exists( 'woocommerce' ) ) {
     292                woocommerce_product_loop_start();
     293                foreach ($response['itemScores'] as $i ) {
     294                    if ( get_post_status ( $i['item'] ) == 'publish' ) {
     295                        $post_object = get_post( $i['item'] );
     296                        setup_postdata( $GLOBALS['post'] =& $post_object );
     297                        wc_get_template_part( $template_slug, $template_name );
     298                    }
     299                }
     300                woocommerce_product_loop_end();
     301            } else {
     302
     303                foreach ($response['itemScores'] as $i ) {
     304                    if ( get_post_status ( $i['item'] ) == 'publish' ) {
     305                        $post_object = get_post( $i['item'] );
     306                        setup_postdata( $GLOBALS['post'] =& $post_object );
     307                        // REPLACE by custom parameter
     308                        get_template_part( $template_slug, $template_name );
     309                    }
     310                }
     311
     312            }
     313
     314            wp_reset_postdata();
     315            $output = ob_get_clean();
     316            return $output;
     317        }
    294318
    295319
     
    297321
    298322
    299     // Shows recommendations in the WooCommerce Related Products area
    300     public function show_related_products( $args ) {
    301 
    302         global $product;
    303 
    304         $resp = $this->get_item_recommendations( $product->get_id(), intval( $this->woo_options['woo_num_related'] ) );
    305 
    306         if ( $resp != false and array_key_exists( 'itemScores', $resp ) ) {
    307             $related_products = array();
    308             foreach ($resp['itemScores'] as $i ) {
    309                 //$related_products[] = wc_get_product( $i['item'] );
    310                 $related_products[] = $i['item'] ;
    311             }
    312             $args = $related_products;
    313         }
    314         return $args;
    315     } // end of method --> show_related_products
     323    // Shows recommendations in the WooCommerce Related Products area
     324    public function show_related_products( $args ) {
     325
     326        global $product;
     327
     328        $resp = $this->get_item_recommendations( $product->get_id(), intval( $this->woo_options['woo_num_related'] ) );
     329
     330        if ( $resp != false and array_key_exists( 'itemScores', $resp ) ) {
     331            $related_products = array();
     332            foreach ($resp['itemScores'] as $i ) {
     333                //$related_products[] = wc_get_product( $i['item'] );
     334                $related_products[] = $i['item'] ;
     335            }
     336            $args = $related_products;
     337        }
     338        return $args;
     339    } // end of method --> show_related_products
    316340
    317341
     
    323347        $defaults = array(
    324348            'posts_per_page' => intval($this->woo_options['woo_num_cart']),
    325             'title' => $this->woo_options['woo_cart_title']
     349            'title' => $this->woo_options['woo_cart_title']
    326350        );
    327351
     
    368392                wc_get_template_part( 'content', 'product' );
    369393            }
    370             echo '</section>';
     394            echo '</section>';
    371395            woocommerce_product_loop_end();
    372             wp_reset_postdata();
     396            wp_reset_postdata();
    373397
    374398        }
     
    381405
    382406        if ( class_exists( 'woocommerce' ) &&
    383             $this->options['post_type'] == 'product'  &&
    384             isset( $this->woo_options['woo_exclude_outofstock'] ) ) {
    385 
    386             $args = array(
     407            $this->options['post_type'] == 'product'  &&
     408            isset( $this->woo_options['woo_exclude_outofstock'] ) ) {
     409
     410            $args = array(
    387411                'post_type' => 'product',
    388412                'fields' => 'ids',
     
    438462
    439463    // returns trending items. This is a fallback for other recommendations.
    440     // when no user, item or complementary recommendations are found, trending items are returned
    441     public function get_trending_items( $number ) {
     464    // when no user, item or complementary recommendations are found, trending items are returned
     465    public function get_trending_items( $number ) {
    442466
    443467        //ignore bots and crawlers
    444         if ( $this->detect_crawler() ) return false;
    445 
    446         $query = array(
     468        if ( $this->detect_crawler() and ! $this->is_robot_allowed() ) return false;
     469
     470        $query = array(
    447471            'num' => $number
    448472        );
     
    450474        $query['blacklistItems'] = $this->get_excluded_items();
    451475
    452         if ( isset ( $this->general_options['expire_date'] ) &&
    453             $this->general_options['expire_date'] != 0 ) {
    454 
    455                 $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
    456                 $query['dateRange'] = array(
    457                     'name' => 'published_date',
    458                     'after' => $after_date
    459                 );
    460 
    461         }
     476        if ( isset ( $this->general_options['expire_date'] ) &&
     477            $this->general_options['expire_date'] != 0 ) {
     478
     479                $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
     480                $query['dateRange'] = array(
     481                    'name' => 'published_date',
     482                    'after' => $after_date
     483                );
     484
     485        }
    462486
    463487        $response = $this->client->send_query( $query );
     
    497521
    498522
    499     private function map_range_input_to_bias( $value ) {
    500         if ( intval($value) == -1 ) return 0.0; // exclude
    501         if ( intval($value) == 0 ) return 0.5; // less importance
    502         if ( intval($value) == 1 ) return 1.0;  // neutral
    503         if ( intval($value) == 2 ) return 1.5; // more importance
    504         if ( intval($value) == 3) return -1.0;  // Include only
    505     }
     523    private function map_range_input_to_bias( $value ) {
     524        if ( intval($value) == -1 ) return 0.0; // exclude
     525        if ( intval($value) == 0 ) return 0.5; // less importance
     526        if ( intval($value) == 1 ) return 1.0;  // neutral
     527        if ( intval($value) == 2 ) return 1.5; // more importance
     528        if ( intval($value) == 3) return -1.0;  // Include only
     529    }
    506530
    507531    // Recomendo user based recommendations
     
    510534
    511535        //ignore bots and crawlers
    512         if ( $this->detect_crawler() ) return false;
     536        if ( $this->detect_crawler() and ! $this->is_robot_allowed() ) return false;
    513537
    514538        if ( get_current_user_id() == 0 ) {
    515             $userid = $_COOKIE['recomendo-cookie-user'];
     539            $userid = $_COOKIE['recomendo-cookie-user'];
    516540        } else {
    517541            $userid = get_current_user_id();
    518542        }
    519543
    520         $fields = array();
    521 
    522         if ( isset(  $this->woo_options['woo_onsale_relevance'] ) ) {
    523 
    524                 $on_sale_bias = $this->map_range_input_to_bias(
    525                     $this->woo_options['woo_onsale_relevance'] );
    526 
    527                 // we ignore neutral and dont add it to the query
    528                 if ( $on_sale_bias != 1.0 ) {
    529                     // less importance boost "no" instead
    530                     if ( $on_sale_bias == 0.5 ) {
    531                         $on_sale_args = array(
    532                             'name' => 'is_on_sale',
    533                             'values' => ['no'],
    534                             'bias' => 1.5
    535                         );
    536                     } else {
    537                         $on_sale_args = array(
    538                             'name' => 'is_on_sale',
    539                             'values' => ['yes'],
    540                             'bias' => $on_sale_bias
    541                         );
    542                     }
    543 
    544                     $fields[] = $on_sale_args;
    545                 }
    546 
    547         }
    548 
    549         if ( isset(  $this->woo_options['woo_featured_relevance'] ) ) {
    550                 $featured_bias = $this->map_range_input_to_bias(
    551                     $this->woo_options['woo_featured_relevance'] );
    552 
    553                 // we ignore neutral and dont add it to the query
    554                 if ( $featured_bias != 1.0 ) {
    555                     // less importance boost "no" instead
    556                     if ( $featured_bias == 0.5 ) {
    557                         $featured_args = array(
    558                             'name' => 'is_featured',
    559                             'values' => ['no'],
    560                             'bias' => 1.5
    561                         );
    562                     } else {
    563                         $featured_args = array(
    564                             'name' => 'is_featured',
    565                             'values' => ['yes'],
    566                             'bias' => $featured_bias
    567                         );
    568 
    569                     }
    570 
    571                     $fields[] = $featured_args;
    572 
    573                 }
    574 
    575         }
     544        $fields = array();
     545
     546        if ( isset(  $this->woo_options['woo_onsale_relevance'] ) ) {
     547
     548                $on_sale_bias = $this->map_range_input_to_bias(
     549                    $this->woo_options['woo_onsale_relevance'] );
     550
     551                // we ignore neutral and dont add it to the query
     552                if ( $on_sale_bias != 1.0 ) {
     553                    // less importance boost "no" instead
     554                    if ( $on_sale_bias == 0.5 ) {
     555                        $on_sale_args = array(
     556                            'name' => 'is_on_sale',
     557                            'values' => ['no'],
     558                            'bias' => 1.5
     559                        );
     560                    } else {
     561                        $on_sale_args = array(
     562                            'name' => 'is_on_sale',
     563                            'values' => ['yes'],
     564                            'bias' => $on_sale_bias
     565                        );
     566                    }
     567
     568                    $fields[] = $on_sale_args;
     569                }
     570
     571        }
     572
     573        if ( isset(  $this->woo_options['woo_featured_relevance'] ) ) {
     574                $featured_bias = $this->map_range_input_to_bias(
     575                    $this->woo_options['woo_featured_relevance'] );
     576
     577                // we ignore neutral and dont add it to the query
     578                if ( $featured_bias != 1.0 ) {
     579                    // less importance boost "no" instead
     580                    if ( $featured_bias == 0.5 ) {
     581                        $featured_args = array(
     582                            'name' => 'is_featured',
     583                            'values' => ['no'],
     584                            'bias' => 1.5
     585                        );
     586                    } else {
     587                        $featured_args = array(
     588                            'name' => 'is_featured',
     589                            'values' => ['yes'],
     590                            'bias' => $featured_bias
     591                        );
     592
     593                    }
     594
     595                    $fields[] = $featured_args;
     596
     597                }
     598
     599        }
    576600
    577601        $query = array(
    578602            'user' => $userid,
    579603            'num' => $number,
    580             'fields' => $fields
    581         );
    582 
    583         if ( isset ( $this->general_options['expire_date'] ) &&
    584             $this->general_options['expire_date'] != 0 ) {
    585 
    586                 $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
    587                 $query['dateRange'] = array(
    588                     'name' => 'published_date',
    589                     'after' => $after_date
    590                 );
    591         }
     604            'fields' => $fields
     605        );
     606
     607        if ( isset ( $this->general_options['expire_date'] ) &&
     608            $this->general_options['expire_date'] != 0 ) {
     609
     610                $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
     611                $query['dateRange'] = array(
     612                    'name' => 'published_date',
     613                    'after' => $after_date
     614                );
     615        }
    592616
    593617        $query['blacklistItems'] = $this->get_excluded_items();
     
    636660
    637661        //ignore bots and crawlers
    638         if ( $this->detect_crawler() ) return false;
     662        if ( $this->detect_crawler() and ! $this->is_robot_allowed() ) return false;
    639663
    640664
     
    649673        }
    650674
    651         // Apply the Similar Categories Bias/Boost to the query
    652         if ( isset(  $this->general_options['similar_categories_relevance'] ) ) {
    653 
    654             $same_categories_bias = $this->map_range_input_to_bias(
    655                     $this->general_options['similar_categories_relevance'] );
    656 
    657             // we ignore neutral and dont add it to the query
    658             if ( $same_categories_bias != 1.0 ) {
    659 
    660                 $categories = array();
    661 
    662                 // get the categories to boost
    663                 if ( class_exists( 'woocommerce' ) ) {
    664                     $terms = get_the_terms( $item, 'product_cat' );
    665                 } else {
    666                     $terms = get_the_terms( $item, 'category' );
    667                 }
    668 
    669                 if (is_array($terms) or is_object($terms)) {
    670                     foreach ($terms as $term) {
    671                         $categories[] = (string) $term->term_id;
    672                     }
    673 
    674                     $similar_categories_args = array(
    675                         'name' => 'categories',
    676                         'values' => $categories,
    677                         'bias' => $same_categories_bias
    678                     );
    679 
    680                     $fields[] = $similar_categories_args;
    681                 }
    682             }
    683 
    684 
    685         }
    686 
    687         // Apply the Similar Tags Bias/Boost to the query
    688         if ( isset(  $this->general_options['similar_tags_relevance'] ) ) {
    689 
    690             $same_tags_bias = $this->map_range_input_to_bias(
    691                     $this->general_options['similar_tags_relevance'] );
    692 
    693             // we ignore neutral and dont add it to the query
    694             if ( $same_tags_bias != 1.0 ) {
    695 
    696                 $tags = array();
    697 
    698                 // get the tags to boost
    699                 if ( class_exists( 'woocommerce' ) ) {
    700                     $taglist = get_the_terms( $item, 'product_tag' );
    701                 } else {
    702                     $taglist = get_the_tags( $item );
    703                 }
    704 
    705 
    706                 if (is_array($taglist) or is_object($taglist)) {
    707                     foreach ($taglist as $tagitem) {
    708                         $tags[] = (string) $tagitem->term_id;
    709                     }
    710 
    711                     $similar_tags_args = array(
    712                         'name' => 'tags',
    713                         'values' => $tags,
    714                         'bias' => $same_tags_bias
    715                     );
    716 
    717                     $fields[] = $similar_tags_args;
    718 
    719                 }
    720 
    721             }
    722 
    723 
    724         }
    725 
    726         // Apply Boost-Bias to Items on Sale
    727         if ( isset(  $this->woo_options['woo_onsale_relevance'] ) ) {
    728 
    729             $on_sale_bias = $this->map_range_input_to_bias(
    730                 $this->woo_options['woo_onsale_relevance'] );
    731 
    732             // we ignore neutral and dont add it to the query
    733             if ( $on_sale_bias != 1.0 ) {
    734                 // less importance boost "no" instead
    735                 if ( $on_sale_bias == 0.5 ) {
    736                     $on_sale_args = array(
    737                         'name' => 'is_on_sale',
    738                         'values' => ['no'],
    739                         'bias' => 1.5
    740                     );
    741                 } else {
    742                     $on_sale_args = array(
    743                         'name' => 'is_on_sale',
    744                         'values' => ['yes'],
    745                         'bias' => $on_sale_bias
    746                     );
    747                 }
    748 
    749                 $fields[] = $on_sale_args;
    750             }
    751 
    752         }
    753 
    754         // Apply Boost-Bias to Featured Items
    755         if ( isset(  $this->woo_options['woo_featured_relevance'] ) ) {
    756             $featured_bias = $this->map_range_input_to_bias(
    757                 $this->woo_options['woo_featured_relevance'] );
    758 
    759             // we ignore neutral and dont add it to the query
    760             if ( $featured_bias != 1.0 ) {
    761                 // less importance boost "no" instead
    762                 if ( $featured_bias == 0.5 ) {
    763                     $featured_args = array(
    764                         'name' => 'is_featured',
    765                         'values' => ['no'],
    766                         'bias' => 1.5
    767                     );
    768                 } else {
    769                     $featured_args = array(
    770                         'name' => 'is_featured',
    771                         'values' => ['yes'],
    772                         'bias' => $featured_bias
    773                     );
    774 
    775                 }
    776 
    777                 $fields[] = $featured_args;
    778             }
    779         }
     675        // Apply the Similar Categories Bias/Boost to the query
     676        if ( isset(  $this->general_options['similar_categories_relevance'] ) ) {
     677
     678            $same_categories_bias = $this->map_range_input_to_bias(
     679                    $this->general_options['similar_categories_relevance'] );
     680
     681            // we ignore neutral and dont add it to the query
     682            if ( $same_categories_bias != 1.0 ) {
     683
     684                $categories = array();
     685
     686                // get the categories to boost
     687                if ( class_exists( 'woocommerce' ) ) {
     688                    $terms = get_the_terms( $item, 'product_cat' );
     689                } else {
     690                    $terms = get_the_terms( $item, 'category' );
     691                }
     692
     693                if (is_array($terms) or is_object($terms)) {
     694                    foreach ($terms as $term) {
     695                        $categories[] = (string) $term->term_id;
     696                    }
     697
     698                    $similar_categories_args = array(
     699                        'name' => 'categories',
     700                        'values' => $categories,
     701                        'bias' => $same_categories_bias
     702                    );
     703
     704                    $fields[] = $similar_categories_args;
     705                }
     706            }
     707
     708
     709        }
     710
     711        // Apply the Similar Tags Bias/Boost to the query
     712        if ( isset(  $this->general_options['similar_tags_relevance'] ) ) {
     713
     714            $same_tags_bias = $this->map_range_input_to_bias(
     715                    $this->general_options['similar_tags_relevance'] );
     716
     717            // we ignore neutral and dont add it to the query
     718            if ( $same_tags_bias != 1.0 ) {
     719
     720                $tags = array();
     721
     722                // get the tags to boost
     723                if ( class_exists( 'woocommerce' ) ) {
     724                    $taglist = get_the_terms( $item, 'product_tag' );
     725                } else {
     726                    $taglist = get_the_tags( $item );
     727                }
     728
     729
     730                if (is_array($taglist) or is_object($taglist)) {
     731                    foreach ($taglist as $tagitem) {
     732                        $tags[] = (string) $tagitem->term_id;
     733                    }
     734
     735                    $similar_tags_args = array(
     736                        'name' => 'tags',
     737                        'values' => $tags,
     738                        'bias' => $same_tags_bias
     739                    );
     740
     741                    $fields[] = $similar_tags_args;
     742
     743                }
     744
     745            }
     746
     747
     748        }
     749
     750        // Apply Boost-Bias to Items on Sale
     751        if ( isset(  $this->woo_options['woo_onsale_relevance'] ) ) {
     752
     753            $on_sale_bias = $this->map_range_input_to_bias(
     754                $this->woo_options['woo_onsale_relevance'] );
     755
     756            // we ignore neutral and dont add it to the query
     757            if ( $on_sale_bias != 1.0 ) {
     758                // less importance boost "no" instead
     759                if ( $on_sale_bias == 0.5 ) {
     760                    $on_sale_args = array(
     761                        'name' => 'is_on_sale',
     762                        'values' => ['no'],
     763                        'bias' => 1.5
     764                    );
     765                } else {
     766                    $on_sale_args = array(
     767                        'name' => 'is_on_sale',
     768                        'values' => ['yes'],
     769                        'bias' => $on_sale_bias
     770                    );
     771                }
     772
     773                $fields[] = $on_sale_args;
     774            }
     775
     776        }
     777
     778        // Apply Boost-Bias to Featured Items
     779        if ( isset(  $this->woo_options['woo_featured_relevance'] ) ) {
     780            $featured_bias = $this->map_range_input_to_bias(
     781                $this->woo_options['woo_featured_relevance'] );
     782
     783            // we ignore neutral and dont add it to the query
     784            if ( $featured_bias != 1.0 ) {
     785                // less importance boost "no" instead
     786                if ( $featured_bias == 0.5 ) {
     787                    $featured_args = array(
     788                        'name' => 'is_featured',
     789                        'values' => ['no'],
     790                        'bias' => 1.5
     791                    );
     792                } else {
     793                    $featured_args = array(
     794                        'name' => 'is_featured',
     795                        'values' => ['yes'],
     796                        'bias' => $featured_bias
     797                    );
     798
     799                }
     800
     801                $fields[] = $featured_args;
     802            }
     803        }
    780804
    781805        $query = array(
     
    785809        );
    786810
    787         if ( isset ( $this->general_options['expire_date'] ) &&
    788             $this->general_options['expire_date'] != 0 ) {
    789 
    790                 $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
    791                 $query['dateRange'] = array(
    792                     'name' => 'published_date',
    793                     'after' => $after_date
    794                 );
    795 
    796         }
     811        if ( isset ( $this->general_options['expire_date'] ) &&
     812            $this->general_options['expire_date'] != 0 ) {
     813
     814                $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
     815                $query['dateRange'] = array(
     816                    'name' => 'published_date',
     817                    'after' => $after_date
     818                );
     819
     820        }
    797821
    798822        $query['blacklistItems'] = $this->get_excluded_items();
     
    842866
    843867        //ignore bots and crawlers
    844         if ( $this->detect_crawler() ) return false;
    845 
    846 
    847         $fields = array();
    848 
    849         if ( isset(  $this->woo_options['woo_onsale_relevance'] ) ) {
    850 
    851             $on_sale_bias = $this->map_range_input_to_bias(
    852                 $this->woo_options['woo_onsale_relevance'] );
    853 
    854             // we ignore neutral and dont add it to the query
    855             if ( $on_sale_bias != 1.0 ) {
    856                 // less importance boost "no" instead
    857                 if ( $on_sale_bias == 0.5 ) {
    858                     $on_sale_args = array(
    859                         'name' => 'is_on_sale',
    860                         'values' => ['no'],
    861                         'bias' => 1.5
    862                     );
    863                 } else {
    864                     $on_sale_args = array(
    865                         'name' => 'is_on_sale',
    866                         'values' => ['yes'],
    867                         'bias' => $on_sale_bias
    868                     );
    869                 }
    870 
    871                 $fields[] = $on_sale_args;
    872             }
    873 
    874         }
    875 
    876         if ( isset(  $this->woo_options['woo_featured_relevance'] ) ) {
    877                 $featured_bias = $this->map_range_input_to_bias(
    878                     $this->woo_options['woo_featured_relevance'] );
    879 
    880                 // we ignore neutral and dont add it to the query
    881                 if ( $featured_bias != 1.0 ) {
    882                     // less importance boost "no" instead
    883                     if ( $featured_bias == 0.5 ) {
    884                         $featured_args = array(
    885                             'name' => 'is_featured',
    886                             'values' => ['no'],
    887                             'bias' => 1.5
    888                         );
    889                     } else {
    890                         $featured_args = array(
    891                             'name' => 'is_featured',
    892                             'values' => ['yes'],
    893                             'bias' => $featured_bias
    894                         );
    895 
    896                     }
    897 
    898                     $fields[] = $featured_args;
    899 
    900                 }
    901 
    902         }
     868        if ( $this->detect_crawler() and ! $this->is_robot_allowed() ) return false;
     869
     870
     871        $fields = array();
     872
     873        if ( isset(  $this->woo_options['woo_onsale_relevance'] ) ) {
     874
     875            $on_sale_bias = $this->map_range_input_to_bias(
     876                $this->woo_options['woo_onsale_relevance'] );
     877
     878            // we ignore neutral and dont add it to the query
     879            if ( $on_sale_bias != 1.0 ) {
     880                // less importance boost "no" instead
     881                if ( $on_sale_bias == 0.5 ) {
     882                    $on_sale_args = array(
     883                        'name' => 'is_on_sale',
     884                        'values' => ['no'],
     885                        'bias' => 1.5
     886                    );
     887                } else {
     888                    $on_sale_args = array(
     889                        'name' => 'is_on_sale',
     890                        'values' => ['yes'],
     891                        'bias' => $on_sale_bias
     892                    );
     893                }
     894
     895                $fields[] = $on_sale_args;
     896            }
     897
     898        }
     899
     900        if ( isset(  $this->woo_options['woo_featured_relevance'] ) ) {
     901                $featured_bias = $this->map_range_input_to_bias(
     902                    $this->woo_options['woo_featured_relevance'] );
     903
     904                // we ignore neutral and dont add it to the query
     905                if ( $featured_bias != 1.0 ) {
     906                    // less importance boost "no" instead
     907                    if ( $featured_bias == 0.5 ) {
     908                        $featured_args = array(
     909                            'name' => 'is_featured',
     910                            'values' => ['no'],
     911                            'bias' => 1.5
     912                        );
     913                    } else {
     914                        $featured_args = array(
     915                            'name' => 'is_featured',
     916                            'values' => ['yes'],
     917                            'bias' => $featured_bias
     918                        );
     919
     920                    }
     921
     922                    $fields[] = $featured_args;
     923
     924                }
     925
     926        }
    903927
    904928        $query = array(
    905929            'itemSet'=> $items,
    906930            'num'=> $number,
    907             'fields' => $fields
     931            'fields' => $fields
    908932        );
    909933
    910934        $query['blacklistItems'] = $this->get_excluded_items();
    911935
    912         if ( isset ( $this->general_options['expire_date'] ) &&
    913             $this->general_options['expire_date'] != 0 ) {
    914 
    915                 $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
    916                 $query['dateRange'] = array(
    917                     'name' => 'published_date',
    918                     'after' => $after_date
    919                 );
    920 
    921         }
     936        if ( isset ( $this->general_options['expire_date'] ) &&
     937            $this->general_options['expire_date'] != 0 ) {
     938
     939                $after_date = date('c', strtotime('-' . $this->general_options['expire_date'] . ' days' ) );
     940                $query['dateRange'] = array(
     941                    'name' => 'published_date',
     942                    'after' => $after_date
     943                );
     944
     945        }
    922946
    923947        $response = $this->client->send_query( $query );
     
    9791003
    9801004
    981     // Add all users using background processing
    982     public function add_all_users_background() {
    983 
    984         $args = array(
     1005    // Add all users using background processing
     1006    public function add_all_users_background() {
     1007
     1008        $args = array(
    9851009            'fields'       => 'ids',
    9861010            'numberposts' => -1
     
    9921016
    9931017        foreach ( $user_ids as $id ) {
    994             $this->bg_user_copy->push_to_queue( $id );
    995         }
    996 
    997         $this->bg_user_copy->save()->dispatch();
    998 
    999     } //end-of-method add_all_users_background()
     1018            $this->bg_user_copy->push_to_queue( $id );
     1019        }
     1020
     1021        $this->bg_user_copy->save()->dispatch();
     1022
     1023    } //end-of-method add_all_users_background()
    10001024
    10011025
     
    10141038    public function add_item( $postid ) {
    10151039
    1016         // Check if WPML is installed and get the id of the original language post (not translation)
    1017         if ( function_exists('icl_object_id') ) {
    1018             global $sitepress;
    1019             $postid = icl_object_id( $postid, $this->options['post_type'], true, $sitepress->get_default_language() );
    1020         }
    1021 
    1022 
    1023         if ( class_exists( 'woocommerce' ) ) {
    1024             $terms = get_the_terms( $postid, 'product_cat' );
    1025             $taglist = get_the_terms( $postid, 'product_tag' );
    1026             $product = wc_get_product( $postid );
    1027             // item on sale !
    1028             $is_on_sale = array($product->is_on_sale() ? "yes" : "no" );
    1029             // Featured item
    1030             $is_featured = array($product->is_featured() ? "yes" : "no" );
    1031         } else {
    1032             $terms = get_the_terms( $postid, 'category' );
    1033             $taglist = get_the_tags( $postid );
    1034             $is_on_sale = array("no"); //false
    1035             $is_featured = array("no");    //false
    1036         }
    1037 
    1038         $title =  wp_filter_nohtml_kses( get_the_title( $postid ) );
    1039 
    1040         $categories = array();
    1041         if (is_array($terms) or is_object($terms)) {
    1042             foreach ($terms as $term) {
    1043                 $categories[] = (string) $term->term_id;
    1044             }
    1045         }
    1046 
    1047         $tags = array();
    1048         if (is_array($taglist) or is_object($taglist)) {
    1049             foreach ($taglist as $tagitem) {
    1050                 $tags[] = (string) $tagitem->term_id;
    1051             }
    1052         }
    1053 
    1054         $published_date = get_the_date( 'c', $postid );
    1055 
    1056         $properties = compact(
    1057             'title',
    1058             'categories',
    1059             'tags',
    1060             'is_on_sale',
    1061             'is_featured',
    1062             'published_date'
    1063 
    1064         );
    1065 
    1066         $response = $this->client->set_item($postid, $properties);
    1067 
    1068         if ( !is_wp_error( $response ) ) {
    1069             $response = $this->client->send_train_request();
    1070 
    1071             if ( is_wp_error( $response ) ) {
    1072                 error_log( "[RECOMENDO] --- Error sending train request after adding item." );
    1073                 error_log( "[RECOMENDO] --- " . $response->get_error_message() );
    1074             }
    1075         } else {
    1076             error_log( "[RECOMENDO] --- Error adding an item." );
    1077             error_log( "[RECOMENDO] --- " . $response->get_error_message() );
    1078         }
     1040        // Check if WPML is installed and get the id of the original language post (not translation)
     1041        if ( function_exists('icl_object_id') ) {
     1042            global $sitepress;
     1043            $postid = icl_object_id( $postid, $this->options['post_type'], true, $sitepress->get_default_language() );
     1044        }
     1045
     1046
     1047        if ( class_exists( 'woocommerce' ) ) {
     1048            $terms = get_the_terms( $postid, 'product_cat' );
     1049            $taglist = get_the_terms( $postid, 'product_tag' );
     1050            $product = wc_get_product( $postid );
     1051            // item on sale !
     1052            $is_on_sale = array($product->is_on_sale() ? "yes" : "no" );
     1053            // Featured item
     1054            $is_featured = array($product->is_featured() ? "yes" : "no" );
     1055        } else {
     1056            $terms = get_the_terms( $postid, 'category' );
     1057            $taglist = get_the_tags( $postid );
     1058            $is_on_sale = array("no"); //false
     1059            $is_featured = array("no");    //false
     1060        }
     1061
     1062        $title =  wp_filter_nohtml_kses( get_the_title( $postid ) );
     1063
     1064        $categories = array();
     1065        if (is_array($terms) or is_object($terms)) {
     1066            foreach ($terms as $term) {
     1067                $categories[] = (string) $term->term_id;
     1068            }
     1069        }
     1070
     1071        $tags = array();
     1072        if (is_array($taglist) or is_object($taglist)) {
     1073            foreach ($taglist as $tagitem) {
     1074                $tags[] = (string) $tagitem->term_id;
     1075            }
     1076        }
     1077
     1078        $published_date = get_the_date( 'c', $postid );
     1079
     1080        $properties = compact(
     1081            'title',
     1082            'categories',
     1083            'tags',
     1084            'is_on_sale',
     1085            'is_featured',
     1086            'published_date'
     1087
     1088        );
     1089
     1090        $response = $this->client->set_item($postid, $properties);
     1091
     1092        if ( !is_wp_error( $response ) ) {
     1093            $response = $this->client->send_train_request();
     1094
     1095            if ( is_wp_error( $response ) ) {
     1096                error_log( "[RECOMENDO] --- Error sending train request after adding item." );
     1097                error_log( "[RECOMENDO] --- " . $response->get_error_message() );
     1098            }
     1099        } else {
     1100            error_log( "[RECOMENDO] --- Error adding an item." );
     1101            error_log( "[RECOMENDO] --- " . $response->get_error_message() );
     1102        }
    10791103
    10801104
     
    10831107
    10841108
    1085     public function add_all_items_background() {
    1086 
    1087         //$options = get_option( 'recomendo_options ' );
    1088 
    1089         $args = array(
     1109    public function add_all_items_background() {
     1110
     1111        //$options = get_option( 'recomendo_options ' );
     1112
     1113        $args = array(
    10901114            'post_type' => $this->options['post_type'],
    10911115            'fields' => 'ids',
     
    10991123        $post_ids = get_posts( $args );
    11001124
    1101         foreach ($post_ids as $id) {
    1102             $this->bg_item_copy->push_to_queue( $id );
    1103         }
    1104 
    1105         $this->bg_item_copy->save()->dispatch();
    1106 
    1107     } //end-of-method add_all_items_background()
     1125        foreach ($post_ids as $id) {
     1126            $this->bg_item_copy->push_to_queue( $id );
     1127        }
     1128
     1129        $this->bg_item_copy->save()->dispatch();
     1130
     1131    } //end-of-method add_all_items_background()
    11081132
    11091133
     
    11551179        if ( is_singular( $this->options['post_type'] ) ) {
    11561180
    1157             if ( get_current_user_id() == 0 ) {
    1158                 $userid = $_COOKIE['recomendo-cookie-user'];
    1159             } else {
    1160                 $userid = get_current_user_id();
    1161             }
     1181            if ( get_current_user_id() == 0 ) {
     1182                $userid = $_COOKIE['recomendo-cookie-user'];
     1183            } else {
     1184                $userid = get_current_user_id();
     1185            }
    11621186
    11631187            // Check if registered user does not want user behaviour to be tracked
     
    11901214
    11911215
    1192     // Send category-pref
     1216    // Send category-pref
    11931217    public function record_category_pref() {
    11941218
     
    11981222        }
    11991223
    1200         if ( is_category() or is_tax() or is_tag() ) {
    1201 
    1202             $queried_object = get_queried_object();
    1203 
    1204             $term_id = $queried_object->term_id ;
    1205             $term_type = $queried_object->name ;
    1206 
    1207 
    1208             if ( get_current_user_id() == 0 ) {
    1209                 $userid = $_COOKIE['recomendo-cookie-user'];
    1210             } else {
    1211                 $userid = get_current_user_id();
    1212             }
     1224        if ( is_category() or is_tax() or is_tag() ) {
     1225
     1226            $queried_object = get_queried_object();
     1227
     1228            $term_id = $queried_object->term_id ;
     1229            $term_type = $queried_object->name ;
     1230
     1231
     1232            if ( get_current_user_id() == 0 ) {
     1233                $userid = $_COOKIE['recomendo-cookie-user'];
     1234            } else {
     1235                $userid = get_current_user_id();
     1236            }
    12131237
    12141238            // Check if registered user does not want user behaviour to be tracked
     
    12461270        }
    12471271
    1248         if ( get_current_user_id() == 0 ) {
    1249             $userid = $_COOKIE['recomendo-cookie-user'];
     1272        if ( get_current_user_id() == 0 ) {
     1273            $userid = $_COOKIE['recomendo-cookie-user'];
    12501274        } else {
    12511275            $userid = get_current_user_id();
     
    12911315
    12921316        if ( get_current_user_id() == 0 ) {
    1293             $userid = $_COOKIE['recomendo-cookie-user'];
     1317            $userid = $_COOKIE['recomendo-cookie-user'];
    12941318        } else {
    12951319            $userid = get_current_user_id();
     
    13431367
    13441368
    1345     // Adds all orders as buy events to the eventserver.
     1369    // Adds all orders as buy events to the eventserver.
    13461370    // Executed when all data is copied to eventserver
    1347     public function add_all_orders_background() {
     1371    public function add_all_orders_background() {
    13481372
    13491373        $query_args = array(
     
    13571381
    13581382        if ( sizeof( $order_ids ) > 0 ) {
    1359             foreach ( $order_ids as $id ) {
    1360                 $this->bg_order_copy->push_to_queue( $id );
    1361             }
    1362         }
    1363 
    1364         $this->bg_order_copy->save()->dispatch();
    1365 
    1366     } //end-of-method add_all_orders_background()
     1383            foreach ( $order_ids as $id ) {
     1384                $this->bg_order_copy->push_to_queue( $id );
     1385            }
     1386        }
     1387
     1388        $this->bg_order_copy->save()->dispatch();
     1389
     1390    } //end-of-method add_all_orders_background()
    13671391
    13681392
     
    13701394    public function copy_data_to_eventserver() {
    13711395
    1372             update_option( 'recomendo_data_saved_ok', true );
    1373 
    1374             $this->add_all_users_background();
    1375             $this->add_all_items_background();
    1376             if ( class_exists( 'woocommerce' ) &&
    1377                 $this->options['post_type'] == 'product' ) {
    1378 
    1379                     $this->add_all_orders_background();
    1380             }
     1396            update_option( 'recomendo_data_saved_ok', true );
     1397
     1398            $this->add_all_users_background();
     1399            $this->add_all_items_background();
     1400            if ( class_exists( 'woocommerce' ) &&
     1401                $this->options['post_type'] == 'product' ) {
     1402
     1403                    $this->add_all_orders_background();
     1404            }
    13811405    }
    13821406
  • recomendo/trunk/recomendo-widget.php

    r1967374 r2005209  
    3131        if ( !get_option( 'recomendo_auth' ) ) return;
    3232
    33         if ( !$options = get_option( 'recomendo_options' ) ) return;
    34 
    35         $template_args = array(
    36             'widget_id'   => $args['widget_id'],
    37             'show_rating' => true
    38         );
     33        if ( !$options = get_option( 'recomendo_options' ) ) return;
     34
     35        $template_args = array(
     36            'widget_id'   => $args['widget_id'],
     37            'show_rating' => true
     38        );
    3939
    4040        switch (  $instance['type'] ) {
     
    9090                }
    9191                break;
    92             case 'Trending Items' :
     92            case 'Trending Items' :
    9393                $response = $recomendo->get_trending_items( intval( $instance['number']));
    9494                break;
     
    9797
    9898
    99         if ( $response != false and array_key_exists( 'itemScores', $response ) ) {
     99        if ( $response != false and array_key_exists( 'itemScores', $response ) ) {
    100100
    101101            $title = apply_filters( 'widget_title', $instance['title'] );
     
    109109            // -----------------------------------------------
    110110
    111             if ( class_exists( 'woocommerce' ) ) {
    112                 echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="' . $instance['class'] .  '">' ) );
    113                 foreach ($response['itemScores'] as $i ) {
    114                     if ( get_post_status ( $i['item'] ) == 'publish' ) {
    115                         $post_object = get_post( $i['item'] );
    116                         setup_postdata( $GLOBALS['post'] =& $post_object );
    117                         // add .php to the template -> woocommerce requires it
    118                         // but get_template_part does not
    119                         wc_get_template( $instance['template'] . '.php', $template_args );
    120                     }
    121                 }
    122             } else {
    123 
    124                 foreach ($response['itemScores'] as $i ) {
    125                     if ( get_post_status ( $i['item'] ) == 'publish' ) {
    126                         $post_object = get_post( $i['item'] );
    127                         setup_postdata( $GLOBALS['post'] =& $post_object );
    128                         // REPLACE by custom parameter
    129                         get_template_part( $instance['template'] );
    130 
    131                     }
    132                 }
    133 
    134             }
    135 
    136             wp_reset_postdata();
    137 
    138             // -----------------------------------------------
    139             // till here
    140             echo $args['after_widget'];
     111            if ( class_exists( 'woocommerce' ) ) {
     112                echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="' . $instance['class'] .  '">' ) );
     113                foreach ($response['itemScores'] as $i ) {
     114                    if ( get_post_status ( $i['item'] ) == 'publish' ) {
     115                        $post_object = get_post( $i['item'] );
     116                        setup_postdata( $GLOBALS['post'] =& $post_object );
     117                        // add .php to the template -> woocommerce requires it
     118                        // but get_template_part does not
     119                        wc_get_template( $instance['template'] . '.php', $template_args );
     120                    }
     121                }
     122            } else {
     123
     124                foreach ($response['itemScores'] as $i ) {
     125                    if ( get_post_status ( $i['item'] ) == 'publish' ) {
     126                        $post_object = get_post( $i['item'] );
     127                        setup_postdata( $GLOBALS['post'] =& $post_object );
     128                        // REPLACE by custom parameter
     129                        get_template_part( $instance['template'] );
     130
     131                    }
     132                }
     133
     134            }
     135
     136            wp_reset_postdata();
     137
     138            // -----------------------------------------------
     139            // till here
     140            echo $args['after_widget'];
    141141        }
    142142
     
    146146    public function form( $instance ) {
    147147
    148         global $recomendo;
     148        global $recomendo;
    149149
    150150        if ( isset( $instance[ 'title' ] ) ) {
     
    170170        }
    171171
    172         if ( isset( $instance[ 'template' ] ) ) {
     172        if ( isset( $instance[ 'template' ] ) ) {
    173173            $template = $instance[ 'template' ];
    174174        }
    175175        else {
    176             if ( class_exists( 'woocommerce' ) ) {
    177                 $template = __( 'content-widget-product', 'recomendo_widget_domain' );
    178             } else {
    179                 $template = __( 'content-' . $recomendo->options['post_type'] , 'recomendo_widget_domain' );
    180             }
    181         }
    182 
    183 
    184         if ( isset( $instance[ 'class' ] ) ) {
     176            if ( class_exists( 'woocommerce' ) ) {
     177                $template = __( 'content-widget-product', 'recomendo_widget_domain' );
     178            } else {
     179                $template = __( 'content-' . $recomendo->options['post_type'] , 'recomendo_widget_domain' );
     180            }
     181        }
     182
     183
     184        if ( isset( $instance[ 'class' ] ) ) {
    185185            $class = $instance[ 'class' ];
    186186        } else {
    187             if ( class_exists( 'woocommerce' ) ) {
    188                 $class = __( 'product_list_widget', 'recomendo_widget_domain' );
    189             } else {
    190                 $class = __( 'widget_text', 'recomendo_widget_domain' );
    191             }
     187            if ( class_exists( 'woocommerce' ) ) {
     188                $class = __( 'product_list_widget', 'recomendo_widget_domain' );
     189            } else {
     190                $class = __( 'widget_text', 'recomendo_widget_domain' );
     191            }
    192192        }
    193193
     
    223223        </p>
    224224
    225         <p>
     225        <p>
    226226            <label for="<?php echo $this->get_field_id( 'template' ); ?>"><?php _e( 'Template part:' ); ?></label>
    227227            <input class="widefat" id="<?php echo $this->get_field_id( 'template' ); ?>" name="<?php echo $this->get_field_name( 'template' ); ?>" type="text" value="<?php echo esc_attr( $template ); ?>" />
    228228        </p>
    229229
    230         <p>
     230        <p>
    231231            <label for="<?php echo $this->get_field_id( 'class' ); ?>"><?php _e( 'CSS class:' ); ?></label>
    232232            <input class="widefat" id="<?php echo $this->get_field_id( 'class' ); ?>" name="<?php echo $this->get_field_name( 'class' ); ?>" type="text" value="<?php echo esc_attr( $class ); ?>" />
     
    244244        $instance['number'] = ( ! empty( $new_instance['number'] ) ) ? strip_tags( $new_instance['number'] ) : '';
    245245
    246         $instance['template'] = ( ! empty( $new_instance['template'] ) ) ? str_replace( '.php', '', strip_tags( $new_instance['template'] ) ) : '';
    247         $instance['class'] = ( ! empty( $new_instance['class'] ) ) ? strip_tags( $new_instance['class'] ) : '';
     246        $instance['template'] = ( ! empty( $new_instance['template'] ) ) ? str_replace( '.php', '', strip_tags( $new_instance['template'] ) ) : '';
     247        $instance['class'] = ( ! empty( $new_instance['class'] ) ) ? strip_tags( $new_instance['class'] ) : '';
    248248
    249249        return $instance;
  • recomendo/trunk/recomendo.php

    r1967374 r2005209  
    55* Description: Make your website smart with Artificial Intelligence recommendations.
    66* Author: Recomendo
    7 * Version: 1.0.4
     7* Version: 1.0.5
    88* Requires at least: 4.7
    9 * Tested up to: 4.9.8
     9* Tested up to: 5.0
    1010* WC requires at least: 3.0
    1111* WC tested up to: 3.5
     
    4242    // Check Recomendo is Authorized and Configured to Continue
    4343    if ( Recomendo_Admin::is_configured() ) {
    44         $options = get_option( 'recomendo_options' );
     44        $options = get_option( 'recomendo_options' );
    4545        if ( class_exists( 'Recomendo_Plugin' ) ) {
    4646            // launch the plugin
    4747            $recomendo = new Recomendo_Plugin( $options );
    4848
    49         }
    50     }
     49        }
     50    }
    5151}
  • recomendo/trunk/screens/dashboard.php

    r1967374 r2005209  
    4949
    5050                    Recomendo_Admin::authorize( $_POST['recomendo_client_id'],
    51                                                 $_POST['recomendo_client_secret']
    52                     );
     51                                                $_POST['recomendo_client_secret']
     52                    );
    5353        }
    5454    ?>
     
    7777                    <?php if ( Recomendo_Admin::is_authorized() ): ?>
    7878                        <p><?php esc_html_e( 'Client ID:', 'admin-screen' ); ?><br><code class="recomendo-code"><?php echo esc_html( Recomendo_Admin::get_censored_code( 'client_id') ); ?></code></p>
    79                         <p><?php esc_html_e( 'Secret:', 'admin-screen' ); ?><br><code class="recomendo-code"><?php echo esc_html( Recomendo_Admin::get_censored_code( 'client_secret' ) ); ?></code></p>
     79                        <p><?php esc_html_e( 'Secret:', 'admin-screen' ); ?><br><code class="recomendo-code"><?php echo esc_html( Recomendo_Admin::get_censored_code( 'client_secret' ) ); ?></code></p>
    8080                    <?php endif; ?>
    8181
    8282                    <?php if ( !Recomendo_Admin::is_authorized() ): ?>
    8383                        <p><?php esc_html_e( 'Client ID:', 'admin-screen' ); ?>
    84                             <br>
    85                             <input id="recomendo_client_id" class="of-input" name="recomendo_client_id" type="text" value="" size="36">
    86                         </p>
    87                         <p><?php esc_html_e( 'Client Secret:', 'admin-screen' ); ?>
    88                             <br>
    89                             <textarea id="recomendo_client_secret" class="of-input" name="recomendo_client_secret" value="" rows="2" cols="36"></textarea>
    90                         </p>
     84                            <br>
     85                            <input id="recomendo_client_id" class="of-input" name="recomendo_client_id" type="text" value="" size="36">
     86                        </p>
     87                        <p><?php esc_html_e( 'Client Secret:', 'admin-screen' ); ?>
     88                            <br>
     89                            <textarea id="recomendo_client_secret" class="of-input" name="recomendo_client_secret" value="" rows="2" cols="36"></textarea>
     90                        </p>
    9191                    <?php endif; ?>
    9292
    9393                    <?php if ( !Recomendo_Admin::is_authorized() ): ?>
    9494                        <?php wp_nonce_field('recomendo_authorize_button_clicked'); ?>
    95                         <input type="hidden" class="button button-primary" name="recomendo_authorize_button" value="true" />
     95                        <input type="hidden" class="button button-primary" name="recomendo_authorize_button" value="true" />
    9696                        <?php submit_button( 'Authorize Plugin' ); ?>
    9797                    <?php endif; ?>
     
    122122
    123123   <?php if ( Recomendo_Admin::is_authorized() ) : ?>
    124         <?php if ( !Recomendo_Admin::is_configured() ) : ?>
    125             <div class="recomendo-postbox">
    126                 <form method="post" action="options.php">
    127                     <?php settings_errors( 'recomendo-options' ); ?>
    128                     <?php settings_fields( 'recomendo-options' ); ?>
    129                     <?php do_settings_sections( 'recomendo-options' ); ?>
    130 
    131 
    132                     <h2>What post type do you want to recommend?</h2>
    133 
    134 
    135                     <table class="form-table">
    136                         <tbody>
    137                             <tr>
    138                                 <th scope="row">
    139                                     <label for="recomendo_post_type"><span>Post Type</span></label>
    140                                 </th>
    141                                 <td>
    142                                     <?php
    143                                         foreach ( get_post_types( '', 'names' ) as $post_type ) {
    144                                             if (!in_array($post_type, $avoid_post_types)) {
    145                                                     echo '<label><input type="radio" id="recomendo_post_type" name="recomendo_options[post_type]" value="' . $post_type . '" />' . ucwords($post_type) . '</label><br>';
    146                                             }
    147                                         }
    148                                     ?>
    149                                 </td>
    150                             </tr>
    151                         </tbody>
    152                     </table>
    153                     <?php submit_button(); ?>
    154                 </form>
    155             </div>
    156         <?php else : ?>
    157             <?php if (!get_option('recomendo_data_saved_ok')) : ?>
    158                 <?php global $recomendo; ?>
    159                 <?php $recomendo->copy_data_to_eventserver(); ?>
    160             <?php endif; ?>
    161 
    162             <div class="recomendo-postbox">
    163                 <h2>Post Type to Recommend is Configured</h2>
    164                 <p>
    165                     If you want to change the post type you need to uninstall and re-install the Recomendo plugin.
    166                 </p>
    167                 <table class="form-table">
    168                     <tbody>
    169                         <tr>
    170                             <th scope="row">
    171                                 <label for="recomendo_post_type"><span>Post Type</span></label>
    172                             </th>
    173                             <td>
    174                                 <?php
    175                                     foreach ( get_post_types( '', 'names' ) as $post_type ) {
    176                                         if ( $post_type == $options['post_type']) {
    177                                             echo '<label><input type="radio" id="recomendo_post_type" name="recomendo_options[post_type]" value="' . $post_type . '" checked disabled/>' . ucwords($post_type) . '</label><br>';
    178                                         } else if (!in_array($post_type, $avoid_post_types)) {
    179                                             echo '<label><input type="radio" id="recomendo_post_type" name="recomendo_options[post_type]" value="' . $post_type . '" disabled />' . ucwords($post_type) . '</label><br>';
    180                                         }
    181                                     }
    182                                 ?>
    183                             </td>
    184                         </tr>
    185                     </tbody>
    186                 </table>
    187             </div>
    188 
    189         <?php endif; ?>
    190     <?php endif; ?>
    191 
    192     <?php if ( Recomendo_Admin::is_authorized() and Recomendo_Admin::is_configured() ) : ?>
    193 
    194         <div class="recomendo-postbox">
    195             <form method="post" action="options.php">
    196                 <?php settings_fields( 'recomendo-general-options' ); ?>
    197                 <?php $general_options = get_option( 'recomendo_general_options' ); ?>
    198 
    199                 <h2>Recommendation Options</h2>
    200                 <table class="form-table">
    201                     <tbody>
    202                         <tr>
    203                             <th scope="row">
    204                                 <label for="recomendo_general_options"><span>Exclude Items Older Than</span></label>
    205                             </th>
    206                             <td>
    207                                 <?php
    208                                 if ( isset( $general_options['expire_date'] ) ) {
    209                                     echo '<label><input type="number" id="recomendo_general_options" name="recomendo_general_options[expire_date]" value="' . $general_options['expire_date'] . '" /> Days</label><br>';
    210                                 } else {
    211                                     echo '<label><input type="number" id="recomendo_general_options" name="recomendo_general_options[expire_date]" value="0" /> Days</label><br>';
    212                                 }
    213 
    214                                 ?>
    215                             </td>
    216                         </tr>
    217                         <tr>
    218                             <th scope="row">
    219                                 <label for="recomendo_general_options"><span>Relevance of Similar Items Having the Same Categories</span></label>
    220                             </th>
    221                             <td>
    222                                 <span class="recomendo-range-title">None</span>
    223                                 <span class="recomendo-range-title">Neutral</span>
    224                                 <span class="recomendo-range-title">All</span>
    225                                 <?php
    226                                     if ( isset( $general_options['similar_categories_relevance'] ) ) {
    227                                             echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_categories_relevance]" min="-1" max="3" step="1" value="' .  $general_options['similar_categories_relevance'] . '" list="tickmarks" />';
    228                                         } else {
    229                                             echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_categories_relevance]" min="-1" max="3" step="1" value="2" list="tickmarks"/>';
    230                                         }
    231                                 ?>
    232                             </td>
    233                         </tr>
    234                         <tr>
    235                             <th scope="row">
    236                                 <label for="recomendo_general_options"><span>Relevance of Similar Items Having the Same Tags</span></label>
    237                             </th>
    238                             <td>
    239                                 <span class="recomendo-range-title">None</span>
    240                                 <span class="recomendo-range-title">Neutral</span>
    241                                 <span class="recomendo-range-title">All</span>
    242                                 <?php
    243                                     if ( isset( $general_options['similar_tags_relevance'] ) ) {
    244                                             echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_tags_relevance]" min="-1" max="3" step="1" value="' .  $general_options['similar_tags_relevance'] . '" list="tickmarks" />';
    245                                         } else {
    246                                             echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_tags_relevance]" min="-1" max="3" step="1" value="2" list="tickmarks"/>';
    247                                         }
    248                                 ?>
    249                             </td>
    250                         </tr>
    251 
    252 
    253                     </tbody>
    254                 </table>
    255                 <p class="submit">
    256                     <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
    257                 </p>
    258             </form>
    259         </div>
    260     <?php endif; ?>
    261 
    262     <?php if ( Recomendo_Admin::is_authorized() and Recomendo_Admin::is_configured() ) : ?>
    263         <?php if ( class_exists( 'woocommerce' ) and $options['post_type'] == "product" ) : ?>
    264 
    265             <div class="recomendo-postbox">
    266                 <form method="post" action="options.php">
    267                     <?php settings_fields( 'recomendo-woo-options' ); ?>
    268                     <?php $woo_options = get_option( 'recomendo_woo_options' ); ?>
    269 
    270                     <h2>WooCommerce Options</h2>
    271                     <table class="form-table">
    272                         <tbody>
    273                             <tr>
    274                                 <th scope="row">
    275                                     <label for="recomendo_woo_options"><span>Show Recomendo on</span></label>
    276                                 </th>
    277                                 <td>
    278                                     <?php
    279                                     if ( isset( $woo_options['woo_show_related'] ) ) {
    280                                         echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_related]" value="yes" checked/>WooCommerce Related Products</label><br>';
    281                                     } else {
    282                                         echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_related]" value="yes" />WooCommerce Related Products</label><br>';
    283                                     }
    284 
    285                                     if ( isset( $woo_options['woo_show_cart'] ) ) {
    286                                         echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_cart]" value="yes" checked/>WooCommerce Cart</label><br>';
    287                                     } else {
    288                                         echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_cart]" value="yes"/>WooCommerce Cart</label><br>';
    289                                     }
    290                                     ?>
    291                                 </td>
    292                             </tr>
    293                             <tr>
    294                                 <th scope="row">
    295                                     <label for="recomendo_woo_num_related"><span>Recommendations in Related Products</span></label>
    296                                 </th>
    297                                 <td>
    298                                     <?php
    299                                     if ( isset( $woo_options['woo_num_related'] ) ) {
    300 
    301                                         echo '<input type="number" id="recomendo_woo_num_related" name="recomendo_woo_options[woo_num_related]" value="' . $woo_options['woo_num_related'] . '"/>';
    302                                     } else {
    303                                         echo '<input type="number" id="recomendo_woo_num_related" name="recomendo_woo_options[woo_num_related]" value="12"/>';
    304                                     }
    305 
    306                                     ?>
    307                                 </td>
    308                             </tr>
    309 
    310                             <tr>
    311                                 <th scope="row">
    312                                     <label for="recomendo_woo_num_cart"><span>Recommendations in Cart</span></label>
    313                                 </th>
    314                                 <td>
    315                                     <?php
    316                                     if ( isset( $woo_options['woo_num_cart'] ) ) {
    317 
    318                                         echo '<input type="number" id="recomendo_woo_num_cart" name="recomendo_woo_options[woo_num_cart]" value="' . $woo_options['woo_num_cart'] . '"/>';
    319                                     } else {
    320                                         echo '<input type="number" id="recomendo_woo_num_cart" name="recomendo_woo_options[woo_num_cart]" value="3"/>';
    321                                     }
    322 
    323                                     ?>
    324                                 </td>
    325                             </tr>
    326 
    327 
    328 
    329                             <tr>
    330                                 <th scope="row">
    331                                     <label for="recomendo_woo_cart_title"><span>Cart Recommendations Title</span></label>
    332                                 </th>
    333                                 <td>
    334                                     <?php
    335                                     if ( isset( $woo_options['woo_cart_title'] ) ) {
    336 
    337                                         echo '<textarea id="recomendo_woo_cart_title" name="recomendo_woo_options[woo_cart_title]">' . $woo_options['woo_cart_title'] . '</textarea>';
    338                                     } else {
    339                                         echo '<textarea id="recomendo_woo_cart_title" name="recomendo_woo_options[woo_cart_title]">Usually bought together</textarea>';
    340                                     }
    341 
    342                                     ?>
    343                                 </td>
    344                             </tr>
    345 
    346                             <tr>
    347                                 <th scope="row">
    348                                     <label for="recomendo_woo_exclude_outofstock"><span> Out of Stock Products</span></label>
    349                                 </th>
    350                                 <td>
    351                                     <?php
    352                                     if ( isset( $woo_options['woo_exclude_outofstock'] ) ) {
    353                                         echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_exclude_outofstock]" value="yes" checked/>Exclude from Recommendations</label><br>';
    354                                     } else {
    355                                         echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_exclude_outofstock]" value="yes" />Exclude from Recommendations</label><br>';
    356                                     }
    357                                     ?>
    358                                 </td>
    359 
    360                             <tr>
    361                                 <th scope="row">
    362                                     <label for="recomendo_woo_onsale_relevance"><span> On Sale Products Relevance</span></label>
    363                                 </th>
    364                                 <td>
    365                                     <span class="recomendo-range-title">None</span>
    366                                     <span class="recomendo-range-title">Neutral</span>
    367                                     <span class="recomendo-range-title">All</span>
    368                                     <?php
    369 
    370                                     if ( isset( $woo_options['woo_onsale_relevance'] ) ) {
    371                                         echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_onsale_relevance]" min="-1" max="3" step="1" value="' .  $woo_options['woo_onsale_relevance'] . '" list="tickmarks" />';
    372                                     } else {
    373                                         echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_onsale_relevance]" min="-1" max="3" step="1" value="1" list="tickmarks"/>';
    374                                     }
    375                                     ?>
    376                                     <datalist id="tickmarks">
    377                                         <option value="-1">
    378                                         <option value="0">
    379                                         <option value="1">
    380                                         <option value="2">
    381                                         <option value="3">
    382                                     </datalist>
    383                                 </td>
    384 
    385                             </tr>
    386 
    387                             <tr>
    388                                 <th scope="row">
    389                                     <label for="recomendo_woo_featured_relevance"><span> Featured Products Relevance</span></label>
    390                                 </th>
    391                                 <td>
    392                                     <span class="recomendo-range-title">None</span>
    393                                     <span class="recomendo-range-title">Neutral</span>
    394                                     <span class="recomendo-range-title">All</span>
    395                                     <?php
    396                                         if ( isset( $woo_options['woo_featured_relevance'] ) ) {
    397                                             echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_featured_relevance]" min="-1" max="3" step="1" value="' .  $woo_options['woo_featured_relevance'] . '" list="tickmarks" />';
    398                                         } else {
    399                                             echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_featured_relevance]" min="-1" max="3" step="1" value="1" list="tickmarks" />';
    400                                         }
    401                                     ?>
    402                                 </td>
    403                             </tr>
    404 
    405 
    406                         </tbody>
    407                     </table>
    408                     <p class="submit">
    409                         <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
    410                     </p>
    411                 </form>
    412             </div>
    413         <?php endif; ?>
     124        <?php if ( !Recomendo_Admin::is_configured() ) : ?>
     125            <div class="recomendo-postbox">
     126                <form method="post" action="options.php">
     127                    <?php settings_errors( 'recomendo-options' ); ?>
     128                    <?php settings_fields( 'recomendo-options' ); ?>
     129                    <?php do_settings_sections( 'recomendo-options' ); ?>
     130
     131
     132                    <h2>What post type do you want to recommend?</h2>
     133
     134
     135                    <table class="form-table">
     136                        <tbody>
     137                            <tr>
     138                                <th scope="row">
     139                                    <label for="recomendo_post_type"><span>Post Type</span></label>
     140                                </th>
     141                                <td>
     142                                    <?php
     143                                        foreach ( get_post_types( '', 'names' ) as $post_type ) {
     144                                            if (!in_array($post_type, $avoid_post_types)) {
     145                                                    echo '<label><input type="radio" id="recomendo_post_type" name="recomendo_options[post_type]" value="' . $post_type . '" />' . ucwords($post_type) . '</label><br>';
     146                                            }
     147                                        }
     148                                    ?>
     149                                </td>
     150                            </tr>
     151                        </tbody>
     152                    </table>
     153                    <?php submit_button(); ?>
     154                </form>
     155            </div>
     156        <?php else : ?>
     157            <?php if (!get_option('recomendo_data_saved_ok')) : ?>
     158                <?php global $recomendo; ?>
     159                <?php $recomendo->copy_data_to_eventserver(); ?>
     160            <?php endif; ?>
     161
     162            <div class="recomendo-postbox">
     163                <h2>Post Type to Recommend is Configured</h2>
     164                <p>
     165                    If you want to change the post type you need to uninstall and re-install the Recomendo plugin.
     166                </p>
     167                <table class="form-table">
     168                    <tbody>
     169                        <tr>
     170                            <th scope="row">
     171                                <label for="recomendo_post_type"><span>Post Type</span></label>
     172                            </th>
     173                            <td>
     174                                <?php
     175                                    foreach ( get_post_types( '', 'names' ) as $post_type ) {
     176                                        if ( $post_type == $options['post_type']) {
     177                                            echo '<label><input type="radio" id="recomendo_post_type" name="recomendo_options[post_type]" value="' . $post_type . '" checked disabled/>' . ucwords($post_type) . '</label><br>';
     178                                        } else if (!in_array($post_type, $avoid_post_types)) {
     179                                            echo '<label><input type="radio" id="recomendo_post_type" name="recomendo_options[post_type]" value="' . $post_type . '" disabled />' . ucwords($post_type) . '</label><br>';
     180                                        }
     181                                    }
     182                                ?>
     183                            </td>
     184                        </tr>
     185                    </tbody>
     186                </table>
     187            </div>
     188
     189        <?php endif; ?>
     190    <?php endif; ?>
     191
     192    <?php if ( Recomendo_Admin::is_authorized() and Recomendo_Admin::is_configured() ) : ?>
     193
     194        <div class="recomendo-postbox">
     195            <form method="post" action="options.php">
     196                <?php settings_fields( 'recomendo-general-options' ); ?>
     197                <?php $general_options = get_option( 'recomendo_general_options' ); ?>
     198
     199                <h2>Recommendation Options</h2>
     200                <table class="form-table">
     201                    <tbody>
     202                        <tr>
     203                            <th scope="row">
     204                                <label for="recomendo_general_options"><span>Show Personalized Content to Main Search Engines</span></label>
     205                            </th>
     206                            <td>
     207                                <?php
     208                                if ( isset( $general_options['allow_seo'] ) ) {
     209                                    echo '<label><input type="checkbox" id="recomendo_general_options" name="recomendo_general_options[allow_seo]" value="yes" checked /> Improves SEO but consumes your Recomendo Plan</label><br>';
     210                                } else {
     211                                    echo '<label><input type="checkbox" id="recomendo_general_options" name="recomendo_general_options[allow_seo]" value="yes" /> Improves SEO but consumes your Recomendo Plan</label><br>';
     212                                }
     213
     214                                ?>
     215                            </td>
     216                        </tr>                       
     217                        <tr>
     218                            <th scope="row">
     219                                <label for="recomendo_general_options"><span>Exclude Items Older Than</span></label>
     220                            </th>
     221                            <td>
     222                                <?php
     223                                if ( isset( $general_options['expire_date'] ) ) {
     224                                    echo '<label><input type="number" id="recomendo_general_options" name="recomendo_general_options[expire_date]" value="' . $general_options['expire_date'] . '" /> Days</label><br>';
     225                                } else {
     226                                    echo '<label><input type="number" id="recomendo_general_options" name="recomendo_general_options[expire_date]" value="0" /> Days</label><br>';
     227                                }
     228
     229                                ?>
     230                            </td>
     231                        </tr>
     232                        <tr>
     233                            <th scope="row">
     234                                <label for="recomendo_general_options"><span>Relevance of Similar Items Having the Same Categories</span></label>
     235                            </th>
     236                            <td>
     237                                <span class="recomendo-range-title">None</span>
     238                                <span class="recomendo-range-title">Neutral</span>
     239                                <span class="recomendo-range-title">All</span>
     240                                <?php
     241                                    if ( isset( $general_options['similar_categories_relevance'] ) ) {
     242                                            echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_categories_relevance]" min="-1" max="3" step="1" value="' .  $general_options['similar_categories_relevance'] . '" list="tickmarks" />';
     243                                        } else {
     244                                            echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_categories_relevance]" min="-1" max="3" step="1" value="2" list="tickmarks"/>';
     245                                        }
     246                                ?>
     247                            </td>
     248                        </tr>
     249                        <tr>
     250                            <th scope="row">
     251                                <label for="recomendo_general_options"><span>Relevance of Similar Items Having the Same Tags</span></label>
     252                            </th>
     253                            <td>
     254                                <span class="recomendo-range-title">None</span>
     255                                <span class="recomendo-range-title">Neutral</span>
     256                                <span class="recomendo-range-title">All</span>
     257                                <?php
     258                                    if ( isset( $general_options['similar_tags_relevance'] ) ) {
     259                                            echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_tags_relevance]" min="-1" max="3" step="1" value="' .  $general_options['similar_tags_relevance'] . '" list="tickmarks" />';
     260                                        } else {
     261                                            echo '<input type="range" id="recomendo_general_options" name="recomendo_general_options[similar_tags_relevance]" min="-1" max="3" step="1" value="2" list="tickmarks"/>';
     262                                        }
     263                                ?>
     264                            </td>
     265                        </tr>
     266
     267
     268                    </tbody>
     269                </table>
     270                <p class="submit">
     271                    <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
     272                </p>
     273            </form>
     274        </div>
     275    <?php endif; ?>
     276
     277    <?php if ( Recomendo_Admin::is_authorized() and Recomendo_Admin::is_configured() ) : ?>
     278        <?php if ( class_exists( 'woocommerce' ) and $options['post_type'] == "product" ) : ?>
     279
     280            <div class="recomendo-postbox">
     281                <form method="post" action="options.php">
     282                    <?php settings_fields( 'recomendo-woo-options' ); ?>
     283                    <?php $woo_options = get_option( 'recomendo_woo_options' ); ?>
     284
     285                    <h2>WooCommerce Options</h2>
     286                    <table class="form-table">
     287                        <tbody>
     288                            <tr>
     289                                <th scope="row">
     290                                    <label for="recomendo_woo_options"><span>Show Recomendo on</span></label>
     291                                </th>
     292                                <td>
     293                                    <?php
     294                                    if ( isset( $woo_options['woo_show_related'] ) ) {
     295                                        echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_related]" value="yes" checked/>WooCommerce Related Products</label><br>';
     296                                    } else {
     297                                        echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_related]" value="yes" />WooCommerce Related Products</label><br>';
     298                                    }
     299
     300                                    if ( isset( $woo_options['woo_show_cart'] ) ) {
     301                                        echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_cart]" value="yes" checked/>WooCommerce Cart</label><br>';
     302                                    } else {
     303                                        echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_show_cart]" value="yes"/>WooCommerce Cart</label><br>';
     304                                    }
     305                                    ?>
     306                                </td>
     307                            </tr>
     308                            <tr>
     309                                <th scope="row">
     310                                    <label for="recomendo_woo_num_related"><span>Recommendations in Related Products</span></label>
     311                                </th>
     312                                <td>
     313                                    <?php
     314                                    if ( isset( $woo_options['woo_num_related'] ) ) {
     315
     316                                        echo '<input type="number" id="recomendo_woo_num_related" name="recomendo_woo_options[woo_num_related]" value="' . $woo_options['woo_num_related'] . '"/>';
     317                                    } else {
     318                                        echo '<input type="number" id="recomendo_woo_num_related" name="recomendo_woo_options[woo_num_related]" value="12"/>';
     319                                    }
     320
     321                                    ?>
     322                                </td>
     323                            </tr>
     324
     325                            <tr>
     326                                <th scope="row">
     327                                    <label for="recomendo_woo_num_cart"><span>Recommendations in Cart</span></label>
     328                                </th>
     329                                <td>
     330                                    <?php
     331                                    if ( isset( $woo_options['woo_num_cart'] ) ) {
     332
     333                                        echo '<input type="number" id="recomendo_woo_num_cart" name="recomendo_woo_options[woo_num_cart]" value="' . $woo_options['woo_num_cart'] . '"/>';
     334                                    } else {
     335                                        echo '<input type="number" id="recomendo_woo_num_cart" name="recomendo_woo_options[woo_num_cart]" value="3"/>';
     336                                    }
     337
     338                                    ?>
     339                                </td>
     340                            </tr>
     341
     342
     343
     344                            <tr>
     345                                <th scope="row">
     346                                    <label for="recomendo_woo_cart_title"><span>Cart Recommendations Title</span></label>
     347                                </th>
     348                                <td>
     349                                    <?php
     350                                    if ( isset( $woo_options['woo_cart_title'] ) ) {
     351
     352                                        echo '<textarea id="recomendo_woo_cart_title" name="recomendo_woo_options[woo_cart_title]">' . $woo_options['woo_cart_title'] . '</textarea>';
     353                                    } else {
     354                                        echo '<textarea id="recomendo_woo_cart_title" name="recomendo_woo_options[woo_cart_title]">Usually bought together</textarea>';
     355                                    }
     356
     357                                    ?>
     358                                </td>
     359                            </tr>
     360
     361                            <tr>
     362                                <th scope="row">
     363                                    <label for="recomendo_woo_exclude_outofstock"><span> Out of Stock Products</span></label>
     364                                </th>
     365                                <td>
     366                                    <?php
     367                                    if ( isset( $woo_options['woo_exclude_outofstock'] ) ) {
     368                                        echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_exclude_outofstock]" value="yes" checked/>Exclude from Recommendations</label><br>';
     369                                    } else {
     370                                        echo '<label><input type="checkbox" id="recomendo_woo_options" name="recomendo_woo_options[woo_exclude_outofstock]" value="yes" />Exclude from Recommendations</label><br>';
     371                                    }
     372                                    ?>
     373                                </td>
     374
     375                            <tr>
     376                                <th scope="row">
     377                                    <label for="recomendo_woo_onsale_relevance"><span> On Sale Products Relevance</span></label>
     378                                </th>
     379                                <td>
     380                                    <span class="recomendo-range-title">None</span>
     381                                    <span class="recomendo-range-title">Neutral</span>
     382                                    <span class="recomendo-range-title">All</span>
     383                                    <?php
     384
     385                                    if ( isset( $woo_options['woo_onsale_relevance'] ) ) {
     386                                        echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_onsale_relevance]" min="-1" max="3" step="1" value="' .  $woo_options['woo_onsale_relevance'] . '" list="tickmarks" />';
     387                                    } else {
     388                                        echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_onsale_relevance]" min="-1" max="3" step="1" value="1" list="tickmarks"/>';
     389                                    }
     390                                    ?>
     391                                    <datalist id="tickmarks">
     392                                        <option value="-1">
     393                                        <option value="0">
     394                                        <option value="1">
     395                                        <option value="2">
     396                                        <option value="3">
     397                                    </datalist>
     398                                </td>
     399
     400                            </tr>
     401
     402                            <tr>
     403                                <th scope="row">
     404                                    <label for="recomendo_woo_featured_relevance"><span> Featured Products Relevance</span></label>
     405                                </th>
     406                                <td>
     407                                    <span class="recomendo-range-title">None</span>
     408                                    <span class="recomendo-range-title">Neutral</span>
     409                                    <span class="recomendo-range-title">All</span>
     410                                    <?php
     411                                        if ( isset( $woo_options['woo_featured_relevance'] ) ) {
     412                                            echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_featured_relevance]" min="-1" max="3" step="1" value="' .  $woo_options['woo_featured_relevance'] . '" list="tickmarks" />';
     413                                        } else {
     414                                            echo '<input type="range" id="recomendo_woo_options" name="recomendo_woo_options[woo_featured_relevance]" min="-1" max="3" step="1" value="1" list="tickmarks" />';
     415                                        }
     416                                    ?>
     417                                </td>
     418                            </tr>
     419
     420
     421                        </tbody>
     422                    </table>
     423                    <p class="submit">
     424                        <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
     425                    </p>
     426                </form>
     427            </div>
     428        <?php endif; ?>
    414429    <?php endif; ?>
    415430
     
    523538            </table>
    524539        </div>
    525     <?php endif; ?>
     540    <?php endif; ?>
    526541</div>
Note: See TracChangeset for help on using the changeset viewer.