WC_PS_Posts_Data

"Copyright 2012 A3 Revolution Web Design" This software is distributed under the terms of GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007.

Defined (1)

The class is defined in the following location(s).

/classes/data/class-wc-ps-posts-data.php  
  1. class WC_PS_Posts_Data 
  2. public function install_database() { 
  3. global $wpdb; 
  4. $collate = ''; 
  5. if ( $wpdb->has_cap( 'collation' ) ) { 
  6. if( ! empty($wpdb->charset ) ) $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; 
  7. if( ! empty($wpdb->collate ) ) $collate .= " COLLATE $wpdb->collate"; 
  8.  
  9. require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 
  10.  
  11. $table_ps_posts = $wpdb->prefix. "ps_posts"; 
  12.  
  13. if ($wpdb->get_var("SHOW TABLES LIKE '$table_ps_posts'") != $table_ps_posts) { 
  14. $sql = "CREATE TABLE IF NOT EXISTS `{$table_ps_posts}` ( 
  15. post_id bigint(20) NOT NULL,  
  16. post_title mediumtext NOT NULL,  
  17. post_type VARCHAR(20) NOT NULL DEFAULT 'post',  
  18. PRIMARY KEY (post_id) 
  19. ) $collate; "; 
  20.  
  21. $wpdb->query($sql); 
  22.  
  23.  
  24. /** 
  25. * Predictive Search Post Table - set table name 
  26. * @return void 
  27. */ 
  28. public function set_table_wpdbfix() { 
  29. global $wpdb; 
  30. $meta_name = 'ps_posts'; 
  31.  
  32. $wpdb->ps_posts = $wpdb->prefix . $meta_name; 
  33.  
  34. $wpdb->tables[] = 'ps_posts'; 
  35.  
  36. /** 
  37. * Predictive Search Post Table - return sql 
  38. * @return void 
  39. */ 
  40. public function get_sql( $search_keyword = '', $search_keyword_nospecial = '', $post_type = 'product', $number_row, $start = 0, $check_existed = false ) { 
  41. if ( '' == $search_keyword && '' == $search_keyword_nospecial ) { 
  42. return false; 
  43.  
  44. global $wpdb; 
  45. global $wc_ps_exclude_data; 
  46.  
  47. $sql = array(); 
  48. $join = array(); 
  49. $where = array(); 
  50. $groupby = array(); 
  51. $orderby = array(); 
  52.  
  53. $items_excluded = $wc_ps_exclude_data->get_array_items( $post_type ); 
  54. if ( 'page' == $post_type ) { 
  55. global $woocommerce_search_page_id; 
  56. $items_excluded = array_merge( array( (int) $woocommerce_search_page_id ), $items_excluded ); 
  57.  
  58. $woocommerce_search_exclude_out_stock = get_option('woocommerce_search_exclude_out_stock'); 
  59. if ( 'yes' == $woocommerce_search_exclude_out_stock && in_array( $post_type, array( 'product', 'product_variation' ) ) ) { 
  60. global $wc_ps_postmeta_data; 
  61. $items_out_of_stock = $wc_ps_postmeta_data->get_array_products_out_of_stock(); 
  62. $items_excluded = array_merge( $items_out_of_stock, $items_excluded ); 
  63. $id_excluded = implode( ', ', $items_excluded ); 
  64.  
  65. $sql['select'] = array(); 
  66. if ( $check_existed ) { 
  67. $sql['select'][] = " 1 "; 
  68. } else { 
  69. $sql['select'][] = " pp.* "; 
  70.  
  71. $sql['from'] = array(); 
  72. $sql['from'][] = " {$wpdb->ps_posts} AS pp "; 
  73.  
  74. $sql['join'] = $join; 
  75.  
  76. $where[] = $wpdb->prepare( " pp.post_type = %s", $post_type ); 
  77.  
  78. if ( '' != trim( $id_excluded ) ) { 
  79. $where[] = " AND pp.post_id NOT IN ({$id_excluded}) "; 
  80.  
  81. $where_title = ' ( '; 
  82. $where_title .= WC_Predictive_Search_Functions::remove_special_characters_in_mysql( 'pp.post_title', $search_keyword ); 
  83. if ( '' != $search_keyword_nospecial ) { 
  84. $where_title .= " OR ". WC_Predictive_Search_Functions::remove_special_characters_in_mysql( 'pp.post_title', $search_keyword_nospecial ); 
  85. $search_keyword_no_s_letter = WC_Predictive_Search_Functions::remove_s_letter_at_end_word( $search_keyword ); 
  86. if ( $search_keyword_no_s_letter != false ) { 
  87. $where_title .= " OR ". WC_Predictive_Search_Functions::remove_special_characters_in_mysql( 'pp.post_title', $search_keyword_no_s_letter ); 
  88. $where_title .= ' ) '; 
  89.  
  90. $where['search'] = array(); 
  91. $where['search'][] = ' ( ' . $where_title . ' ) '; 
  92.  
  93. $sql['where'] = $where; 
  94.  
  95. $sql['groupby'] = array(); 
  96. $sql['groupby'][] = ' pp.post_id '; 
  97.  
  98. $sql['orderby'] = array(); 
  99. if ( $check_existed ) { 
  100. $sql['limit'] = " 0 , 1 "; 
  101. } else { 
  102. global $predictive_search_mode; 
  103. if ( 'broad' != $predictive_search_mode ) { 
  104. $sql['orderby'][] = $wpdb->prepare( " pp.post_title NOT LIKE '%s' ASC, pp.post_title ASC ", $search_keyword.'%' ); 
  105. } else { 
  106. $sql['orderby'][] = $wpdb->prepare( " pp.post_title NOT LIKE '%s' ASC, pp.post_title NOT LIKE '%s' ASC, pp.post_title ASC ", $search_keyword.'%', '% '.$search_keyword.'%' ); 
  107.  
  108. $sql['limit'] = " {$start} , {$number_row} "; 
  109.  
  110. return $sql; 
  111.  
  112. /** 
  113. * Insert Predictive Search Post 
  114. */ 
  115. public function insert_item( $post_id, $post_title = '', $post_type = 'post' ) { 
  116. global $wpdb; 
  117. return $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->ps_posts} VALUES(%d, %s, %s)", $post_id, stripslashes( $post_title ), stripslashes( $post_type ) ) ); 
  118.  
  119. /** 
  120. * Update Predictive Search Post 
  121. */ 
  122. public function update_item( $post_id, $post_title = '', $post_type = 'post' ) { 
  123. global $wpdb; 
  124.  
  125. $value = $this->get_item( $post_id ); 
  126. if ( NULL == $value ) { 
  127. return $this->insert_item( $post_id, $post_title, $post_type ); 
  128. } else { 
  129. return $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->ps_posts} SET post_title = %s, post_type = %s WHERE post_id = %d ", stripslashes( $post_title ), stripslashes( $post_type ), $post_id ) ); 
  130.  
  131. /** 
  132. * Get Predictive Search Post 
  133. */ 
  134. public function get_item( $post_id ) { 
  135. global $wpdb; 
  136. return $wpdb->get_var( $wpdb->prepare( "SELECT post_title FROM {$wpdb->ps_posts} WHERE post_id = %d LIMIT 0, 1", $post_id ) ); 
  137.  
  138. /** 
  139. * Get Predictive Search Latest Post ID 
  140. */ 
  141. public function get_latest_post_id() { 
  142. global $wpdb; 
  143. return $wpdb->get_var( "SELECT post_id FROM {$wpdb->ps_posts} ORDER BY post_id DESC LIMIT 0, 1" ); 
  144.  
  145. /** 
  146. * Get Total Items Synched 
  147. */ 
  148. public function get_total_items_synched( $post_type = '' ) { 
  149. global $wpdb; 
  150. if ( '' == trim( $post_type ) ) { 
  151. return $wpdb->get_var( "SELECT COUNT(post_id) FROM {$wpdb->ps_posts} " ); 
  152. } else { 
  153. return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$wpdb->ps_posts} WHERE post_type = %s ", $post_type ) ); 
  154.  
  155. /** 
  156. * Delete Predictive Search Post 
  157. */ 
  158. public function delete_item( $post_id ) { 
  159. global $wpdb; 
  160. return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->ps_posts} WHERE post_id = %d ", $post_id ) ); 
  161.  
  162. /** 
  163. * Empty Predictive Search Posts 
  164. */ 
  165. public function empty_table() { 
  166. global $wpdb; 
  167. return $wpdb->query( "TRUNCATE {$wpdb->ps_posts}" );