PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 1.4
Tracking Code Manager v1.4
trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / class-TCM-tracking.php
tracking-code-manager / includes Last commit date
admin 11 years ago actions.php 11 years ago class-TCM-check.php 11 years ago class-TCM-cron.php 11 years ago class-TCM-form.php 11 years ago class-TCM-language.php 11 years ago class-TCM-logger.php 11 years ago class-TCM-manager.php 11 years ago class-TCM-options.php 11 years ago class-TCM-tracking.php 11 years ago class-TCM-utils.php 11 years ago core.php 11 years ago install.php 11 years ago uninstall.php 11 years ago
class-TCM-tracking.php
189 lines
1 <?php
2
3 // Exit if accessed directly
4 if (!defined('ABSPATH')) exit;
5
6 /**
7 * Usage tracking
8 *
9 * @access public
10 * @since 1.8.2
11 * @return void
12 */
13 class TCM_Tracking {
14
15 public function __construct() {
16 //We send once a week (while tracking is allowed) to check in which can be used
17 //to determine active sites
18 add_action('tcm_weekly_scheduled_events', array($this, 'sendTracking'));
19
20 //add_action('tcm_tracking_on', array($this, 'enableTracking'));
21 //add_action('tcm_tracking_off', array($this, 'disableTracking'));
22 //add_action('admin_notices', array($this, 'admin_notice'));
23 }
24
25 private function getThemeData() {
26 $theme_data = wp_get_theme();
27 $theme = array(
28 'name' => $theme_data->display( 'Name', false, false ),
29 'theme_uri' => $theme_data->display( 'ThemeURI', false, false ),
30 'version' => $theme_data->display( 'Version', false, false ),
31 'author' => $theme_data->display( 'Author', false, false ),
32 'author_uri' => $theme_data->display( 'AuthorURI', false, false ),
33 );
34 $theme_template = $theme_data->get_template();
35 if ( $theme_template !== '' && $theme_data->parent() ) {
36 $theme['template'] = array(
37 'version' => $theme_data->parent()->display( 'Version', false, false ),
38 'name' => $theme_data->parent()->display( 'Name', false, false ),
39 'theme_uri' => $theme_data->parent()->display( 'ThemeURI', false, false ),
40 'author' => $theme_data->parent()->display( 'Author', false, false ),
41 'author_uri' => $theme_data->parent()->display( 'AuthorURI', false, false ),
42 );
43 }
44 else {
45 $theme['template'] = '';
46 }
47 unset( $theme_template );
48 return $theme;
49 }
50 private function getPluginData() {
51 //retrieve plugins (active/inactive) list
52 if(!function_exists('get_plugins')) {
53 include ABSPATH . '/wp-admin/includes/plugin.php';
54 }
55
56 $plugins=array();
57 $active_plugin = get_option( 'active_plugins' );
58 foreach ( $active_plugin as $plugin_path ) {
59 if ( ! function_exists( 'get_plugin_data' ) ) {
60 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
61 }
62
63 $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
64
65 $slug= str_replace( '/' . basename( $plugin_path ), '', $plugin_path );
66 $plugins[ $slug ] = array(
67 'version' => $plugin_info['Version'],
68 'name' => $plugin_info['Name'],
69 'plugin_uri' => $plugin_info['PluginURI'],
70 'author' => $plugin_info['AuthorName'],
71 'author_uri' => $plugin_info['AuthorURI'],
72 );
73 }
74 unset( $active_plugins, $plugin_path );
75 return $plugins;
76 }
77 //obtain tracking data into an associative array
78 public function getData() {
79 global $tcm;
80
81 //retrieve blog info
82 $result['wp_url']=home_url();
83 $result['wp_version']=get_bloginfo('version');
84 $result['wp_language']=get_bloginfo('language');
85 $result['wp_wpurl']=get_bloginfo('wpurl');
86 $result['wp_admin_email']=get_bloginfo('admin_email');
87
88 $result['plugins']=$this->getPluginData();
89 $result['theme']=$this->getThemeData();
90
91 //to obtain for each post type its count
92 $post_types=$tcm->Utils->query(TCM_QUERY_POST_TYPES);
93 $data=array();
94 foreach ($post_types as $v) {
95 $v=$v['name'];
96 $data[$v]=intval(wp_count_posts($v)->publish);
97 }
98 $result['post_types']=$data;
99
100 //plugin configuration without secret-code
101 $data=array();
102 $keys=$tcm->Manager->keys();
103 foreach($keys as $k) {
104 $v=$tcm->Manager->get($k);
105 //to allow us to receive a part of the code and to protect user privacy
106 //we use this data only to know which SaaS services are used
107 //and not to use your data
108 $v['code']=substr($v['code'], 0, 100);
109 $data[]=$v;
110 }
111 $result['iwpm_plugin_name']=TCM_PLUGIN_NAME;
112 $result['iwpm_plugin_version']=TCM_PLUGIN_VERSION;
113 $result['iwpm_plugin_data']=$data;
114
115 $result['iwpm_tracking_enable']=$tcm->Options->isTrackingEnable();
116 $result['iwpm_logger_enable']=$tcm->Options->isLoggerEnable();
117 $result['iwpm_feedback_email']=$tcm->Options->getFeedbackEmail();
118
119 //var_dump($result);
120 return $result;
121 }
122
123 //send tracking data info to our server
124 public function sendTracking($override = FALSE) {
125 global $tcm;
126
127 $result=-1;
128 if(!$override && !$tcm->Options->isTrackingEnable())
129 return $result;
130
131 // Send a maximum of once per week
132 $last_send=$tcm->Options->getTrackingLastSend();
133 if(!$override && $last_send>strtotime('-1 week'))
134 return $result;
135
136 //add_filter('https_local_ssl_verify', '__return_false');
137 //add_filter('https_ssl_verify', '__return_false');
138 //add_filter('block_local_requests', '__return_false');
139
140 $data=$tcm->Utils->remotePost('usage', $this->getData());
141 if($data) {
142 $result=intval($data['id']);
143 $tcm->Options->setTrackingLastSend(time());
144 }
145 return $result;
146 }
147
148 public function enableTracking() {
149 global $tcm;
150
151 $tcm->Options->setTrackingEnable(TRUE);
152 $tcm->Options->setTrackingNotice(FALSE);
153 $this->sendTracking(TRUE);
154 }
155 public function disableTracking() {
156 global $tcm;
157
158 $tcm->Options->setTrackingEnable(FALSE);
159 $tcm->Options->setTrackingNotice(FALSE);
160 $this->sendTracking(TRUE);
161 }
162
163 public function admin_notice() {
164 global $tcm;
165
166 if(!$tcm->Options->isTrackingNotice() || $tcm->Options->isTrackingEnable() || !current_user_can('manage_options'))
167 return;
168
169 if(FALSE && (
170 stristr(network_site_url('/'), 'dev' ) !== false ||
171 stristr(network_site_url('/'), 'localhost') !== false ||
172 stristr(network_site_url('/'), ':8888' ) !== false // This is common with MAMP on OS X
173 )) {
174 $tcm->Options->setTrackingNotice(TRUE);
175 } else {
176 $yes_url=add_query_arg('tcm_action', 'manager_trackingOn');
177 $no_url=add_query_arg('tcm_action', 'manager_trackingOff');
178
179 ?>
180 <div class="updated">
181 <p>
182 <?php $tcm->Lang->P('Allow IntellyWP to track plugin usage?');?>
183 &nbsp;<a href="<?php echo esc_url($yes_url)?>" class="button-primary"><?php $tcm->Lang->P('Oh yes :)')?></a>
184 &nbsp;<a href="<?php echo esc_url($no_url)?>" class="button-secondary"><?php $tcm->Lang->P('Refuse!')?></a>
185 </p>
186 </div>
187 <?php }
188 }
189 }