PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.0.10
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.0.10
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 3.0.10, at vendor/codeinwp/themeisle-sdk/class-themeisle-sdk-logger.php

228 lines 6.3 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 <b>{product}</b>? 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 $environment = array();
81 $theme = wp_get_theme();
82 $environment['theme'] = array();
83 $environment['theme']['name'] = $theme->get( 'Name' );
84 $environment['theme']['author'] = $theme->get( 'Author' );
85 $environment['plugins'] = get_option( 'active_plugins' );
86
87 wp_remote_post(
88 $this->logging_url, array(
89 'method' => 'POST',
90 'timeout' => 3,
91 'redirection' => 5,
92 'headers' => array(
93 'X-ThemeIsle-Event' => 'log_site',
94 ),
95 'body' => array(
96 'site' => get_site_url(),
97 'slug' => $this->product->get_slug(),
98 'version' => $this->product->get_version(),
99 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
100 'environment' => $environment,
101 'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
102 ),
103 )
104 );
105 }
106
107 /**
108 * Dismiss the notification
109 */
110 function dismiss() {
111 check_ajax_referer( (string) __CLASS__, 'nonce' );
112
113 $flag = intval( $_POST['enable'] ) === 1;
114 update_option( $this->product->logger_option, ( $flag ? 'yes' : 'no' ) );
115
116 if ( true === $flag ) {
117 $this->enable();
118 }
119 }
120
121 /**
122 * Either we should show the notification or not.
123 *
124 * @return bool Valida notification.
125 */
126 function can_notify() {
127 $show = $this->product->is_logger_active();
128 $checked = get_option( $this->product->logger_option, '' );
129 if ( ! $show && $checked == '' ) {
130 return true;
131 }
132
133 return false;
134 }
135
136 /**
137 * Shows the notification
138 */
139 function show_notification() {
140 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
141 }
142
143 /**
144 * Shows the admin notice
145 */
146 function admin_notices() {
147 $id = $this->product->get_key() . '_logger';
148
149 $this->add_media( $this->product->get_key() );
150
151 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>';
152 }
153
154 /**
155 * Generates the HTML
156 *
157 * @param string $key The product key.
158 */
159 function get_html( $key ) {
160 $heading = apply_filters( $this->product->get_key() . '_logger_heading', $this->heading );
161 $heading = str_replace(
162 array( '{product}' ), array(
163 trim( str_replace( 'Lite', '', $this->product->get_name() ) ),
164 ),
165 $heading
166 );
167 $button_submit = apply_filters( $this->product->get_key() . '_logger_button_submit', $this->button_submit );
168 $button_cancel = apply_filters( $this->product->get_key() . '_logger_button_cancel', $this->button_cancel );
169
170 return '<div >'
171 . '<p>' . $heading . '</p>'
172 . '<div class="actions">'
173 . get_submit_button(
174 $button_submit, 'primary ' . $this->product->get_key() . '-ti-logger', $this->product->get_key() . 'ti-logger-yes', false, array(
175 'data-ti-log-enable' => 1,
176 )
177 )
178 . get_submit_button(
179 $button_cancel, 'secondary ' . $this->product->get_key() . '-ti-logger', $this->product->get_key() . 'ti-logger-no', false, array(
180 'data-ti-log-enable' => 0,
181 )
182 )
183 . '</div></div>';
184 }
185
186 /**
187 * Loads the js
188 *
189 * @param string $key The product key.
190 */
191 function add_media( $key ) {
192 ?>
193 <style type="text/css">
194 #<?php echo $key; ?>-logger-notification {
195 padding-bottom: 5px;
196 }
197
198 #<?php echo $key; ?>-logger-notification .button {
199 margin-left: 5px;
200 }
201 </style>
202 <script type="text/javascript" id="<?php echo $key; ?>ti-logger-js">
203 (function ($) {
204 $(document).ready(function () {
205 $('.<?php echo $key; ?>-ti-logger').on('click', function (e) {
206
207 $.ajax({
208 url: ajaxurl,
209 method: "post",
210 data: {
211 'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ ); ?>',
212 'action': '<?php echo $this->product->get_key() . __CLASS__; ?>',
213 'enable': $(this).attr('data-ti-log-enable')
214 },
215 success: function () {
216 $('#<?php echo $key; ?>-logger-notification').hide();
217 }
218 });
219 });
220 });
221 })(jQuery);
222 </script>
223 <?php
224 }
225
226 }
227 endif;
228