buffer
1 year ago
script_loader_tag
1 year ago
traits
1 year ago
Account_Service.php
1 year ago
Consent_API_Helper.php
1 year ago
Cookie_Consent.php
1 year ago
Cookie_Consent_Interface.php
1 year ago
Cookiebot_Activated.php
1 year ago
Cookiebot_Admin_Links.php
1 year ago
Cookiebot_Automatic_Updates.php
1 year ago
Cookiebot_Deactivated.php
1 year ago
Cookiebot_Frame.php
1 year ago
Cookiebot_Javascript_Helper.php
1 year ago
Cookiebot_Review.php
1 year ago
Cookiebot_WP.php
1 year ago
Dependency_Container.php
1 year ago
Settings_Page_Tab.php
1 year ago
Settings_Service.php
1 year ago
Settings_Service_Interface.php
1 year ago
Supported_Languages.php
1 year ago
Supported_Regions.php
1 year ago
WP_Rocket_Helper.php
1 year ago
Widgets.php
1 year ago
global-deprecations.php
1 year ago
helper.php
1 year ago
Cookiebot_Review.php
181 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | use WP_REST_SERVER; |
| 6 | use function current_user_can; |
| 7 | use cybot\cookiebot\settings\pages\Debug_Page; |
| 8 | |
| 9 | class Cookiebot_Review { |
| 10 | |
| 11 | /** |
| 12 | * Handler url. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $api_url = 'https://www.cookiebot.com/wp-json/cmp/v1/survey/'; |
| 17 | |
| 18 | public function register_hooks() { |
| 19 | add_action( 'admin_enqueue_scripts', array( $this, 'cookiebot_admin_script' ), 9999 ); |
| 20 | add_filter( 'plugin_action_links_cookiebot/cookiebot.php', array( $this, 'plugin_action_links' ) ); |
| 21 | add_filter( 'network_admin_plugin_action_links', array( $this, 'plugin_action_links' ) ); |
| 22 | add_action( 'wp_ajax_cb_submit_survey', array( $this, 'send_uninstall_survey' ) ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Edit action links |
| 27 | * |
| 28 | * @param array $links action links. |
| 29 | * @return array |
| 30 | */ |
| 31 | public function plugin_action_links( $links ) { |
| 32 | if ( array_key_exists( 'deactivate', $links ) ) { |
| 33 | $links['deactivate'] = str_replace( '<a', '<a class="cb-deactivate-action"', $links['deactivate'] ); |
| 34 | } |
| 35 | |
| 36 | return $links; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Cookiebot Add ajax url |
| 41 | */ |
| 42 | public function cookiebot_admin_script( $hook ) { |
| 43 | wp_enqueue_script( |
| 44 | 'cookiebot_admin_js', |
| 45 | asset_url( 'js/backend/cookiebot-admin-script.js' ), |
| 46 | null, |
| 47 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 48 | true |
| 49 | ); |
| 50 | |
| 51 | wp_enqueue_style( |
| 52 | 'cookiebot-admin-global-css', |
| 53 | asset_url( 'css/backend/global/cookiebot_admin.css' ), |
| 54 | null, |
| 55 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 56 | ); |
| 57 | |
| 58 | wp_localize_script( |
| 59 | 'cookiebot_admin_js', |
| 60 | 'cb_ajax', |
| 61 | array( |
| 62 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 63 | ) |
| 64 | ); |
| 65 | |
| 66 | wp_localize_script( |
| 67 | 'cookiebot_admin_js', |
| 68 | 'cb_survey', |
| 69 | array( |
| 70 | 'survey_nonce' => wp_create_nonce( 'cookiebot_survey_nonce' ), |
| 71 | 'logo' => asset_url( 'img/icons/shield_icon.svg' ), |
| 72 | 'popup_header_title' => __( 'Cookiebot CMP Deactivation', 'cookiebot' ), |
| 73 | 'first_msg' => __( 'We are sad to lose you. Take a moment to help us improve?', 'cookiebot' ), |
| 74 | 'options' => array( |
| 75 | array( |
| 76 | 'text' => __( 'The installation is too complicated', 'cookiebot' ), |
| 77 | 'value' => '1', |
| 78 | ), |
| 79 | array( |
| 80 | 'text' => __( 'I found a plugin that better serves my needs', 'cookiebot' ), |
| 81 | 'value' => '2', |
| 82 | ), |
| 83 | array( |
| 84 | 'text' => __( 'Missing features / did not meet my expectations', 'cookiebot' ), |
| 85 | 'value' => '3', |
| 86 | ), |
| 87 | array( |
| 88 | 'text' => __( 'I need more customization options', 'cookiebot' ), |
| 89 | 'value' => '4', |
| 90 | ), |
| 91 | array( |
| 92 | 'text' => __( 'The premium plan is too expensive', 'cookiebot' ), |
| 93 | 'value' => '5', |
| 94 | ), |
| 95 | array( |
| 96 | 'text' => __( 'I’m only deactivating the plugin temporarily', 'cookiebot' ), |
| 97 | 'value' => '6', |
| 98 | ), |
| 99 | array( |
| 100 | 'text' => __( 'Other', 'cookiebot' ), |
| 101 | 'value' => '7', |
| 102 | 'extra' => __( 'Please specify here', 'cookiebot' ), |
| 103 | ), |
| 104 | ), |
| 105 | 'consent' => array( |
| 106 | 'optional' => __( '(Optional)', 'cookiebot' ), |
| 107 | 'first' => __( |
| 108 | ' By checking this box, you agree to submit troubleshooting information and allow us to contact you regarding the problem if necessary.', |
| 109 | 'cookiebot' |
| 110 | ), |
| 111 | 'second' => __( |
| 112 | 'The information will be kept for no longer than 90 days. You may revoke this consent at any time, e.g. by sending an email to ', |
| 113 | 'cookiebot' |
| 114 | ), |
| 115 | ), |
| 116 | 'alert' => __( 'Please select one option', 'cookiebot' ), |
| 117 | 'actions' => array( |
| 118 | 'skip' => __( 'Skip and Deactivate', 'cookiebot' ), |
| 119 | 'submit' => __( 'Submit and Deactivate', 'cookiebot' ), |
| 120 | ), |
| 121 | ) |
| 122 | ); |
| 123 | |
| 124 | if ( 'plugins.php' === $hook ) { |
| 125 | include_view( 'admin/common/templates/extra/review-form.php' ); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Send uninstall reason to server |
| 131 | * |
| 132 | * @return void |
| 133 | */ |
| 134 | public function send_uninstall_survey() { |
| 135 | global $wpdb; |
| 136 | if ( ! check_ajax_referer( 'cookiebot_survey_nonce', 'survey_nonce', false ) || ! current_user_can( 'deactivate_plugins' ) ) { |
| 137 | wp_send_json_error( esc_html__( 'Sorry you are not allowed to do this.', 'cookiebot' ), 401 ); |
| 138 | } |
| 139 | if ( ! isset( $_POST['reason_id'] ) ) { |
| 140 | wp_send_json_error( esc_html__( 'Please select one option', 'cookiebot' ), 400 ); |
| 141 | } |
| 142 | $data = array( |
| 143 | 'survey_check' => sanitize_text_field( wp_unslash( $_POST['survey_check'] ) ), |
| 144 | 'reason_slug' => sanitize_text_field( wp_unslash( $_POST['reason_id'] ) ), |
| 145 | 'reason_detail' => ! empty( $_POST['reason_text'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_text'] ) ) : null, |
| 146 | 'comments' => ! empty( $_POST['reason_info'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_info'] ) ) : null, |
| 147 | 'date' => gmdate( 'M d, Y h:i:s A' ), |
| 148 | 'server' => ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : null, |
| 149 | 'php_version' => phpversion(), |
| 150 | 'mysql_version' => $wpdb->db_version(), |
| 151 | 'wp_version' => get_bloginfo( 'version' ), |
| 152 | 'locale' => get_locale(), |
| 153 | 'plugin_version' => Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 154 | 'is_multisite' => is_multisite(), |
| 155 | ); |
| 156 | |
| 157 | if ( ! empty( $_POST['reason_debug'] ) && rest_sanitize_boolean( $_POST['reason_debug'] ) === true ) { |
| 158 | $debug_info = new Debug_Page(); |
| 159 | $data['debug_info'] = wp_json_encode( $debug_info->prepare_debug_data() ); |
| 160 | } |
| 161 | |
| 162 | wp_remote_post( |
| 163 | $this->api_url, |
| 164 | array( |
| 165 | 'headers' => array( |
| 166 | 'Content-Type' => 'application/json; charset=utf-8', |
| 167 | ), |
| 168 | 'method' => 'POST', |
| 169 | 'timeout' => 45, |
| 170 | 'redirection' => 5, |
| 171 | 'httpversion' => '1.0', |
| 172 | 'blocking' => false, |
| 173 | 'body' => wp_json_encode( $data ), |
| 174 | 'cookies' => array(), |
| 175 | ) |
| 176 | ); |
| 177 | |
| 178 | wp_send_json_success( null, 200 ); |
| 179 | } |
| 180 | } |
| 181 |