PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.1.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.1.9
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / codeinwp / themeisle-sdk / class-themeisle-sdk-logger.php

class-themeisle-sdk-logger.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.1.9, at vendor/codeinwp/themeisle-sdk/class-themeisle-sdk-logger.php

212 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The main loader class for ThemeIsle SDK
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Logger
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11 if ( ! class_exists( 'ThemeIsle_SDK_Logger' ) ) :
12 /**
13 * Class ThemeIsle_SDK_Logger
14 *
15 * Send the statistics to the Themeisle Endpoint
16 */
17 /**
18 * Class ThemeIsle_SDK_Logger
19 */
20 class ThemeIsle_SDK_Logger {
21
22 /**
23 * @var string $logging_url Url where to send the logs
24 */
25 private $logging_url = 'http://log.themeisle.com/wp-json/v1/logs/';
26
27 /**
28 * @var ThemeIsle_SDK_Product $product Themeisle Product.
29 */
30 private $product;
31
32 /**
33 * @var string $product_cron Cron name handler
34 */
35 private $product_cron;
36
37 /**
38 * @var string $heading The heading of the modal
39 */
40 private $heading = 'Do you enjoy {product}? Become a contributor by opting in to our anonymous data tracking. We guarantee no sensitive data is collected.';
41
42 /**
43 * @var string $button_submit The text of the submit button
44 */
45 private $button_submit = 'Sure, I would love to help.';
46
47 /**
48 * @var string $button_cancel The text of the cancel button
49 */
50 private $button_cancel = 'No, thanks.';
51
52 /**
53 * ThemeIsle_SDK_Logger constructor.
54 *
55 * @param ThemeIsle_SDK_Product $product_object Product Object.
56 */
57 public function __construct( $product_object ) {
58 if ( $product_object instanceof ThemeIsle_SDK_Product ) {
59 $this->product = $product_object;
60 $this->product_cron = $product_object->get_key() . '_log_activity';
61 }
62 add_action( 'wp_ajax_' . $this->product->get_key() . __CLASS__, array( $this, 'dismiss' ) );
63 }
64
65
66 /**
67 * Start the cron to send the log. It will randomize the interval in order to not send all the logs at the same time.
68 */
69 public function enable() {
70 if ( ! wp_next_scheduled( $this->product_cron ) ) {
71 wp_schedule_single_event( time() + ( rand( 15, 24 ) * 3600 ), $this->product_cron );
72 }
73 add_action( $this->product_cron, array( $this, 'send_log' ) );
74 }
75
76 /**
77 * Send the statistics to the api endpoint
78 */
79 public function send_log() {
80 wp_remote_post(
81 $this->logging_url, array(
82 'method' => 'POST',
83 'timeout' => 3,
84 'redirection' => 5,
85 'headers' => array(
86 'X-ThemeIsle-Event' => 'log_site',
87 ),
88 'body' => array(
89 'site' => get_site_url(),
90 'slug' => $this->product->get_slug(),
91 'version' => $this->product->get_version(),
92 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
93 ),
94 )
95 );
96 }
97
98 /**
99 * Dismiss the notification
100 */
101 function dismiss() {
102 check_ajax_referer( (string) __CLASS__, 'nonce' );
103
104 $flag = intval( $_POST['enable'] ) === 1;
105 update_option( $this->product->logger_option, ( $flag ? 'yes' : 'no' ) );
106
107 if ( true === $flag ) {
108 $this->enable();
109 }
110 }
111
112 /**
113 * Shows the notification
114 */
115 function show_notification() {
116 $show = $this->product->is_logger_active();
117 $checked = get_option( $this->product->logger_option, '' );
118 if ( ! $show && $checked == '' ) {
119 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
120
121 return true;
122 }
123
124 return false;
125 }
126
127 /**
128 * Shows the admin notice
129 */
130 function admin_notices() {
131 $id = $this->product->get_key() . '_logger';
132
133 $this->add_media( $this->product->get_key() );
134
135 echo '<div class="notice notice-success is-dismissible " id="' . $this->product->get_key() . '-logger-notification" ><div id="' . $id . '" class="themeisle-logger-box">' . $this->get_html( $this->product->get_key() ) . '</div></div>';
136 }
137
138 /**
139 * Generates the HTML
140 *
141 * @param string $key The product key.
142 */
143 function get_html( $key ) {
144 $heading = apply_filters( $this->product->get_key() . '_logger_heading', $this->heading );
145 $heading = str_replace(
146 array( '{product}' ), array(
147 trim( str_replace( 'Lite', '', $this->product->get_name() ) ),
148 ),
149 $heading
150 );
151 $button_submit = apply_filters( $this->product->get_key() . '_logger_button_submit', $this->button_submit );
152 $button_cancel = apply_filters( $this->product->get_key() . '_logger_button_cancel', $this->button_cancel );
153
154 return '<div >'
155 . '<p>' . $heading . '</p>'
156 . '<div class="actions">'
157 . get_submit_button(
158 __( $button_submit ), 'primary ' . $this->product->get_key() . '-ti-logger', $this->product->get_key() . 'ti-logger-yes', false, array(
159 'data-ti-log-enable' => 1,
160 )
161 )
162 . get_submit_button(
163 __( $button_cancel ), 'secondary ' . $this->product->get_key() . '-ti-logger', $this->product->get_key() . 'ti-logger-no', false, array(
164 'data-ti-log-enable' => 0,
165 )
166 )
167 . '</div></div>';
168 }
169
170 /**
171 * Loads the js
172 *
173 * @param string $key The product key.
174 */
175 function add_media( $key ) {
176 ?>
177 <style type="text/css">
178 #<?php echo $key; ?>-logger-notification {
179 padding-bottom: 5px;
180 }
181
182 #<?php echo $key; ?>-logger-notification .button {
183 margin-left: 5px;
184 }
185 </style>
186 <script type="text/javascript" id="<?php echo $key; ?>ti-logger-js">
187 (function ($) {
188 $(document).ready(function () {
189 $('.<?php echo $key; ?>-ti-logger').on('click', function (e) {
190
191 $.ajax({
192 url: ajaxurl,
193 method: "post",
194 data: {
195 'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ ); ?>',
196 'action': '<?php echo $this->product->get_key() . __CLASS__; ?>',
197 'enable': $(this).attr('data-ti-log-enable')
198 },
199 success: function () {
200 $('#<?php echo $key; ?>-logger-notification').hide();
201 }
202 });
203 });
204 });
205 })(jQuery);
206 </script>
207 <?php
208 }
209
210 }
211 endif;
212