| @@ -1,171 +1,166 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -// Exit if accessed directly | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | - exit; | |
| 6 | -} | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * Usage tracking | |
| 10 | - * | |
| 11 | - * @access public | |
| 12 | - * @since 1.8.2 | |
| 13 | - * @return void | |
| 14 | - */ | |
| 15 | -class TCMP_Tracking { | |
| 16 | - | |
| 17 | - public function __construct() { | |
| 18 | - //We send once a week (while tracking is allowed) to check in which can be used | |
| 19 | - //to determine active sites | |
| 20 | - add_action( 'tcmp_weekly_scheduled_events', array( $this, 'sendTracking' ) ); | |
| 21 | - | |
| 22 | - //add_action('tcmp_tracking_on', array($this, 'enableTracking')); | |
| 23 | - //add_action('tcmp_tracking_off', array($this, 'disableTracking')); | |
| 24 | - //add_action('admin_notices', array($this, 'admin_notice')); | |
| 25 | - } | |
| 26 | - | |
| 27 | - private function getThemeData() { | |
| 28 | - $theme_data = wp_get_theme(); | |
| 29 | - $theme = array( | |
| 30 | - 'name' => $theme_data->display( 'Name', false, false ), | |
| 31 | - 'theme_uri' => $theme_data->display( 'ThemeURI', false, false ), | |
| 32 | - 'version' => $theme_data->display( 'Version', false, false ), | |
| 33 | - 'author' => $theme_data->display( 'Author', false, false ), | |
| 34 | - 'author_uri' => $theme_data->display( 'AuthorURI', false, false ), | |
| 35 | - ); | |
| 36 | - $theme_template = $theme_data->get_template(); | |
| 37 | - if ( '' != $theme_template && $theme_data->parent() ) { | |
| 38 | - $theme['template'] = array( | |
| 39 | - 'version' => $theme_data->parent()->display( 'Version', false, false ), | |
| 40 | - 'name' => $theme_data->parent()->display( 'Name', false, false ), | |
| 41 | - 'theme_uri' => $theme_data->parent()->display( 'ThemeURI', false, false ), | |
| 42 | - 'author' => $theme_data->parent()->display( 'Author', false, false ), | |
| 43 | - 'author_uri' => $theme_data->parent()->display( 'AuthorURI', false, false ), | |
| 44 | - ); | |
| 45 | - } else { | |
| 46 | - $theme['template'] = ''; | |
| 47 | - } | |
| 48 | - unset( $theme_template ); | |
| 49 | - return $theme; | |
| 50 | - } | |
| 51 | - private function getPluginData() { | |
| 52 | - //retrieve plugins (active/inactive) list | |
| 53 | - if ( ! function_exists( 'get_plugins' ) ) { | |
| 54 | - include ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 55 | - } | |
| 56 | - | |
| 57 | - $plugins = array(); | |
| 58 | - $active_plugin = get_option( 'active_plugins' ); | |
| 59 | - foreach ( $active_plugin as $plugin_path ) { | |
| 60 | - if ( ! function_exists( 'get_plugin_data' ) ) { | |
| 61 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path ); | |
| 65 | - | |
| 66 | - $slug = str_replace( '/' . basename( $plugin_path ), '', $plugin_path ); | |
| 67 | - $plugins[ $slug ] = array( | |
| 68 | - 'version' => $plugin_info['Version'], | |
| 69 | - 'name' => $plugin_info['Name'], | |
| 70 | - 'plugin_uri' => $plugin_info['PluginURI'], | |
| 71 | - 'author' => $plugin_info['AuthorName'], | |
| 72 | - 'author_uri' => $plugin_info['AuthorURI'], | |
| 73 | - ); | |
| 74 | - } | |
| 75 | - unset( $active_plugins, $plugin_path ); | |
| 76 | - return $plugins; | |
| 77 | - } | |
| 78 | - //obtain tracking data into an associative array | |
| 79 | - public function getData() { | |
| 80 | - global $tcmp; | |
| 81 | - | |
| 82 | - //retrieve blog info | |
| 83 | - $result['wp_url'] = home_url(); | |
| 84 | - $result['wp_version'] = get_bloginfo( 'version' ); | |
| 85 | - $result['wp_language'] = get_bloginfo( 'language' ); | |
| 86 | - $result['wp_wpurl'] = get_bloginfo( 'wpurl' ); | |
| 87 | - // The administrator email address is intentionally NOT transmitted: it is | |
| 88 | - // personal data that is not needed for the usage statistics this payload | |
| 89 | - // collects. (See F-08 — data minimisation.) | |
| 90 | - | |
| 91 | - $result['plugins'] = $this->getPluginData(); | |
| 92 | - $result['theme'] = $this->getThemeData(); | |
| 93 | - | |
| 94 | - //to obtain for each post type its count | |
| 95 | - $post_types = $tcmp->utils->query( TCMP_QUERY_POST_TYPES ); | |
| 96 | - $data = array(); | |
| 97 | - foreach ( $post_types as $v ) { | |
| 98 | - $v = $v['id']; | |
| 99 | - $data[ $v ] = intval( wp_count_posts( $v )->publish ); | |
| 100 | - } | |
| 101 | - $result['post_types'] = $data; | |
| 102 | - | |
| 103 | - //plugin configuration without secret-code | |
| 104 | - $data = array(); | |
| 105 | - $keys = $tcmp->manager->keys(); | |
| 106 | - foreach ( $keys as $k ) { | |
| 107 | - $v = $tcmp->manager->get( $k ); | |
| 108 | - //to allow us to receive a part of the code and to protect user privacy | |
| 109 | - //we use this data only to know which SaaS services are used | |
| 110 | - //and not to use your data | |
| 111 | - $v['code'] = substr( $v['code'], 0, 100 ); | |
| 112 | - $data[] = $v; | |
| 113 | - } | |
| 114 | - $result['iwpm_plugin_name'] = TCMP_PLUGIN_SLUG; | |
| 115 | - $result['iwpm_plugin_version'] = TCMP_PLUGIN_VERSION; | |
| 116 | - $result['iwpm_plugin_data'] = $data; | |
| 117 | - $result['iwpm_plugin_install_date'] = $tcmp->options->getPluginInstallDate(); | |
| 118 | - $result['iwpm_plugin_update_date'] = $tcmp->options->getPluginUpdateDate(); | |
| 119 | - | |
| 120 | - $result['iwpm_license_key'] = $tcmp->options->getLicenseKey(); | |
| 121 | - $result['iwpm_license_status'] = $tcmp->options->isLicenseSuccess(); | |
| 122 | - $result['iwpm_tracking_enable'] = $tcmp->options->isTrackingEnable(); | |
| 123 | - $result['iwpm_logger_enable'] = $tcmp->options->isLoggerEnable(); | |
| 124 | - $result['iwpm_feedback_email'] = $tcmp->options->getFeedbackEmail(); | |
| 125 | - | |
| 126 | - //var_dump($result); | |
| 127 | - return $result; | |
| 128 | - } | |
| 129 | - | |
| 130 | - //send tracking data info to our server | |
| 131 | - public function sendTracking( $override = false ) { | |
| 132 | - global $tcmp; | |
| 133 | - | |
| 134 | - $result = -1; | |
| 135 | - if ( ! $override && ! $tcmp->options->isTrackingEnable() ) { | |
| 136 | - return $result; | |
| 137 | - } | |
| 138 | - | |
| 139 | - // Send a maximum of once per week | |
| 140 | - $last_send = $tcmp->options->getTrackingLastSend(); | |
| 141 | - if ( ! $override && $last_send > strtotime( '-1 week' ) ) { | |
| 142 | - return $result; | |
| 143 | - } | |
| 144 | - | |
| 145 | - //add_filter('https_local_ssl_verify', '__return_false'); | |
| 146 | - //add_filter('https_ssl_verify', '__return_false'); | |
| 147 | - //add_filter('block_local_requests', '__return_false'); | |
| 148 | - | |
| 149 | - $data = $tcmp->utils->remotePost( 'usage', $this->getData() ); | |
| 150 | - if ( $data ) { | |
| 151 | - $result = intval( $data['id'] ); | |
| 152 | - $tcmp->options->setTrackingLastSend( time() ); | |
| 153 | - } | |
| 154 | - return $result; | |
| 155 | - } | |
| 156 | - | |
| 157 | - public function enableTracking() { | |
| 158 | - global $tcmp; | |
| 159 | - | |
| 160 | - $tcmp->options->setTrackingEnable( true ); | |
| 161 | - $tcmp->options->setTrackingNotice( false ); | |
| 162 | - $this->sendTracking( true ); | |
| 163 | - } | |
| 164 | - public function disableTracking() { | |
| 165 | - global $tcmp; | |
| 166 | - | |
| 167 | - $tcmp->options->setTrackingEnable( false ); | |
| 168 | - $tcmp->options->setTrackingNotice( false ); | |
| 169 | - $this->sendTracking( true ); | |
| 170 | - } | |
| 171 | -} | |
| 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 | +} | |