PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.8.0
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.8.0
8.8.0 8.7.9 8.7.8 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 All 536 releases
chatbot / qc-rating-feature / qc-rating-class.php

qc-rating-class.php in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.8.0, at qc-rating-feature/qc-rating-class.php

413 lines 17.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * QuantumCloud Promo + Support Page
4 * Revised On: 06-01-2017
5 */
6
7 /*******************************
8 * Main Class to Display Support
9 * form and the promo pages
10 *******************************/
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
12 if( !class_exists('Wpbot_rating') ){
13
14 class Wpbot_rating{
15
16 public $plugin_name = "wpbot"; //Without spaces
17 public $plugin_full_name = "ChatBot";
18 public $logo_url;
19
20 public $plugin_rating_url = "https://wordpress.org/support/plugin/chatbot/reviews/";
21
22 public function __construct(){
23 $this->logo_url = QCLD_wpCHATBOT_IMG_URL . "/chatbot.png";
24
25 }
26
27 function run(){
28 add_action('admin_init', array($this, 'qc_admin_notice_rating'));
29
30 add_action('wp_ajax_qc_chatbot_feedback_notice_dismiss', array($this, 'notice_dismiss'));
31 add_action('wp_ajax_qc_chatbot_blackfriday_notice_dismiss', array($this, 'blackfriday_notice_dismiss'));
32 add_action('wp_ajax_qc_chatbot_generate_review_ai', array($this, 'generate_review_ai'));
33 }
34
35 public function blackfriday_notice_dismiss(){
36 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'wp_chatbot' ) ) {
37 wp_send_json_error( array( 'message' => 'Security check failed.' ) );
38 }
39 if ( ! current_user_can( 'manage_options' ) ) {
40 wp_send_json_error( array( 'message' => 'Unauthorized.' ) );
41 }
42 update_option('wpbot-admin-notice-blackfriday', 'hide');
43 die(0);
44 }
45 public function notice_dismiss(){
46 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'wp_chatbot' ) ) {
47 wp_send_json_error( array( 'message' => 'Security check failed.' ) );
48 }
49 if ( ! current_user_can( 'manage_options' ) ) {
50 wp_send_json_error( array( 'message' => 'Unauthorized.' ) );
51 }
52 update_option('wpbot-admin-notice-oninstallation', 'hide');
53 die(0);
54 }
55
56 /**
57 * Check and Dismiss review message.
58 *
59 */
60 private function review_dismissal() {
61
62
63
64 //delete_site_option( 'wp_analytify_review_dismiss' );
65 if ( ! is_admin() ||
66 ! isset( $_GET['_wpnonce'] ) ||
67 ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'qc-'.$this->plugin_name.'-rating-nonce' ) ||
68 ! isset( $_GET['qc_'.$this->plugin_name.'_rating_dismiss'] ) ) {
69
70 return;
71 }
72
73
74 update_option( 'qc_'.$this->plugin_name.'_rating_dismiss', 'yes' );
75
76 }
77
78 /**
79 * Set time to current so review notice will popup after X days
80 */
81 function review_prending() {
82
83 // delete_site_option( 'wp_analytify_review_dismiss' );
84 if ( ! is_admin() ||
85 ! isset( $_GET['_wpnonce'] ) ||
86 ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'qc-'.$this->plugin_name.'-rating-nonce' ) ||
87 ! isset( $_GET['qc_'.$this->plugin_name.'_rating_later'] ) ) {
88
89 return;
90 }
91
92 // Reset Time to current time.
93 update_option( 'qc_'.$this->plugin_name.'_rating_active_time', time() );
94
95 }
96
97 public function qc_admin_notice_rating(){
98
99 $this->review_dismissal();
100 $this->review_prending();
101
102 $activation_time = get_option( 'qc_'.$this->plugin_name.'_rating_active_time' );
103 $review_dismissal = get_option( 'qc_'.$this->plugin_name.'_rating_dismiss' );
104 if ( 'yes' == $review_dismissal ) {
105 if( get_option( 'wpbot-admin-notice-oninstallation' ) && get_option( 'wpbot-admin-notice-oninstallation' ) == 'show' && $this->is_wpbot_page() ){
106 add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') );
107 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
108 }
109 return;
110 }
111 if ( ! $activation_time ) {
112 $activation_time = time();
113 add_option( 'qc_'.$this->plugin_name.'_rating_active_time', $activation_time );
114 }
115
116 // 604800 = 7 Days in seconds.
117
118 if ( time() - $activation_time > 604800 && $this->is_wpbot_page() ) {
119 add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') );
120 add_action( 'admin_notices' , array( $this, 'qc_rating_notice_message' ) );
121 }else{
122 if( get_option( 'wpbot-admin-notice-oninstallation' ) && get_option( 'wpbot-admin-notice-oninstallation' ) == 'show' && $this->is_wpbot_page() ){
123 add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') );
124 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
125 }
126 }
127
128 }
129
130 public function admin_notice(){
131
132 ?>
133 <div data-dismiss-type="qcbot-feedback-notice" class="notice is-dismissible qcbot-feedback">
134 <div class="wpbot-notice-content">
135 <div class="qc-review-thumbnail qc-small-thumb">
136 <img src="<?php echo esc_url($this->logo_url); ?>" alt="halloween">
137 </div>
138
139 <div class="qc-review-text">
140
141 <p style="font-weight:bold; font-size: 17px;color: var(--woobot-primary) !important;"><?php esc_html_e( 'Hello! Thank you for using our ChatBot.', 'chatbot' ) ?></p>
142
143 <p><?php esc_html_e( 'If you have any feedback or need help, please ', 'chatbot' ) ?><b><a href="<?php echo esc_url('https://www.wpbot.pro/free-support/'); ?>" target="_blank"><?php esc_html_e( 'Contact Us', 'chatbot' ) ?></a></b><?php esc_html_e( '. We take all user feedback seriously and resolve all issues.', 'chatbot' ) ?></p>
144
145 </div>
146 </div>
147 </div>
148 <?php
149 /* Delete transient, only display this notice once. */
150 delete_transient( 'wpbot-admin-notice-oninstallation' );
151 }
152
153 public function is_wpbot_page(){
154
155 $status = false;
156 if( ( isset( $_GET['page'] ) && $_GET['page'] == 'wpbot-panel' ) || ( isset( $_GET['page'] ) && $_GET['page'] == 'wpbot' ) || ( isset( $_GET['page'] ) && $_GET['page'] == 'simple-text-response' ) || ( isset( $_GET['page'] ) && $_GET['page'] == 'wpbot_support_page' ) || ( isset( $_GET['page'] ) && $_GET['page'] == 'wpbot_help_page' ) ){
157 $status = true;
158 }
159 return $status;
160
161 }
162
163 public function qc_load_rating_style(){
164 wp_enqueue_style( 'qc_rating_stylesheet', plugin_dir_url(__FILE__)."css/style.css");
165 wp_register_script( 'qc_rating_js', plugin_dir_url(__FILE__)."js/rating.js", array('jquery'), '1.02.2' , true);
166 $translation_array = array(
167 'ajax_url' => admin_url( 'admin-ajax.php' ),
168 'nonce' => wp_create_nonce( 'qc_chatbot_rating_nonce' ),
169 );
170 wp_localize_script( 'qc_rating_js', 'qcld_rating_object', $translation_array );
171 wp_enqueue_script( 'qc_rating_js');
172
173 }
174
175 public function qc_rating_notice_message(){
176
177 /*if ( ! is_admin() ||
178 ! current_user_can( 'manage_options' ) ) {
179 return;
180 }*/
181
182 $scheme = ( wp_parse_url( isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '', PHP_URL_QUERY ) ) ? '&' : '?';
183
184 $url = esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'] . $scheme . 'qc_'.$this->plugin_name.'_rating_dismiss=yes'));
185
186 $dismiss_url = wp_nonce_url( $url, 'qc-'.$this->plugin_name.'-rating-nonce' );
187
188 $_later_link = esc_url_raw($_SERVER['REQUEST_URI']) . $scheme . 'qc_'.$this->plugin_name.'_rating_later=yes';
189
190 $later_url = wp_nonce_url( $_later_link, 'qc-'.$this->plugin_name.'-rating-nonce' );
191
192 ?>
193 <div class="notice is-dismissible qcbot-str-top-notic" style="background-color: #ffffff;border-radius: 16px;margin: 20px 0 0 0;border-left: 4px solid transparent; border:none;">
194 <div class="wpbot-notice-content">
195 <div class="qc-review-thumbnail">
196 <img src="<?php echo esc_url($this->logo_url); ?>" alt="">
197 </div>
198
199 <div class="qc-review-text">
200
201 <p style="font-weight:bold; font-size: 17px;color: var(--woobot-primary) !important;"><?php esc_html_e( 'Hello! Thank you for using our ChatBot.', 'chatbot' ) ?></p>
202
203 <p style="display:inline-block">
204 <b><?php esc_html_e( 'If you have any feedback or need help, please ', 'chatbot' ) ?><a style="display:inline-block" href="<?php echo esc_url('https://www.wpbot.pro/free-support/'); ?>" target="_blank"><?php esc_html_e( 'Contact Us', 'chatbot' ) ?></a></b><?php esc_html_e( '. We take all user feedback seriously and resolve all issues.', 'chatbot' ) ?><br><?php esc_html_e( 'If you found our plugin useful, please take a minute to leave the plugin a 5 Star rating on WordPress. That really boosts our confidence and encourages us to keep adding new features to the plugin.', 'chatbot' ) ?>
205 </p>
206
207 <ul class="qc-review-ul">
208
209 <li><a href="<?php echo esc_url($this->plugin_rating_url); ?>" target="_blank"><span class="dashicons dashicons-star-filled"></span><?php esc_html_e( 'Leave A Review', 'chatbot' ) ?></a></li>
210 <li><a href="#" id="qc-write-review-ai" style="background-color: var(--woobot-primary); color: #fff; border-color: var(--woobot-primary);"><span class="dashicons dashicons-admin-customizer" style="color: #fff; margin-right: 5px;"></span><?php esc_html_e( 'Generate Review with AI', 'chatbot' ) ?></a></li>
211 <li><a href="<?php echo esc_url($dismiss_url) ?>"><span class="dashicons dashicons-yes"></span><?php esc_html_e( 'I\'ve already left a review', 'chatbot' ) ?></a></li>
212 <li><a href="<?php echo esc_url($later_url) ?>"><span class="dashicons dashicons-calendar"></span><?php esc_html_e( 'Maybe Later', 'chatbot' ) ?></a></li>
213 <li><a href="<?php echo esc_url($dismiss_url) ?>"><span class="dashicons dashicons-no"></span><?php esc_html_e( 'Never show this again', 'chatbot' ) ?></a></li>
214
215 </ul>
216
217 <div id="qc-ai-review-container" class="qc-ai-review-wrapper" style="display: none; margin-top: 15px; padding: 15px; background: #fcfbff; border: 1px dashed var(--woobot-primary); border-radius: 8px; max-width: 600px;">
218 <p style="font-weight: bold; color: var(--woobot-primary); margin-bottom: 8px; display: flex; align-items: center; gap: 5px;">
219 <span class="dashicons dashicons-admin-customizer"></span>
220 <?php esc_html_e( 'AI Generated Review (5 Stars)', 'chatbot' ); ?>:
221 </p>
222 <textarea id="qc-ai-review-text" style="width: 100%; height: 75px; resize: none; margin-bottom: 10px; padding: 8px; border-radius: 4px; border: 1px solid #ddd; background: #fff; font-size: 13px; color: #333;" readonly></textarea>
223 <div class="qc-ai-review-actions" style="display: flex; gap: 10px; align-items: center;">
224 <button type="button" id="qc-copy-review-btn" class="button button-secondary" style="height: 32px; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 4px;">
225 <span class="dashicons dashicons-clipboard" style="font-size: 16px; width: 16px; height: 16px;"></span>
226 <span class="qc-btn-text"><?php esc_html_e( 'Copy to Clipboard', 'chatbot' ); ?></span>
227 </button>
228 <a href="<?php echo esc_url($this->plugin_rating_url); ?>" target="_blank" class="button button-primary" style="height: 32px; font-size: 12px; line-height: 30px; display: inline-flex; align-items: center; justify-content: center; gap: 4px;">
229 <span class="dashicons dashicons-external" style="font-size: 16px; width: 16px; height: 16px; color: #fff;"></span>
230 <?php esc_html_e( 'Paste & Submit Review', 'chatbot' ); ?>
231 </a>
232 </div>
233 </div>
234 </div>
235 </div>
236 </div>
237 <?php
238 }
239
240 public function generate_review_ai() {
241 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'qc_chatbot_rating_nonce' ) ) {
242 wp_send_json_error( array( 'message' => 'Security check failed.' ) );
243 }
244 if ( ! current_user_can( 'manage_options' ) ) {
245 wp_send_json_error( array( 'message' => 'Unauthorized.' ) );
246 }
247
248 // Predefined reviews as fallback
249 $fallback_reviews = array(
250 "WPBot is an absolute game-changer for WordPress! The AI integration is seamless, making customer support automated and highly responsive. Highly recommend it to anyone looking to enhance user interaction.",
251 "I am highly impressed with the capabilities of this ChatBot. It is incredibly easy to set up and customize. The GPT/Gemini integration works flawlessly, taking customer engagement to the next level.",
252 "WPBot is by far the best AI chatbot plugin for WordPress. It handles client queries with high accuracy and has significantly reduced our support workload. The setup is simple and user-friendly.",
253 "Fantastic plugin with rich features! The customer service and automation options are top-notch. Integrating it with AI APIs was a breeze, and it functions perfectly on our site.",
254 "A brilliant, highly intuitive chatbot plugin. It works exactly as described and has greatly boosted our lead generation. Truly a 5-star product with excellent developer support!"
255 );
256
257 $selected_review = $fallback_reviews[ array_rand( $fallback_reviews ) ];
258
259 $prompt = "Write a short, engaging 5-star review (maximum 2-3 sentences) for the WordPress plugin 'AI ChatBot - WPBot'. Focus on its helpfulness, AI integration, or ease of use. Keep the tone friendly, helpful, and natural. Do not use quotes or placeholders.";
260
261 // Check which AI is enabled
262 $ai_enabled = get_option('ai_enabled');
263 $gemini_enabled = (get_option('qcld_gemini_enabled') == '1');
264 $grok_enabled = (get_option('qcld_grok_enabled') == '1');
265 $openrouter_enabled = (get_option('qcld_openrouter_enabled') == '1');
266
267 if ( $gemini_enabled ) {
268 $gemini_api_key = get_option('qcld_gemini_api_key');
269 if ( ! empty( $gemini_api_key ) ) {
270 $selected_model = get_option('qcld_gemini_model') ? get_option('qcld_gemini_model') : 'gemini-2.5-flash';
271 $api_url = 'https://generativelanguage.googleapis.com/v1/models/' . $selected_model . ':generateContent';
272
273 $data = array(
274 'contents' => array(
275 array(
276 'role' => 'user',
277 'parts' => array(
278 array( 'text' => $prompt )
279 )
280 )
281 ),
282 );
283
284 $args = array(
285 'body' => json_encode( $data ),
286 'headers' => array(
287 'Content-Type' => 'application/json',
288 'X-goog-api-key' => $gemini_api_key,
289 ),
290 'timeout' => 30,
291 'blocking' => true,
292 );
293
294 $result = wp_remote_post( $api_url, $args );
295 if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) {
296 $body = json_decode( wp_remote_retrieve_body( $result ), true );
297 if ( isset( $body['candidates'][0]['content']['parts'][0]['text'] ) ) {
298 $selected_review = trim( $body['candidates'][0]['content']['parts'][0]['text'] );
299 }
300 }
301 }
302 } elseif ( $ai_enabled ) {
303 $openai_api_key = get_option('open_ai_api_key');
304 if ( ! empty( $openai_api_key ) ) {
305 $model = get_option( 'qcld_openai_custom_model' );
306 if ( empty( $model ) ) {
307 $model = get_option( 'openai_engines', 'gpt-4o' );
308 }
309 $api_url = 'https://api.openai.com/v1/chat/completions';
310
311 $data = array(
312 'model' => $model,
313 'messages' => array(
314 array( 'role' => 'user', 'content' => $prompt )
315 ),
316 );
317
318 $args = array(
319 'body' => json_encode( $data ),
320 'headers' => array(
321 'Content-Type' => 'application/json',
322 'Authorization' => 'Bearer ' . $openai_api_key,
323 ),
324 'timeout' => 30,
325 'blocking' => true,
326 );
327
328 $result = wp_remote_post( $api_url, $args );
329 if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) {
330 $body = json_decode( wp_remote_retrieve_body( $result ), true );
331 if ( isset( $body['choices'][0]['message']['content'] ) ) {
332 $selected_review = trim( $body['choices'][0]['message']['content'] );
333 }
334 }
335 }
336 } elseif ( $openrouter_enabled ) {
337 $openrouter_api_key = get_option('qcld_openrouter_api_key');
338 if ( ! empty( $openrouter_api_key ) ) {
339 $model = get_option( 'qcld_openrouter_model', 'google/gemini-2.5-pro' );
340 $api_url = 'https://openrouter.ai/api/v1/chat/completions';
341
342 $data = array(
343 'model' => $model,
344 'messages' => array(
345 array( 'role' => 'user', 'content' => $prompt )
346 ),
347 );
348
349 $args = array(
350 'body' => json_encode( $data ),
351 'headers' => array(
352 'Content-Type' => 'application/json',
353 'Authorization' => 'Bearer ' . $openrouter_api_key,
354 ),
355 'timeout' => 30,
356 'blocking' => true,
357 );
358
359 $result = wp_remote_post( $api_url, $args );
360 if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) {
361 $body = json_decode( wp_remote_retrieve_body( $result ), true );
362 if ( isset( $body['choices'][0]['message']['content'] ) ) {
363 $selected_review = trim( $body['choices'][0]['message']['content'] );
364 }
365 }
366 }
367 } elseif ( $grok_enabled ) {
368 $grok_api_key = get_option('qcld_grok_api_key');
369 if ( ! empty( $grok_api_key ) ) {
370 $model = get_option( 'qcld_grok_model', 'grok-2' );
371 $api_url = 'https://api.x.ai/v1/chat/completions';
372
373 $data = array(
374 'model' => $model,
375 'messages' => array(
376 array( 'role' => 'user', 'content' => $prompt )
377 ),
378 );
379
380 $args = array(
381 'body' => json_encode( $data ),
382 'headers' => array(
383 'Content-Type' => 'application/json',
384 'Authorization' => 'Bearer ' . $grok_api_key,
385 ),
386 'timeout' => 30,
387 'blocking' => true,
388 );
389
390 $result = wp_remote_post( $api_url, $args );
391 if ( ! is_wp_error( $result ) && wp_remote_retrieve_response_code( $result ) === 200 ) {
392 $body = json_decode( wp_remote_retrieve_body( $result ), true );
393 if ( isset( $body['choices'][0]['message']['content'] ) ) {
394 $selected_review = trim( $body['choices'][0]['message']['content'] );
395 }
396 }
397 }
398 }
399
400 // Clean up output
401 $selected_review = trim( $selected_review, '"\'' );
402
403 wp_send_json_success( array( 'review' => $selected_review ) );
404 }
405
406 }
407 }
408 $qc_wpbot_rating = new Wpbot_rating();
409
410 $qc_wpbot_rating->plugin_name = 'wpbot';
411
412 $qc_wpbot_rating->run();
413