buffer
3 years ago
script_loader_tag
2 years ago
traits
3 years ago
Consent_API_Helper.php
3 years ago
Cookie_Consent.php
3 years ago
Cookie_Consent_Interface.php
4 years ago
Cookiebot_Activated.php
3 years ago
Cookiebot_Automatic_Updates.php
3 years ago
Cookiebot_Deactivated.php
4 years ago
Cookiebot_Javascript_Helper.php
3 years ago
Cookiebot_Review.php
2 years ago
Cookiebot_WP.php
2 years ago
Dependency_Container.php
3 years ago
Settings_Page_Tab.php
3 years ago
Settings_Service.php
3 years ago
Settings_Service_Interface.php
3 years ago
Supported_Languages.php
4 years ago
Supported_Regions.php
3 years ago
WP_Rocket_Helper.php
3 years ago
Widgets.php
3 years ago
global-deprecations.php
3 years ago
helper.php
3 years ago
Cookiebot_Review.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | use WP_REST_SERVER; |
| 6 | use cybot\cookiebot\settings\pages\Debug_Page; |
| 7 | |
| 8 | class Cookiebot_Review { |
| 9 | /** |
| 10 | * Handler url. |
| 11 | * |
| 12 | * @var string |
| 13 | */ |
| 14 | protected $api_url = 'https://www.cookiebot.com/wp-json/cmp/v1/survey/'; |
| 15 | |
| 16 | public function register_hooks() { |
| 17 | add_action( 'admin_footer', array( $this, 'cookiebot_admin_script' ) ); |
| 18 | add_filter( 'plugin_action_links_cookiebot/cookiebot.php', array( $this, 'plugin_action_links' ) ); |
| 19 | add_filter( 'network_admin_plugin_action_links', array( $this, 'plugin_action_links' ) ); |
| 20 | add_action( 'wp_ajax_cb_submit_survey', array( $this, 'send_uninstall_survey' ) ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Edit action links |
| 25 | * |
| 26 | * @param array $links action links. |
| 27 | * @return array |
| 28 | */ |
| 29 | public function plugin_action_links( $links ) { |
| 30 | if ( array_key_exists( 'deactivate', $links ) ) { |
| 31 | $links['deactivate'] = str_replace( '<a', '<a class="cb-deactivate-action"', $links['deactivate'] ); |
| 32 | } |
| 33 | |
| 34 | return $links; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Cookiebot Add ajax url |
| 39 | */ |
| 40 | public function cookiebot_admin_script() { |
| 41 | wp_enqueue_script( |
| 42 | 'cookiebot_admin_js', |
| 43 | asset_url( 'js/backend/cookiebot-admin-script.js' ), |
| 44 | null, |
| 45 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 46 | true |
| 47 | ); |
| 48 | |
| 49 | wp_enqueue_style( |
| 50 | 'cookiebot-admin-global-css', |
| 51 | asset_url( 'css/backend/global/cookiebot_admin.css' ), |
| 52 | null, |
| 53 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 54 | ); |
| 55 | |
| 56 | wp_localize_script( |
| 57 | 'cookiebot_admin_js', |
| 58 | 'cb_ajax', |
| 59 | array( |
| 60 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 61 | 'survey_nonce' => wp_create_nonce( 'cookiebot_survey_nonce' ), |
| 62 | ) |
| 63 | ); |
| 64 | |
| 65 | $args = array( |
| 66 | 'cookiebot_logo' => asset_url( 'img/icon.svg' ), |
| 67 | ); |
| 68 | |
| 69 | include_view( 'admin/templates/extra/review-form.php', $args ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Send uninstall reason to server |
| 74 | * |
| 75 | * @return void |
| 76 | */ |
| 77 | public function send_uninstall_survey() { |
| 78 | global $wpdb; |
| 79 | if ( ! check_ajax_referer( 'cookiebot_survey_nonce', 'survey_nonce', false ) ) { |
| 80 | wp_send_json_error( esc_html__( 'Sorry you are not allowed to do this.', 'cookiebot' ), 401 ); |
| 81 | } |
| 82 | if ( ! isset( $_POST['reason_id'] ) ) { |
| 83 | wp_send_json_error( esc_html__( 'Please select one option', 'cookiebot' ), 400 ); |
| 84 | } |
| 85 | $data = array( |
| 86 | 'survey_check' => sanitize_text_field( wp_unslash( $_POST['survey_check'] ) ), |
| 87 | 'reason_slug' => sanitize_text_field( wp_unslash( $_POST['reason_id'] ) ), |
| 88 | 'reason_detail' => ! empty( $_POST['reason_text'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_text'] ) ) : null, |
| 89 | 'comments' => ! empty( $_POST['reason_info'] ) ? sanitize_text_field( wp_unslash( $_POST['reason_info'] ) ) : null, |
| 90 | 'date' => gmdate( 'M d, Y h:i:s A' ), |
| 91 | 'server' => ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : null, |
| 92 | 'php_version' => phpversion(), |
| 93 | 'mysql_version' => $wpdb->db_version(), |
| 94 | 'wp_version' => get_bloginfo( 'version' ), |
| 95 | 'locale' => get_locale(), |
| 96 | 'plugin_version' => Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 97 | 'is_multisite' => is_multisite(), |
| 98 | ); |
| 99 | |
| 100 | if ( ! empty( $_POST['reason_debug'] ) && rest_sanitize_boolean( $_POST['reason_debug'] ) === true ) { |
| 101 | $debug_info = new Debug_Page(); |
| 102 | $data['debug_info'] = wp_json_encode( $debug_info->prepare_debug_data() ); |
| 103 | } |
| 104 | |
| 105 | wp_remote_post( |
| 106 | $this->api_url, |
| 107 | array( |
| 108 | 'headers' => array( |
| 109 | 'Content-Type' => 'application/json; charset=utf-8', |
| 110 | ), |
| 111 | 'method' => 'POST', |
| 112 | 'timeout' => 45, |
| 113 | 'redirection' => 5, |
| 114 | 'httpversion' => '1.0', |
| 115 | 'blocking' => false, |
| 116 | 'body' => wp_json_encode( $data ), |
| 117 | 'cookies' => array(), |
| 118 | ) |
| 119 | ); |
| 120 | |
| 121 | wp_send_json_success( null, 200 ); |
| 122 | } |
| 123 | } |
| 124 |