PluginProbe ʕ •ᴥ•ʔ
PiWeb Product Enquiry or product catalog for WooCommerce / trunk
PiWeb Product Enquiry or product catalog for WooCommerce vtrunk
2.2.34.43 2.2.34.42 2.2.34.41 2.2.34.40 2.2.34.39 trunk 2.2.22 2.2.26 2.2.33.16 2.2.33.17 2.2.33.19 2.2.33.20 2.2.33.21 2.2.33.22 2.2.33.23 2.2.33.24 2.2.33.26 2.2.33.27 2.2.33.29 2.2.33.30 2.2.33.31 2.2.33.32 2.2.33.33 2.2.33.34 2.2.33.36 2.2.33.37 2.2.33.39 2.2.33.40 2.2.33.41 2.2.33.42 2.2.33.43 2.2.33.44 2.2.33.46 2.2.33.47 2.2.33.49 2.2.34.0 2.2.34.1 2.2.34.10 2.2.34.11 2.2.34.12 2.2.34.13 2.2.34.14 2.2.34.16 2.2.34.17 2.2.34.19 2.2.34.2 2.2.34.20 2.2.34.21 2.2.34.22 2.2.34.23 2.2.34.24 2.2.34.26 2.2.34.27 2.2.34.29 2.2.34.3 2.2.34.30 2.2.34.31 2.2.34.32 2.2.34.33 2.2.34.34 2.2.34.36 2.2.34.37 2.2.34.4 2.2.34.6 2.2.34.7 2.2.34.9
enquiry-quotation-for-woocommerce / admin / class-analytics.php
enquiry-quotation-for-woocommerce / admin Last commit date
css 11 months ago img 9 months ago js 1 year ago partials 5 months ago class-analytics.php 5 months ago class-eqw-advance.php 5 months ago class-eqw-cart.php 5 months ago class-eqw-email.php 5 months ago class-eqw-enquiry.php 5 months ago class-eqw-form-control.php 5 months ago class-eqw-menu.php 4 months ago class-eqw-option.php 5 months ago class-eqw-product-options.php 5 months ago class-pisol-enquiry-quotation-woocommerce-admin.php 5 months ago class-telegram-options.php 9 months ago index.php 7 years ago plugins.php 5 months ago
class-analytics.php
269 lines
1 <?php
2 /**
3 * v1.0.2
4 */
5
6
7 if ( ! defined( 'ABSPATH' ) ) exit;
8
9 class Pi_Eqw_Analytics{
10
11 private $plugin_slug;
12 private $plugin_path;
13 private $version;
14 private $url;
15 private $plugin_name;
16 private $enable_tracking;
17 private $enable_tracking_action;
18 public function __construct($plugin_name, $plugin_path, $version) {
19 $this->plugin_name = $plugin_name;
20 $this->plugin_path = $plugin_path;
21
22 $parts = explode('/', $this->plugin_path);
23
24 $this->plugin_slug = $parts[0];
25
26 $this->enable_tracking = 'pisol_'.$this->plugin_slug;
27 $this->enable_tracking_action = 'pisol_'.$this->plugin_slug.'_action';
28
29
30 $this->version = $version;
31
32 $this->url = 'https://www.piwebsolution.com/plugin-tracker/';
33
34 add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
35 add_action( 'admin_footer-plugins.php', [ $this, 'print_deactivation_modal' ] );
36 add_action('admin_post_pi_handle_deactivation_' . $this->plugin_slug, array($this, 'handle_deactivation_form'));
37
38 add_action('admin_notices', array($this, 'show_tracker_notice'));
39
40 add_action('admin_post_' . $this->enable_tracking_action, array($this, 'handle_tracker_action'));
41
42 add_filter('safe_style_css', array($this, 'allow_display_style'));
43
44 }
45
46 function allow_display_style($styles) {
47 $styles[] = 'display';
48 return $styles;
49 }
50
51 public function show_tracker_notice() {
52 //delete_option($this->enable_tracking);
53 if (!empty(get_option($this->enable_tracking, ''))) {
54 return;
55 }
56
57 $notice = sprintf(
58 '<div class="notice notice-error is-dismissible"><h4>%s</h4><p>%s</p><p>%s</p>',
59 // translators: %s is the plugin name
60 sprintf( esc_html__( 'Help to Improve %s plugin', 'pisol-enquiry-quotation-woocommerce' ), esc_html( $this->plugin_name ) ),
61 esc_html__( 'Hi, your support can make a big difference!', 'pisol-enquiry-quotation-woocommerce' ),
62 esc_html__( 'We collect only technical data — including the plugin version, WordPress version, WooCommerce version, and site url — solely to improve compatibility and enhance plugin features.', 'pisol-enquiry-quotation-woocommerce' )
63 );
64
65 $notice .= '<p style="display: flex; justify-content: space-between; margin-top: 10px;">';
66
67 $notice .= sprintf(
68 '<a href="%s" class="button">%s</a>',
69 esc_url(admin_url('admin-post.php?enable=0&action=' . $this->enable_tracking_action)),
70 esc_html__('I Don\'t Help', 'pisol-enquiry-quotation-woocommerce')
71 );
72 $notice .= sprintf(
73 '<a href="%s" class="button button-primary" style="margin-right:20px; padding-left:30px; padding-right:30px;">%s</a>',
74 esc_url(admin_url('admin-post.php?enable=1&action=' . $this->enable_tracking_action)),
75 esc_html__('I Will Help', 'pisol-enquiry-quotation-woocommerce')
76 );
77
78 $notice .= '</p>';
79 $notice .= '</div>';
80 // Use wp_kses_post to allow safe HTML in the assembled notice
81 echo wp_kses_post($notice);
82
83 }
84
85 public function handle_tracker_action() {
86 if (isset($_GET['enable']) && in_array($_GET['enable'], array('1', '0'))) {
87 $enable = $_GET['enable'] === '1' ? 'enable' : 'disable';
88 update_option($this->enable_tracking, $enable);
89 $redirect_url = isset($_SERVER['HTTP_REFERER']) ? esc_url_raw($_SERVER['HTTP_REFERER']) : admin_url();
90
91 if ($enable === 'enable') {
92 $this->send_activation_data('enable');
93 }
94
95 wp_safe_redirect($redirect_url);
96 exit;
97 }
98 }
99
100 public function send_activation_data($action, $message = '') {
101
102 $data = array(
103 'plugin_slug' => $this->plugin_slug,
104 'version' => $this->version,
105 'site_url' => get_site_url(),
106 'wp_version' => get_bloginfo('version'),
107 'wc_version' => function_exists('WC') ? WC()->version : '',
108 'action' => $action,
109 'message' => $message,
110 );
111
112 // Make the request non-blocking by setting 'blocking' => false
113 wp_remote_post($this->url, array(
114 'body' => wp_json_encode($data),
115 'headers' => array('Content-Type' => 'application/json'),
116 'blocking' => false,
117 ));
118 }
119
120 function enqueue_scripts($hook) {
121 if ($hook !== 'plugins.php') return;
122
123 $js = '
124 jQuery(document).ready(function($) {
125 var id = "deactivate-'.$this->plugin_slug.'";
126
127 jQuery(document).on("click", "#"+id, function(e) {
128
129 var href = $(this).attr("href");
130 var popup = "#pi-deactivation-reason-'.$this->plugin_slug.'";
131 if ($(popup).length) {
132 e.preventDefault();
133 $(popup).show();
134 }
135 });
136
137 jQuery(document).on("click", "#pi-deactivator-close-'.$this->plugin_slug.'", function(e) {
138
139 var popup = "#pi-deactivation-reason-'.$this->plugin_slug.'";
140 if ($(popup).length) {
141 e.preventDefault();
142 $(popup).hide();
143 }
144 });
145
146 jQuery(document).on("change", "#pi-deact-form-'.esc_attr($this->plugin_slug).' input[name=\'reason_radio\']", function () {
147 if (jQuery(this).val() === "Other") {
148 jQuery("#pi-deact-form-'.esc_attr($this->plugin_slug).' textarea").show();
149 } else {
150 jQuery("#pi-deact-form-'.esc_attr($this->plugin_slug).' textarea").hide();
151 }
152 });
153 });
154 ';
155
156 wp_add_inline_script('jquery', $js);
157
158 // Add the deactivation modal CSS as inline style
159 $css = '.pi-deactivation-overlay-' . esc_attr($this->plugin_slug) . ' {
160 display: none;
161 position: fixed;
162 top: 0; left: 0; right: 0; bottom: 0;
163 width: 100%;
164 height: 100%;
165 background: rgba(0,0,0,0.5);
166 z-index: 9999;
167 }
168
169 .pi-deact-close-' . esc_attr($this->plugin_slug) . ' {
170 color: #000;
171 text-decoration: none;
172 font-size: 20px;
173 font-weight: bold;
174 }
175
176 .pi-deactivation-modal-' . esc_attr($this->plugin_slug) . ' {
177 position: fixed;
178 top: 50%;
179 left: 50%;
180 transform: translate(-50%, -50%);
181 background: #fff;
182 padding: 20px;
183 width: 400px;
184 max-width: 90%;
185 max-height: 90%;
186 overflow: auto;
187 box-shadow: 0 2px 10px rgba(0,0,0,0.3);
188 z-index: 10000;
189 }';
190 wp_add_inline_style('wp-admin', $css);
191 }
192
193 public function print_deactivation_modal() {
194 $nonce = wp_create_nonce('pi_deactivate_nonce_' . $this->plugin_slug);
195 ?>
196 <div id="pi-deactivation-reason-<?php echo esc_attr($this->plugin_slug); ?>" style="display:none;" class="pi-deactivation-overlay-<?php echo esc_attr($this->plugin_slug); ?>">
197 <div class="pi-deactivation-modal-<?php echo esc_attr($this->plugin_slug); ?>">
198 <a href="javascript:void(0);" id="pi-deactivator-close-<?php echo esc_attr($this->plugin_slug); ?>" class="pi-deact-close-<?php echo esc_attr($this->plugin_slug); ?>" style="position: absolute; top: 10px; right: 10px; z-index: 10001;">&times;</a>
199 <form id="pi-deact-form-<?php echo esc_attr($this->plugin_slug); ?>" method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
200 <h3>Help us to improve by giving reason for deactivation:</h3>
201 <div style="margin-bottom:10px;">
202 <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="Was looking for something else"> Was looking for something else</label>
203 <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="I found a better plugin"> I found a better plugin</label>
204 <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="The plugin broke my site"> The plugin broke my site</label>
205 <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="The plugin is not working as expected"> The plugin is not working as expected</label>
206 <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="Other"> Other (please specify below)</label>
207 </div>
208 <textarea id="pi-deact-reason-<?php echo esc_attr($this->plugin_slug); ?>" name="message" style="width:100%; display:none;" rows="4" placeholder="Let us know the reason for deactivation"></textarea>
209 <?php
210 // Hidden fields
211 echo '<input type="hidden" name="action" value="pi_handle_deactivation_' . esc_attr($this->plugin_slug) . '">';
212 echo '<input type="hidden" name="plugin_slug" value="' . esc_attr($this->plugin_slug) . '">';
213 echo '<input type="hidden" name="nonce" value="' . esc_attr($nonce) . '">';
214 ?>
215 <p style="display: flex; justify-content: space-between; margin-top: 10px;">
216 <button type="submit" name="action_type" class="pi-deact-skip button" value="skip">Skip</button>
217 <button type="submit" class="pi-deact-submit button button-primary" name="action_type" value="submit">Deactivate & Submit</button>
218 </p>
219 </form>
220 </div>
221 </div>
222 <?php
223 }
224
225 public function handle_deactivation_form() {
226 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'pi_deactivate_nonce_' . $this->plugin_slug)) {
227 wp_die( esc_html__('Security check failed', 'pisol-enquiry-quotation-woocommerce') );
228 }
229
230 $plugin_slug = sanitize_text_field($_POST['plugin_slug'] ?? '');
231 $message = sanitize_textarea_field($_POST['message'] ?? '');
232 $reason = sanitize_text_field($_POST['reason_radio'] ?? '');
233 // Combine reason and message, prioritizing reason if message is empty
234 if (!empty($reason) && !empty($message)) {
235 $message = $reason . ': ' . $message;
236 } elseif (!empty($reason)) {
237 $message = $reason;
238 }
239
240 $action_type = sanitize_text_field($_POST['action_type'] ?? '');
241
242 if (is_multisite() && is_plugin_active_for_network($this->plugin_path)) {
243 if (is_super_admin()) {
244 deactivate_plugins($this->plugin_path, false, true); // network-wide
245 } else {
246 wp_die( esc_html__('You do not have permission to deactivate a network plugin.', 'pisol-enquiry-quotation-woocommerce') );
247 }
248 } else {
249 deactivate_plugins($this->plugin_path); // normal
250 }
251
252 if($action_type === 'submit'){
253 $this->send_activation_data('disable', wp_strip_all_tags($message));
254 }
255
256
257 // Redirect back to plugins page
258 wp_safe_redirect(admin_url('plugins.php'));
259 exit;
260 }
261
262
263 }
264
265 new Pi_Eqw_Analytics(
266 'WooCommerce Enquiry & Quotation',
267 'enquiry-quotation-for-woocommerce/pisol-enquiry-quotation-woocommerce.php',
268 PISOL_ENQUIRY_QUOTATION_WOOCOMMERCE_VERSION
269 );