PluginProbe ʕ •ᴥ•ʔ
PiWeb Product Enquiry or product catalog for WooCommerce / 2.2.34.29
PiWeb Product Enquiry or product catalog for WooCommerce v2.2.34.29
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 5 months ago img 5 months ago js 5 months 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 5 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 5 months ago index.php 5 months ago plugins.php 5 months ago
class-analytics.php
268 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 sprintf( esc_html__( 'Help to Improve %s plugin', 'pisol-enquiry-quotation-woocommerce' ), esc_html( $this->plugin_name ) ),
60 esc_html__( 'Hi, your support can make a big difference!', 'pisol-enquiry-quotation-woocommerce' ),
61 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' )
62 );
63
64 $notice .= '<p style="display: flex; justify-content: space-between; margin-top: 10px;">';
65
66 $notice .= sprintf(
67 '<a href="%s" class="button">%s</a>',
68 esc_url(admin_url('admin-post.php?enable=0&action=' . $this->enable_tracking_action)),
69 esc_html__('I Don\'t Help', 'pisol-enquiry-quotation-woocommerce')
70 );
71 $notice .= sprintf(
72 '<a href="%s" class="button button-primary" style="margin-right:20px; padding-left:30px; padding-right:30px;">%s</a>',
73 esc_url(admin_url('admin-post.php?enable=1&action=' . $this->enable_tracking_action)),
74 esc_html__('I Will Help', 'pisol-enquiry-quotation-woocommerce')
75 );
76
77 $notice .= '</p>';
78 $notice .= '</div>';
79 // Use wp_kses_post to allow safe HTML in the assembled notice
80 echo wp_kses_post($notice);
81
82 }
83
84 public function handle_tracker_action() {
85 if (isset($_GET['enable']) && in_array($_GET['enable'], array('1', '0'))) {
86 $enable = $_GET['enable'] === '1' ? 'enable' : 'disable';
87 update_option($this->enable_tracking, $enable);
88 $redirect_url = isset($_SERVER['HTTP_REFERER']) ? esc_url_raw($_SERVER['HTTP_REFERER']) : admin_url();
89
90 if ($enable === 'enable') {
91 $this->send_activation_data('enable');
92 }
93
94 wp_safe_redirect($redirect_url);
95 exit;
96 }
97 }
98
99 public function send_activation_data($action, $message = '') {
100
101 $data = array(
102 'plugin_slug' => $this->plugin_slug,
103 'version' => $this->version,
104 'site_url' => get_site_url(),
105 'wp_version' => get_bloginfo('version'),
106 'wc_version' => function_exists('WC') ? WC()->version : '',
107 'action' => $action,
108 'message' => $message,
109 );
110
111 // Make the request non-blocking by setting 'blocking' => false
112 wp_remote_post($this->url, array(
113 'body' => wp_json_encode($data),
114 'headers' => array('Content-Type' => 'application/json'),
115 'blocking' => false,
116 ));
117 }
118
119 function enqueue_scripts($hook) {
120 if ($hook !== 'plugins.php') return;
121
122 $js = '
123 jQuery(document).ready(function($) {
124 var id = "deactivate-'.$this->plugin_slug.'";
125
126 jQuery(document).on("click", "#"+id, function(e) {
127
128 var href = $(this).attr("href");
129 var popup = "#pi-deactivation-reason-'.$this->plugin_slug.'";
130 if ($(popup).length) {
131 e.preventDefault();
132 $(popup).show();
133 }
134 });
135
136 jQuery(document).on("click", "#pi-deactivator-close-'.$this->plugin_slug.'", function(e) {
137
138 var popup = "#pi-deactivation-reason-'.$this->plugin_slug.'";
139 if ($(popup).length) {
140 e.preventDefault();
141 $(popup).hide();
142 }
143 });
144
145 jQuery(document).on("change", "#pi-deact-form-'.esc_attr($this->plugin_slug).' input[name=\'reason_radio\']", function () {
146 if (jQuery(this).val() === "Other") {
147 jQuery("#pi-deact-form-'.esc_attr($this->plugin_slug).' textarea").show();
148 } else {
149 jQuery("#pi-deact-form-'.esc_attr($this->plugin_slug).' textarea").hide();
150 }
151 });
152 });
153 ';
154
155 wp_add_inline_script('jquery', $js);
156
157 // Add the deactivation modal CSS as inline style
158 $css = '.pi-deactivation-overlay-' . esc_attr($this->plugin_slug) . ' {
159 display: none;
160 position: fixed;
161 top: 0; left: 0; right: 0; bottom: 0;
162 width: 100%;
163 height: 100%;
164 background: rgba(0,0,0,0.5);
165 z-index: 9999;
166 }
167
168 .pi-deact-close-' . esc_attr($this->plugin_slug) . ' {
169 color: #000;
170 text-decoration: none;
171 font-size: 20px;
172 font-weight: bold;
173 }
174
175 .pi-deactivation-modal-' . esc_attr($this->plugin_slug) . ' {
176 position: fixed;
177 top: 50%;
178 left: 50%;
179 transform: translate(-50%, -50%);
180 background: #fff;
181 padding: 20px;
182 width: 400px;
183 max-width: 90%;
184 max-height: 90%;
185 overflow: auto;
186 box-shadow: 0 2px 10px rgba(0,0,0,0.3);
187 z-index: 10000;
188 }';
189 wp_add_inline_style('wp-admin', $css);
190 }
191
192 public function print_deactivation_modal() {
193 $nonce = wp_create_nonce('pi_deactivate_nonce_' . $this->plugin_slug);
194 ?>
195 <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); ?>">
196 <div class="pi-deactivation-modal-<?php echo esc_attr($this->plugin_slug); ?>">
197 <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>
198 <form id="pi-deact-form-<?php echo esc_attr($this->plugin_slug); ?>" method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
199 <h3>Help us to improve by giving reason for deactivation:</h3>
200 <div style="margin-bottom:10px;">
201 <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>
202 <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>
203 <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>
204 <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>
205 <label style="margin-bottom:10px; display:block;"><input type="radio" name="reason_radio" value="Other"> Other (please specify below)</label>
206 </div>
207 <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>
208 <?php
209 // Hidden fields
210 echo '<input type="hidden" name="action" value="pi_handle_deactivation_' . esc_attr($this->plugin_slug) . '">';
211 echo '<input type="hidden" name="plugin_slug" value="' . esc_attr($this->plugin_slug) . '">';
212 echo '<input type="hidden" name="nonce" value="' . esc_attr($nonce) . '">';
213 ?>
214 <p style="display: flex; justify-content: space-between; margin-top: 10px;">
215 <button type="submit" name="action_type" class="pi-deact-skip button" value="skip">Skip</button>
216 <button type="submit" class="pi-deact-submit button button-primary" name="action_type" value="submit">Deactivate & Submit</button>
217 </p>
218 </form>
219 </div>
220 </div>
221 <?php
222 }
223
224 public function handle_deactivation_form() {
225 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'pi_deactivate_nonce_' . $this->plugin_slug)) {
226 wp_die( esc_html__('Security check failed', 'pisol-enquiry-quotation-woocommerce') );
227 }
228
229 $plugin_slug = sanitize_text_field($_POST['plugin_slug'] ?? '');
230 $message = sanitize_textarea_field($_POST['message'] ?? '');
231 $reason = sanitize_text_field($_POST['reason_radio'] ?? '');
232 // Combine reason and message, prioritizing reason if message is empty
233 if (!empty($reason) && !empty($message)) {
234 $message = $reason . ': ' . $message;
235 } elseif (!empty($reason)) {
236 $message = $reason;
237 }
238
239 $action_type = sanitize_text_field($_POST['action_type'] ?? '');
240
241 if (is_multisite() && is_plugin_active_for_network($this->plugin_path)) {
242 if (is_super_admin()) {
243 deactivate_plugins($this->plugin_path, false, true); // network-wide
244 } else {
245 wp_die( esc_html__('You do not have permission to deactivate a network plugin.', 'pisol-enquiry-quotation-woocommerce') );
246 }
247 } else {
248 deactivate_plugins($this->plugin_path); // normal
249 }
250
251 if($action_type === 'submit'){
252 $this->send_activation_data('disable', wp_strip_all_tags($message));
253 }
254
255
256 // Redirect back to plugins page
257 wp_safe_redirect(admin_url('plugins.php'));
258 exit;
259 }
260
261
262 }
263
264 new Pi_Eqw_Analytics(
265 'WooCommerce Enquiry & Quotation',
266 'enquiry-quotation-for-woocommerce/pisol-enquiry-quotation-woocommerce.php',
267 PISOL_ENQUIRY_QUOTATION_WOOCOMMERCE_VERSION
268 );