PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.4
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 / src / Modules / Logger.php

Logger.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.3.4, at vendor/codeinwp/themeisle-sdk/src/Modules/Logger.php

178 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The logger model class for ThemeIsle SDK
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Modules
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
12 namespace ThemeisleSDK\Modules;
13
14 use ThemeisleSDK\Common\Abstract_Module;
15 use ThemeisleSDK\Loader;
16 use ThemeisleSDK\Product;
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Logger module for ThemeIsle SDK.
25 */
26 class Logger extends Abstract_Module {
27 /**
28 * Endpoint where to collect logs.
29 */
30 const TRACKING_ENDPOINT = 'http://log.themeisle.com/wp-json/v1/logs/';
31
32
33 /**
34 * Check if we should load the module for this product.
35 *
36 * @param Product $product Product to load the module for.
37 *
38 * @return bool Should we load ?
39 */
40 public function can_load( $product ) {
41
42 return apply_filters( $product->get_slug() . '_sdk_enable_logger', true );
43 }
44
45 /**
46 * Load module logic.
47 *
48 * @param Product $product Product to load.
49 *
50 * @return Logger Module object.
51 */
52 public function load( $product ) {
53 $this->product = $product;
54 $this->setup_notification();
55 $this->setup_actions();
56
57 return $this;
58 }
59
60 /**
61 * Setup notification on admin.
62 */
63 public function setup_notification() {
64 if ( ! $this->product->is_wordpress_available() ) {
65 return;
66 }
67
68 add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ] );
69
70 }
71
72 /**
73 * Setup tracking actions.
74 */
75 public function setup_actions() {
76 if ( ! $this->is_logger_active() ) {
77 return;
78 }
79 $action_key = $this->product->get_key() . '_log_activity';
80 if ( ! wp_next_scheduled( $action_key ) ) {
81 wp_schedule_single_event( time() + ( rand( 1, 24 ) * 3600 ), $action_key );
82 }
83 add_action( $action_key, array( $this, 'send_log' ) );
84
85 }
86
87 /**
88 * Check if the logger is active.
89 *
90 * @return bool Is logger active?
91 */
92 private function is_logger_active() {
93 if ( ! $this->product->is_wordpress_available() ) {
94 return true;
95 }
96 $pro_slug = $this->product->get_pro_slug();
97
98 if ( ! empty( $pro_slug ) ) {
99 $all_products = Loader::get_products();
100 if ( isset( $all_products[ $pro_slug ] ) ) {
101 return true;
102 }
103 }
104
105 return ( get_option( $this->product->get_key() . '_logger_flag', 'no' ) === 'yes' );
106 }
107
108 /**
109 * Add notification to queue.
110 *
111 * @param array $all_notifications Previous notification.
112 *
113 * @return array All notifications.
114 */
115 public function add_notification( $all_notifications ) {
116
117 $message = apply_filters( $this->product->get_key() . '_logger_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.' );
118
119 $message = str_replace(
120 array( '{product}' ),
121 $this->product->get_friendly_name(),
122 $message
123 );
124 $button_submit = apply_filters( $this->product->get_key() . '_logger_button_submit', 'Sure, I would love to help.' );
125 $button_cancel = apply_filters( $this->product->get_key() . '_logger_button_cancel', 'No, thanks.' );
126
127 $all_notifications[] = [
128 'id' => $this->product->get_key() . '_logger_flag',
129 'message' => $message,
130 'ctas' => [
131 'confirm' => [
132 'link' => '#',
133 'text' => $button_submit,
134 ],
135 'cancel' => [
136 'link' => '#',
137 'text' => $button_cancel,
138 ],
139 ],
140 ];
141
142 return $all_notifications;
143 }
144
145 /**
146 * Send the statistics to the api endpoint.
147 */
148 public function send_log() {
149 $environment = array();
150 $theme = wp_get_theme();
151 $environment['theme'] = array();
152 $environment['theme']['name'] = $theme->get( 'Name' );
153 $environment['theme']['author'] = $theme->get( 'Author' );
154 $environment['plugins'] = get_option( 'active_plugins' );
155 global $wp_version;
156 wp_remote_post(
157 self::TRACKING_ENDPOINT,
158 array(
159 'method' => 'POST',
160 'timeout' => 3,
161 'redirection' => 5,
162 'headers' => array(
163 'X-ThemeIsle-Event' => 'log_site',
164 ),
165 'body' => array(
166 'site' => get_site_url(),
167 'slug' => $this->product->get_slug(),
168 'version' => $this->product->get_version(),
169 'wp_version' => $wp_version,
170 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
171 'environment' => $environment,
172 'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
173 ),
174 )
175 );
176 }
177 }
178