Cron.php
8 years ago
Ecommerce.php
7 years ago
Language.php
10 years ago
Logger.php
8 years ago
MobileDetect.php
8 years ago
Options.php
8 years ago
Plugin.php
10 years ago
Properties.php
10 years ago
Tracking.php
8 years ago
Utils.php
8 years ago
Tracking.php
166 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 TCMP_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('tcmp_weekly_scheduled_events', array($this, 'sendTracking')); |
| 19 | |
| 20 | //add_action('tcmp_tracking_on', array($this, 'enableTracking')); |
| 21 | //add_action('tcmp_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 $tcmp; |
| 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=$tcmp->Utils->query(TCMP_QUERY_POST_TYPES); |
| 93 | $data=array(); |
| 94 | foreach ($post_types as $v) { |
| 95 | $v=$v['id']; |
| 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=$tcmp->Manager->keys(); |
| 103 | foreach($keys as $k) { |
| 104 | $v=$tcmp->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']=TCMP_PLUGIN_SLUG; |
| 112 | $result['iwpm_plugin_version']=TCMP_PLUGIN_VERSION; |
| 113 | $result['iwpm_plugin_data']=$data; |
| 114 | $result['iwpm_plugin_install_date']=$tcmp->Options->getPluginInstallDate(); |
| 115 | $result['iwpm_plugin_update_date']=$tcmp->Options->getPluginUpdateDate(); |
| 116 | |
| 117 | $result['iwpm_license_key']=$tcmp->Options->getLicenseKey(); |
| 118 | $result['iwpm_license_status']=$tcmp->Options->isLicenseSuccess(); |
| 119 | $result['iwpm_tracking_enable']=$tcmp->Options->isTrackingEnable(); |
| 120 | $result['iwpm_logger_enable']=$tcmp->Options->isLoggerEnable(); |
| 121 | $result['iwpm_feedback_email']=$tcmp->Options->getFeedbackEmail(); |
| 122 | |
| 123 | //var_dump($result); |
| 124 | return $result; |
| 125 | } |
| 126 | |
| 127 | //send tracking data info to our server |
| 128 | public function sendTracking($override = FALSE) { |
| 129 | global $tcmp; |
| 130 | |
| 131 | $result=-1; |
| 132 | if(!$override && !$tcmp->Options->isTrackingEnable()) |
| 133 | return $result; |
| 134 | |
| 135 | // Send a maximum of once per week |
| 136 | $last_send=$tcmp->Options->getTrackingLastSend(); |
| 137 | if(!$override && $last_send>strtotime('-1 week')) |
| 138 | return $result; |
| 139 | |
| 140 | //add_filter('https_local_ssl_verify', '__return_false'); |
| 141 | //add_filter('https_ssl_verify', '__return_false'); |
| 142 | //add_filter('block_local_requests', '__return_false'); |
| 143 | |
| 144 | $data=$tcmp->Utils->remotePost('usage', $this->getData()); |
| 145 | if($data) { |
| 146 | $result=intval($data['id']); |
| 147 | $tcmp->Options->setTrackingLastSend(time()); |
| 148 | } |
| 149 | return $result; |
| 150 | } |
| 151 | |
| 152 | public function enableTracking() { |
| 153 | global $tcmp; |
| 154 | |
| 155 | $tcmp->Options->setTrackingEnable(TRUE); |
| 156 | $tcmp->Options->setTrackingNotice(FALSE); |
| 157 | $this->sendTracking(TRUE); |
| 158 | } |
| 159 | public function disableTracking() { |
| 160 | global $tcmp; |
| 161 | |
| 162 | $tcmp->Options->setTrackingEnable(FALSE); |
| 163 | $tcmp->Options->setTrackingNotice(FALSE); |
| 164 | $this->sendTracking(TRUE); |
| 165 | } |
| 166 | } |