PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 6.6.0
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v6.6.0
8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 All 533 releases
← All changes | includes/class-response-list.php +302 -317 8.7.46.6.0 View file →
@@ -1,318 +1,303 @@
1 -<?php
2 -if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 -if ( ! class_exists( 'WP_List_Table' ) ) {
4 - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5 -}
6 -
7 -class Response_list extends WP_List_Table {
8 -
9 -
10 - public $chatbot_admin_page;
11 - /** Class constructor */
12 - public function __construct() {
13 -
14 - parent::__construct( [
15 - 'singular' => __( 'Response', 'chatbot' ), //singular name of the listed records
16 - 'plural' => __( 'Responses', 'chatbot' ), //plural name of the listed records
17 - 'ajax' => false //does this table support ajax?
18 - ] );
19 -
20 - $this->chatbot_admin_page = admin_url('admin.php?page=simple-text-response');
21 -
22 - }
23 -
24 -
25 - /**
26 - * Retrieve customers data from the database
27 - *
28 - * @param int $per_page
29 - * @param int $page_number
30 - *
31 - * @return mixed
32 - */
33 - public static function get_responses( $per_page = 5, $page_number = 1 ) {
34 - global $wpdb;
35 -
36 - // Default order by and order
37 - $orderby = 'id';
38 - $order = 'DESC';
39 -
40 - // Allow sorting by column and order if provided and valid
41 - if ( ! empty( $_REQUEST['orderby'] ) ) {
42 - // Whitelist allowed columns to prevent SQL injection
43 - $allowed = array( 'id', 'intent', 'response', 'type' );
44 - $orderby_request = esc_sql( wp_unslash($_REQUEST['orderby']) );
45 - if ( in_array( $orderby_request, $allowed ) ) {
46 - $orderby = $orderby_request;
47 - }
48 - }
49 - if ( ! empty( $_REQUEST['order'] ) ) {
50 - $order_request = strtoupper( esc_sql( wp_unslash($_REQUEST['order']) ) );
51 - if ( in_array( $order_request, array( 'ASC', 'DESC' ) ) ) {
52 - $order = $order_request;
53 - }
54 - }
55 -
56 - $offset = ( $page_number - 1 ) * $per_page;
57 -
58 - // Build the SQL query with validated orderby and order
59 - $sql = $wpdb->prepare(
60 - "SELECT * FROM {$wpdb->prefix}wpbot_response ORDER BY $orderby $order LIMIT %d OFFSET %d",
61 - $per_page,
62 - $offset
63 - );
64 -
65 - $result = $wpdb->get_results( $sql, 'ARRAY_A' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
66 -
67 - return $result;
68 - }
69 -
70 -
71 - /**
72 - * Delete a customer record.
73 - *
74 - * @param int $id customer ID
75 - */
76 - public static function delete_response( $id ) {
77 - global $wpdb;
78 -
79 - $wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
80 - "{$wpdb->prefix}wpbot_response",
81 - [ 'id' => $id ],
82 - [ '%d' ]
83 - );
84 -
85 - }
86 -
87 -
88 - /**
89 - * Returns the count of records in the database.
90 - *
91 - * @return null|string
92 - */
93 - public static function record_count() {
94 - global $wpdb;
95 -
96 - $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}wpbot_response";
97 -
98 - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
99 - }
100 -
101 -
102 - /** Text displayed when no customer data is available */
103 - public function no_items() {
104 - esc_html_e( 'No responses avaliable.', 'chatbot' );
105 - }
106 -
107 -
108 - /**
109 - * Render a column when no column specific method exist.
110 - *
111 - * @param array $item
112 - * @param string $column_name
113 - *
114 - * @return mixed
115 - */
116 - public function column_default( $item, $column_name ) {
117 -
118 -
119 -
120 -
121 - if(class_exists('Qcld_str_pro')){
122 - switch ( $column_name ) {
123 - case 'query':
124 - case 'keyword':
125 - case 'intent':
126 - case 'category':
127 - return $item[ $column_name ];
128 -
129 - case 'responses':
130 - return $item[ 'response' ];
131 - default:
132 - return print_r( $item, true ); //Show the whole array for troubleshooting purposes
133 - }
134 - }else{
135 - switch ( $column_name ) {
136 - case 'query':
137 - case 'keyword':
138 - case 'intent':
139 - return $item[ $column_name ];
140 -
141 - case 'responses':
142 - return $item[ 'response' ];
143 - default:
144 - return print_r( $item, true ); //Show the whole array for troubleshooting purposes
145 - }
146 - }
147 -
148 - }
149 -
150 - /**
151 - * Render the bulk edit checkbox
152 - *
153 - * @param array $item
154 - *
155 - * @return string
156 - */
157 - function column_cb( $item ) {
158 - return sprintf(
159 - '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id']
160 - );
161 - }
162 -
163 -
164 - /**
165 - * Method for name column
166 - *
167 - * @param array $item an array of DB data
168 - *
169 - * @return string
170 - */
171 - function column_query( $item ) {
172 -
173 - $delete_nonce = wp_create_nonce( 'wp_delete_query' );
174 - $edit_nonce = wp_create_nonce( 'wp_edit_query' );
175 -
176 - $title = '<strong>' . $item['query'] . '</strong>';
177 -// var_dump($title);
178 - $actions = [
179 - 'edit' => sprintf( '<a href="?page=%s&action=%s&query=%s&_wpnonce=%s">Edit</a>', esc_attr(wp_unslash($_REQUEST['page'])), 'edit', absint( $item['id'] ), $edit_nonce ),
180 - 'delete' => sprintf( '<a href="?page=%s&action=%s&query=%s&_wpnonce=%s">Delete</a>', esc_attr(wp_unslash($_REQUEST['page'])), 'delete', absint( $item['id'] ), $delete_nonce )
181 - ];
182 -
183 - return $title . $this->row_actions( $actions );
184 - }
185 -
186 -
187 - /**
188 - * Associative array of columns
189 - *
190 - * @return array
191 - */
192 - function get_columns() {
193 -
194 -
195 - if(class_exists('Qcld_str_pro')){
196 - $columns = [
197 - 'cb' => '<input type="checkbox" />',
198 - 'query' => __( 'Query', 'chatbot' ),
199 - 'keyword' => __( 'Keyword', 'chatbot' ),
200 - 'responses' => __( 'Response', 'chatbot' ),
201 - 'intent'=> __( 'Intent', 'chatbot' ),
202 - 'category'=> __( 'Category', 'chatbot' ),
203 -
204 - ];
205 - }else{
206 - $columns = [
207 - 'cb' => '<input type="checkbox" />',
208 - 'query' => __( 'Query', 'chatbot' ),
209 - 'keyword' => __( 'Keyword', 'chatbot' ),
210 - 'responses' => __( 'Response', 'chatbot' ),
211 - 'intent'=> __( 'Intent', 'chatbot' ),
212 -
213 - ];
214 - }
215 -
216 - return $columns;
217 - }
218 -
219 -
220 - /**
221 - * Columns to make sortable.
222 - *
223 - * @return array
224 - */
225 - public function get_sortable_columns() {
226 - $sortable_columns = array(
227 - 'query' => array( 'query', true ),
228 - );
229 -
230 - return $sortable_columns;
231 - }
232 -
233 - /**
234 - * Returns an associative array containing the bulk action
235 - *
236 - * @return array
237 - */
238 - public function get_bulk_actions() {
239 - $actions = [
240 - 'bulk-delete' => 'Delete'
241 - ];
242 -
243 - return $actions;
244 - }
245 -
246 -
247 - /**
248 - * Handles data query and filter, sorting, and pagination.
249 - */
250 - public function prepare_items() {
251 -
252 - $this->_column_headers = $this->get_column_info();
253 -
254 - /** Process bulk action */
255 - $this->process_bulk_action();
256 - if( !empty($_POST['wp_screen_options'] )){
257 - $per_page = (int)$_POST['wp_screen_options']["value"];
258 - }else{
259 - $per_page = $this->get_items_per_page( 'responses_per_page' );
260 -
261 - }
262 - $current_page = $this->get_pagenum();
263 - $total_items = self::record_count();
264 -
265 - $this->set_pagination_args( [
266 - 'total_items' => $total_items, //WE have to calculate the total number of items
267 - 'per_page' => $per_page //WE have to determine how many items to show on a page
268 - ] );
269 -
270 - $this->items = self::get_responses( $per_page, $current_page );
271 - }
272 -
273 - public function process_bulk_action() {
274 -
275 -
276 -
277 - //Detect when a bulk action is being triggered...
278 - if ( 'delete' === $this->current_action() ) {
279 -
280 - // In our file that handles the request, verify the nonce.
281 - $nonce = esc_attr(wp_unslash($_REQUEST['_wpnonce']));
282 -
283 - if ( ! wp_verify_nonce( $nonce, 'wp_delete_query' ) ) {
284 - die( 'Go get a life script kiddies' );
285 - }
286 - else {
287 - self::delete_response( absint( wp_unslash($_GET['query']) ) );
288 -
289 - // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
290 - // add_query_arg() return the current url
291 - //wp_redirect( esc_url_raw($this->chatbot_admin_page) );
292 - //exit;
293 - }
294 -
295 - }
296 -
297 - // If the delete bulk action is triggered
298 - if ( ( isset($_POST['action']) && wp_unslash($_POST['action']) == 'bulk-delete' )
299 - || ( isset($_POST['action2']) && wp_unslash($_POST['action2']) == 'bulk-delete' )
300 - ) {
301 -
302 - $delete_ids = esc_sql( wp_unslash($_POST['bulk-delete']) );
303 -
304 -
305 - // loop over the array of record IDs and delete them
306 - foreach ( $delete_ids as $id ) {
307 - self::delete_response( $id );
308 -
309 - }
310 -
311 - // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
312 - // add_query_arg() return the current url
313 - wp_safe_redirect( esc_url_raw($this->chatbot_admin_page) );
314 - exit;
315 - }
316 - }
317 -
1 +<?php
2 +if ( ! class_exists( 'WP_List_Table' ) ) {
3 + require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4 +}
5 +
6 +class Response_list extends WP_List_Table {
7 +
8 +
9 + public $chatbot_admin_page;
10 + /** Class constructor */
11 + public function __construct() {
12 +
13 + parent::__construct( [
14 + 'singular' => __( 'Response', 'wpchatbot' ), //singular name of the listed records
15 + 'plural' => __( 'Responses', 'wpchatbot' ), //plural name of the listed records
16 + 'ajax' => false //does this table support ajax?
17 + ] );
18 +
19 + $this->chatbot_admin_page = admin_url('admin.php?page=simple-text-response');
20 +
21 + }
22 +
23 +
24 + /**
25 + * Retrieve customers data from the database
26 + *
27 + * @param int $per_page
28 + * @param int $page_number
29 + *
30 + * @return mixed
31 + */
32 + public static function get_responses( $per_page = 5, $page_number = 1 ) {
33 +
34 +
35 + global $wpdb;
36 +
37 + $order = "id";
38 + $orderby = " ASC";
39 +
40 + if ( ! empty( $_REQUEST['orderby'] ) ) {
41 + $orderby .= sanitize_sql_orderby('ORDER BY ' . esc_sql( $_REQUEST['orderby'] ));
42 + $order .= ! empty( $_REQUEST['order'] ) ? '' . sanitize_sql_orderby(esc_sql( $_REQUEST['order'] )) : ' ASC';
43 +
44 + }
45 +
46 + $offset = ( $page_number - 1 ) * $per_page;
47 +
48 + $safe_sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbot_response ORDER BY %s %s LIMIT %d OFFSET %d", $orderby, $order, $per_page, $offset);
49 +
50 + $result = $wpdb->get_results( $safe_sql, 'ARRAY_A' ); //DB Call OK, No Caching OK
51 +
52 + return $result;
53 + }
54 +
55 +
56 + /**
57 + * Delete a customer record.
58 + *
59 + * @param int $id customer ID
60 + */
61 + public static function delete_response( $id ) {
62 + global $wpdb;
63 +
64 + $wpdb->delete(
65 + "{$wpdb->prefix}wpbot_response",
66 + [ 'id' => $id ],
67 + [ '%d' ]
68 + ); //DB Call OK, No Caching OK
69 +
70 + }
71 +
72 +
73 + /**
74 + * Returns the count of records in the database.
75 + *
76 + * @return null|string
77 + */
78 + public static function record_count() {
79 + global $wpdb;
80 +
81 + $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}wpbot_response";
82 +
83 + return $wpdb->get_var( $sql ); //DB Call OK, No Caching OK
84 + }
85 +
86 +
87 + /** Text displayed when no customer data is available */
88 + public function no_items() {
89 + esc_html_e( 'No responses avaliable.', 'wpchatbot' );
90 + }
91 +
92 +
93 + /**
94 + * Render a column when no column specific method exist.
95 + *
96 + * @param array $item
97 + * @param string $column_name
98 + *
99 + * @return mixed
100 + */
101 + public function column_default( $item, $column_name ) {
102 +
103 +
104 +
105 +
106 + if(class_exists('Qcld_str_pro')){
107 + switch ( $column_name ) {
108 + case 'query':
109 + case 'keyword':
110 + case 'intent':
111 + case 'category':
112 + return $item[ $column_name ];
113 +
114 + case 'responses':
115 + return $item[ 'response' ];
116 + default:
117 + return print_r( $item, true ); //Show the whole array for troubleshooting purposes
118 + }
119 + }else{
120 + switch ( $column_name ) {
121 + case 'query':
122 + case 'keyword':
123 + case 'intent':
124 + return $item[ $column_name ];
125 +
126 + case 'responses':
127 + return $item[ 'response' ];
128 + default:
129 + return print_r( $item, true ); //Show the whole array for troubleshooting purposes
130 + }
131 + }
132 +
133 + }
134 +
135 + /**
136 + * Render the bulk edit checkbox
137 + *
138 + * @param array $item
139 + *
140 + * @return string
141 + */
142 + function column_cb( $item ) {
143 + return sprintf(
144 + '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id']
145 + );
146 + }
147 +
148 +
149 + /**
150 + * Method for name column
151 + *
152 + * @param array $item an array of DB data
153 + *
154 + * @return string
155 + */
156 + function column_query( $item ) {
157 +
158 + $delete_nonce = wp_create_nonce( 'wp_delete_query' );
159 + $edit_nonce = wp_create_nonce( 'wp_edit_query' );
160 +
161 + $title = '<strong>' . $item['query'] . '</strong>';
162 +
163 + $actions = [
164 + 'edit' => sprintf( '<a href="?page=%s&action=%s&query=%s&_wpnonce=%s">Edit</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ), $edit_nonce ),
165 + 'delete' => sprintf( '<a href="?page=%s&action=%s&query=%s&_wpnonce=%s">Delete</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['id'] ), $delete_nonce )
166 + ];
167 +
168 + return $title . $this->row_actions( $actions );
169 + }
170 +
171 +
172 + /**
173 + * Associative array of columns
174 + *
175 + * @return array
176 + */
177 + function get_columns() {
178 +
179 +
180 + if(class_exists('Qcld_str_pro')){
181 + $columns = [
182 + 'cb' => '<input type="checkbox" />',
183 + 'query' => __( 'Query', 'wpchatbot' ),
184 + 'keyword' => __( 'Keyword', 'wpchatbot' ),
185 + 'responses' => __( 'Response', 'wpchatbot' ),
186 + 'intent'=> __( 'Intent', 'wpchatbot' ),
187 + 'category'=> __( 'Category', 'wpchatbot' ),
188 +
189 + ];
190 + }else{
191 + $columns = [
192 + 'cb' => '<input type="checkbox" />',
193 + 'query' => __( 'Query', 'wpchatbot' ),
194 + 'keyword' => __( 'Keyword', 'wpchatbot' ),
195 + 'responses' => __( 'Response', 'wpchatbot' ),
196 + 'intent'=> __( 'Intent', 'wpchatbot' ),
197 +
198 + ];
199 + }
200 +
201 + return $columns;
202 + }
203 +
204 +
205 + /**
206 + * Columns to make sortable.
207 + *
208 + * @return array
209 + */
210 + public function get_sortable_columns() {
211 + $sortable_columns = array(
212 + 'query' => array( 'query', true ),
213 + );
214 +
215 + return $sortable_columns;
216 + }
217 +
218 + /**
219 + * Returns an associative array containing the bulk action
220 + *
221 + * @return array
222 + */
223 + public function get_bulk_actions() {
224 + $actions = [
225 + 'bulk-delete' => 'Delete'
226 + ];
227 +
228 + return $actions;
229 + }
230 +
231 +
232 + /**
233 + * Handles data query and filter, sorting, and pagination.
234 + */
235 + public function prepare_items() {
236 +
237 + $this->_column_headers = $this->get_column_info();
238 +
239 + /** Process bulk action */
240 + $this->process_bulk_action();
241 + if( !empty($_POST['wp_screen_options'] )){
242 + $per_page = (int)$_POST['wp_screen_options']["value"];
243 + }else{
244 + $per_page = $this->get_items_per_page( 'responses_per_page' );
245 +
246 + }
247 + $current_page = $this->get_pagenum();
248 + $total_items = self::record_count();
249 +
250 + $this->set_pagination_args( [
251 + 'total_items' => $total_items, //WE have to calculate the total number of items
252 + 'per_page' => $per_page //WE have to determine how many items to show on a page
253 + ] );
254 +
255 + $this->items = self::get_responses( $per_page, $current_page );
256 + }
257 +
258 + public function process_bulk_action() {
259 +
260 +
261 +
262 + //Detect when a bulk action is being triggered...
263 + if ( 'delete' === $this->current_action() ) {
264 +
265 + // In our file that handles the request, verify the nonce.
266 + $nonce = esc_attr( $_REQUEST['_wpnonce'] );
267 +
268 + if ( ! wp_verify_nonce( $nonce, 'wp_delete_query' ) ) {
269 + die( 'Go get a life script kiddies' );
270 + }
271 + else {
272 + self::delete_response( absint( $_GET['query'] ) );
273 +
274 + // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
275 + // add_query_arg() return the current url
276 + //wp_redirect( esc_url_raw($this->chatbot_admin_page) );
277 + //exit;
278 + }
279 +
280 + }
281 +
282 + // If the delete bulk action is triggered
283 + if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
284 + || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
285 + ) {
286 +
287 + $delete_ids = esc_sql( $_POST['bulk-delete'] );
288 +
289 +
290 + // loop over the array of record IDs and delete them
291 + foreach ( $delete_ids as $id ) {
292 + self::delete_response( $id );
293 +
294 + }
295 +
296 + // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
297 + // add_query_arg() return the current url
298 + wp_redirect( esc_url_raw($this->chatbot_admin_page) );
299 + exit;
300 + }
301 + }
302 +
318 303 }