| 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 |
} |
| 33 |
|
| 34 |
public function blackfriday_notice_dismiss(){ |
| 35 |
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'wp_chatbot' ) ) { |
| 36 |
wp_send_json_error( array( 'message' => 'Security check failed.' ) ); |
| 37 |
} |
| 38 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 39 |
wp_send_json_error( array( 'message' => 'Unauthorized.' ) ); |
| 40 |
} |
| 41 |
update_option('wpbot-admin-notice-blackfriday', 'hide'); |
| 42 |
die(0); |
| 43 |
} |
| 44 |
public function notice_dismiss(){ |
| 45 |
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['nonce'])), 'wp_chatbot' ) ) { |
| 46 |
wp_send_json_error( array( 'message' => 'Security check failed.' ) ); |
| 47 |
} |
| 48 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 49 |
wp_send_json_error( array( 'message' => 'Unauthorized.' ) ); |
| 50 |
} |
| 51 |
update_option('wpbot-admin-notice-oninstallation', 'hide'); |
| 52 |
die(0); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Check and Dismiss review message. |
| 57 |
* |
| 58 |
*/ |
| 59 |
private function review_dismissal() { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
//delete_site_option( 'wp_analytify_review_dismiss' ); |
| 64 |
if ( ! is_admin() || |
| 65 |
! isset( $_GET['_wpnonce'] ) || |
| 66 |
! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'qc-'.$this->plugin_name.'-rating-nonce' ) || |
| 67 |
! isset( $_GET['qc_'.$this->plugin_name.'_rating_dismiss'] ) ) { |
| 68 |
|
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
update_option( 'qc_'.$this->plugin_name.'_rating_dismiss', 'yes' ); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Set time to current so review notice will popup after X days |
| 79 |
*/ |
| 80 |
function review_prending() { |
| 81 |
|
| 82 |
// delete_site_option( 'wp_analytify_review_dismiss' ); |
| 83 |
if ( ! is_admin() || |
| 84 |
! isset( $_GET['_wpnonce'] ) || |
| 85 |
! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'qc-'.$this->plugin_name.'-rating-nonce' ) || |
| 86 |
! isset( $_GET['qc_'.$this->plugin_name.'_rating_later'] ) ) { |
| 87 |
|
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
// Reset Time to current time. |
| 92 |
update_option( 'qc_'.$this->plugin_name.'_rating_active_time', time() ); |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
public function qc_admin_notice_rating(){ |
| 97 |
|
| 98 |
$this->review_dismissal(); |
| 99 |
$this->review_prending(); |
| 100 |
|
| 101 |
$activation_time = get_option( 'qc_'.$this->plugin_name.'_rating_active_time' ); |
| 102 |
$review_dismissal = get_option( 'qc_'.$this->plugin_name.'_rating_dismiss' ); |
| 103 |
if ( 'yes' == $review_dismissal ) { |
| 104 |
if( get_option( 'wpbot-admin-notice-oninstallation' ) && get_option( 'wpbot-admin-notice-oninstallation' ) == 'show' && $this->is_wpbot_page() ){ |
| 105 |
add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') ); |
| 106 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
| 107 |
} |
| 108 |
return; |
| 109 |
} |
| 110 |
if ( ! $activation_time ) { |
| 111 |
$activation_time = time(); |
| 112 |
add_option( 'qc_'.$this->plugin_name.'_rating_active_time', $activation_time ); |
| 113 |
} |
| 114 |
|
| 115 |
// 604800 = 7 Days in seconds. |
| 116 |
|
| 117 |
if ( time() - $activation_time > 604800 && $this->is_wpbot_page() ) { |
| 118 |
add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') ); |
| 119 |
add_action( 'admin_notices' , array( $this, 'qc_rating_notice_message' ) ); |
| 120 |
}else{ |
| 121 |
if( get_option( 'wpbot-admin-notice-oninstallation' ) && get_option( 'wpbot-admin-notice-oninstallation' ) == 'show' && $this->is_wpbot_page() ){ |
| 122 |
add_action( 'admin_enqueue_scripts', array($this, 'qc_load_rating_style') ); |
| 123 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
public function admin_notice(){ |
| 130 |
|
| 131 |
?> |
| 132 |
<div data-dismiss-type="qcbot-feedback-notice" class="notice is-dismissible qcbot-feedback"> |
| 133 |
<div class="wpbot-notice-content"> |
| 134 |
<div class="qc-review-thumbnail qc-small-thumb"> |
| 135 |
<img src="<?php echo esc_url($this->logo_url); ?>" alt="halloween"> |
| 136 |
</div> |
| 137 |
|
| 138 |
<div class="qc-review-text"> |
| 139 |
|
| 140 |
<p style="font-weight:bold; font-size: 17px;color: #5b4e96 !important;"><?php esc_html_e( 'Hello! Thank you for using our ChatBot.', 'chatbot' ) ?></p> |
| 141 |
|
| 142 |
<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> |
| 143 |
|
| 144 |
</div> |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
<?php |
| 148 |
/* Delete transient, only display this notice once. */ |
| 149 |
delete_transient( 'wpbot-admin-notice-oninstallation' ); |
| 150 |
} |
| 151 |
|
| 152 |
public function is_wpbot_page(){ |
| 153 |
|
| 154 |
$status = false; |
| 155 |
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' ) ){ |
| 156 |
$status = true; |
| 157 |
} |
| 158 |
return $status; |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
public function qc_load_rating_style(){ |
| 163 |
wp_enqueue_style( 'qc_rating_stylesheet', plugin_dir_url(__FILE__)."css/style.css"); |
| 164 |
wp_register_script( 'qc_rating_js', plugin_dir_url(__FILE__)."js/rating.js", array('jquery'), '1.02.2' , true); |
| 165 |
$translation_array = array( |
| 166 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 167 |
); |
| 168 |
wp_localize_script( 'qc_rating_js', 'qcld_rating_object', $translation_array ); |
| 169 |
wp_enqueue_script( 'qc_rating_js'); |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
public function qc_rating_notice_message(){ |
| 174 |
|
| 175 |
/*if ( ! is_admin() || |
| 176 |
! current_user_can( 'manage_options' ) ) { |
| 177 |
return; |
| 178 |
}*/ |
| 179 |
|
| 180 |
$scheme = ( wp_parse_url( isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '', PHP_URL_QUERY ) ) ? '&' : '?'; |
| 181 |
|
| 182 |
$url = esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'] . $scheme . 'qc_'.$this->plugin_name.'_rating_dismiss=yes')); |
| 183 |
|
| 184 |
$dismiss_url = wp_nonce_url( $url, 'qc-'.$this->plugin_name.'-rating-nonce' ); |
| 185 |
|
| 186 |
$_later_link = esc_url_raw($_SERVER['REQUEST_URI']) . $scheme . 'qc_'.$this->plugin_name.'_rating_later=yes'; |
| 187 |
|
| 188 |
$later_url = wp_nonce_url( $_later_link, 'qc-'.$this->plugin_name.'-rating-nonce' ); |
| 189 |
|
| 190 |
?> |
| 191 |
<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;"> |
| 192 |
<div class="wpbot-notice-content"> |
| 193 |
<div class="qc-review-thumbnail"> |
| 194 |
<img src="<?php echo esc_url($this->logo_url); ?>" alt=""> |
| 195 |
</div> |
| 196 |
|
| 197 |
<div class="qc-review-text"> |
| 198 |
|
| 199 |
<p style="font-weight:bold; font-size: 17px;color: #5b4e96 !important;"><?php esc_html_e( 'Hello! Thank you for using our ChatBot.', 'chatbot' ) ?></p> |
| 200 |
|
| 201 |
<p style="display:inline-block"> |
| 202 |
<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' ) ?> |
| 203 |
</p> |
| 204 |
|
| 205 |
<ul class="qc-review-ul"> |
| 206 |
|
| 207 |
<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> |
| 208 |
<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> |
| 209 |
<li><a href="<?php echo esc_url($later_url) ?>"><span class="dashicons dashicons-calendar"></span><?php esc_html_e( 'Maybe Later', 'chatbot' ) ?></a></li> |
| 210 |
<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> |
| 211 |
|
| 212 |
</ul> |
| 213 |
</div> |
| 214 |
</div> |
| 215 |
</div> |
| 216 |
<?php |
| 217 |
} |
| 218 |
|
| 219 |
} |
| 220 |
} |
| 221 |
$qc_wpbot_rating = new Wpbot_rating(); |
| 222 |
|
| 223 |
$qc_wpbot_rating->plugin_name = 'wpbot'; |
| 224 |
|
| 225 |
$qc_wpbot_rating->run(); |
| 226 |
|