public function __construct() { global $wp_version, $WP_Statistics; // Call the parent constructor (WP_Statistics::__construct) parent::__construct(); // Set the timestamp value. $this->timestamp = $this->current_date('U'); // Set the default seconds a user needs to visit the site before they are considered offline. $this->second = 30; // Get the user set value for seconds to check for users online. if ($this->get_option('check_online')) { $this->second = $this->get_option('check_online'); } // Check to see if the user wants us to record why we're excluding hits. if ($this->get_option('record_exclusions')) { $this->exclusion_record = TRUE; } // Let's check to see if our subnet matches a private IP address range, if so go ahead and set the location infomraiton now. if ($this->get_option('private_country_code') != '000' && $this->get_option('private_country_code') != '') { $private_subnets = array('10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '127.0.0.1/24'); foreach ($private_subnets as $psub) { if ($this->net_match($psub, $this->ip)) { $this->location = $this->get_option('private_country_code'); break; } } } // The follow exclusion checks are done during the class construction so we don't have to execute them twice if we're tracking visits and visitors. // // Order of exclusion checks is: // 1 - Robots // 2 - IP/Subnets // 3 - Self Referrals, Referrer Spam & login page // 4 - User roles // 5 - Host name list // // The GoeIP exclusions will be processed in the GeoIP hits class constructor. // // Get the upload directory from WordPRess. $upload_dir = wp_upload_dir(); // Create a variable with the name of the database file to download. $BrowscapFile = $upload_dir['basedir'] . '/wp-statistics'; $crawler = false; $ua_string = ""; if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) { $ua_string = $_SERVER['HTTP_USER_AGENT']; } if ($this->get_option('last_browscap_dl') > 1 && $this->get_option('browscap')) { // Get the Browser Capabilities use Browscap. $bc = new Browscap($BrowscapFile); $bc->doAutoUpdate = false; // We don't want to auto update. try { $current_browser = $bc->getBrowser(); // Make sure we got an object back and it has the Crawler property before accessing it. if (is_object($current_browser) && property_exists($current_browser, 'Crawler')) { $crawler = $current_browser->Crawler; } else { $crawler = false; } } catch (Exception $e) { $crawler = false; } } else { $this->update_option('update_browscap', true); } // If we're a crawler as per browscap, exclude us, otherwise double check based on the WP Statistics robot list. if ($crawler == true) { $this->exclusion_match = TRUE; $this->exclusion_reason = "browscap"; } else { // Pull the robots from the database. $robots = explode("\n", $this->get_option('robotlist')); // Check to see if we match any of the robots. foreach ($robots as $robot) { $robot = trim($robot); // If the match case is less than 4 characters long, it might match too much so don't execute it. if (strlen($robot) > 3) { if (stripos($ua_string, $robot) !== FALSE) { $this->exclusion_match = TRUE; $this->exclusion_reason = "robot"; break; } } } // Finally check to see if we have corrupt header information. if (!$this->exclusion_match && $this->get_option('corrupt_browser_info')) { if ($ua_string == '' || $this->ip == '') { $this->exclusion_match = TRUE; $this->exclusion_reason = "robot"; } } } // If we didn't match a robot, check ip subnets. if (!$this->exclusion_match) { // Pull the subnets from the database. $subnets = explode("\n", $this->get_option('exclude_ip')); // Check to see if we match any of the excluded addresses. foreach ($subnets as $subnet) { $subnet = trim($subnet); // The shortest ip address is 1.1.1.1, anything less must be a malformed entry. if (strlen($subnet) > 6) { if ($this->net_match($subnet, $this->ip)) { $this->exclusion_match = TRUE; $this->exclusion_reason = "ip match"; break; } } } // Check to see if we are being referred to ourselves. if (!$this->exclusion_match) { if ($ua_string == "WordPress/" . $wp_version . "; " . get_home_url(null, "/")) { $this->exclusion_match = TRUE; $this->exclusion_reason = "self referral"; } if ($ua_string == "WordPress/" . $wp_version . "; " . get_home_url()) { $this->exclusion_match = TRUE; $this->exclusion_reason = "self referral"; } if ($this->get_option('exclude_loginpage')) { $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === FALSE ? 'http' : 'https'; $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['SCRIPT_NAME']; $currentURL = $protocol . '://' . $host . $script; $loginURL = wp_login_url(); if ($currentURL == $loginURL) { $this->exclusion_match = TRUE; $this->exclusion_reason = "login page"; } } if ($this->get_option('exclude_adminpage') && !$this->exclusion_match) { $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === FALSE ? 'http' : 'https'; $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['SCRIPT_NAME']; $currentURL = $protocol . '://' . $host . $script; $adminURL = get_admin_url(); $currentURL = substr($currentURL, 0, strlen($adminURL)); if ($currentURL == $adminURL) { $this->exclusion_match = TRUE; $this->exclusion_reason = "admin page"; } } if ($this->get_option('referrerspam') && !$this->exclusion_match) { $referrer = $this->get_Referred(); // Pull the referrer spam list from the database. $referrerspamlist = explode("\n", $this->get_option('referrerspamlist')); // Check to see if we match any of the robots. foreach ($referrerspamlist as $item) { $item = trim($item); // If the match case is less than 4 characters long, it might match too much so don't execute it. if (strlen($item) > 3) { if (stripos($referrer, $item) !== FALSE) { $this->exclusion_match = TRUE; $this->exclusion_reason = "referrer_spam"; break; } } } } if ($this->get_option('exclude_feeds') && !$this->exclusion_match) { if (is_object($WP_Statistics)) { if ($WP_Statistics->check_feed()) { $this->exclusion_match = TRUE; $this->exclusion_reason = "feed"; } } } if ($this->get_option('exclude_404s') && !$this->exclusion_match) { if (is_404()) { $this->exclusion_match = TRUE; $this->exclusion_reason = "404"; } } if ($this->get_option('excluded_urls') && !$this->exclusion_match) { $script = $_SERVER['REQUEST_URI']; $delimiter = strpos($script, '?'); if ($delimiter > 0) { $script = substr($script, 0, $delimiter); } $excluded_urls = explode("\n", $this->get_option('excluded_urls')); foreach ($excluded_urls as $url) { $this_url = trim($url); if (strlen($this_url) > 2) { if (stripos($script, $this_url) === 0) { $this->exclusion_match = TRUE; $this->exclusion_reason = "excluded url"; break; } } } } // Check to see if we are excluding based on the user role. if (!$this->exclusion_match) { if (is_user_logged_in()) { $current_user = wp_get_current_user(); foreach ($current_user->roles as $role) { $option_name = 'exclude_' . str_replace(" ", "_", strtolower($role)); if ($this->get_option($option_name) == TRUE) { $this->exclusion_match = TRUE; $this->exclusion_reason = "user role"; break; } } } // Check to see if we are excluded by the host name. if (!$this->exclusion_match) { $excluded_host = explode("\n", $this->get_option('excluded_hosts')); // If there's nothing in the excluded host list, don't do anything. if (count($excluded_host) > 0) { $transient_name = 'wps_excluded_hostname_to_ip_cache'; // Get the transient with the hostname cache. $hostname_cache = get_transient($transient_name); // If the transient has expired (or has never been set), create one now. if ($hostname_cache === false) { // Flush the failed cache variable. $hostname_cache = array(); // Loop through the list of hosts and look them up. foreach ($excluded_host as $host) { if (strpos($host, '.') > 0) { // We add the extra period to the end of the host name to make sure we don't append the local dns suffix to the resolution cycle. $hostname_cache[$host] = gethostbyname($host . "."); } } // Set the transient and store it for 1 hour. set_transient($transient_name, $hostname_cache, 360); } // Check if the current IP address matches one of the ones in the excluded hosts list. if (in_array($this->ip, $hostname_cache)) { $this->exclusion_match = TRUE; $this->exclusion_reason = "hostname"; } } } } } } }
} // This adds a row after WP Statistics in the plugin page IF we've been removed via the settings page. function wp_statistics_removal_after_plugin_row() { echo '<tr><th scope="row" class="check-column"></th><td class="plugin-title" colspan="*"><span style="padding: 3px; color: white; background-color: red; font-weight: bold"> ' . __('WP Statistics has been removed, please disable and delete it.', 'wp_statistics') . ' </span></td></tr>'; } // If we've been removed, return without doing anything else. if (get_option('wp_statistics_removal') == 'done') { add_action('after_plugin_row_' . plugin_basename(__FILE__), 'wp_statistics_removal_after_plugin_row', 10, 2); return; } // Load the user agent parsing code first, the WP_Statistics class depends on it. Then load the WP_Statistics class. include_once dirname(__FILE__) . '/includes/functions/parse-user-agent.php'; include_once dirname(__FILE__) . '/includes/classes/statistics.class.php'; // This is our global WP_Statitsics class that is used throughout the plugin. $WP_Statistics = new WP_Statistics(); // Check to see if we're installed and are the current version. $WPS_Installed = get_option('wp_statistics_plugin_version'); if ($WPS_Installed != WP_STATISTICS_VERSION) { include_once dirname(__FILE__) . '/wps-install.php'; } // Load the update functions for GeoIP and browscap.ini (done in a separate file to avoid a parse error in PHP 5.2 or below) include_once dirname(__FILE__) . '/wps-updates.php'; // Load the rest of the required files for our global functions, online user tracking and hit tracking. include_once dirname(__FILE__) . '/includes/functions/functions.php'; include_once dirname(__FILE__) . '/includes/classes/hits.class.php'; // If GeoIP is enabled and supported, extend the hits class to record the GeoIP information. if ($WP_Statistics->get_option('geoip') && wp_statistics_geoip_supported()) { include_once dirname(__FILE__) . '/includes/classes/hits.geoip.class.php'; } // Finally load the widget, dashboard, shortcode and scheduled events.
} // This adds a row after WP Statistics in the plugin page IF we've been removed via the settings page. function wp_statistics_removal_after_plugin_row() { echo '<tr><th scope="row" class="check-column"></th><td class="plugin-title" colspan="*"><span style="padding: 3px; color: white; background-color: red; font-weight: bold"> ' . __('WP Statistics has been removed, please disable and delete it.', 'wp_statistics') . ' </span></td></tr>'; } // If we've been removed, return without doing anything else. if (get_option('wp_statistics_removal') == 'done') { add_action('after_plugin_row_' . plugin_basename(__FILE__), 'wp_statistics_removal_after_plugin_row', 10, 2); return; } // Load the user agent parsing code first, the WP_Statistics class depends on it. Then load the WP_Statistics class. include_once dirname(__FILE__) . '/vendor/donatj/phpuseragentparser/Source/UserAgentParser.php'; include_once dirname(__FILE__) . '/includes/classes/statistics.class.php'; // This is our global WP_Statitsics class that is used throughout the plugin. $WP_Statistics = new WP_Statistics(); // Check to see if we're installed and are the current version. $WPS_Installed = get_option('wp_statistics_plugin_version'); if ($WPS_Installed != WP_STATISTICS_VERSION) { include_once dirname(__FILE__) . '/wps-install.php'; } // Load the update functions for GeoIP and browscap.ini (done in a separate file to avoid a parse error in PHP 5.2 or below) include_once dirname(__FILE__) . '/wps-updates.php'; // Load the rest of the required files for our global functions, online user tracking and hit tracking. include_once dirname(__FILE__) . '/includes/functions/functions.php'; include_once dirname(__FILE__) . '/includes/classes/hits.class.php'; // If GeoIP is enabled and supported, extend the hits class to record the GeoIP information. if ($WP_Statistics->get_option('geoip') && wp_statistics_geoip_supported()) { include_once dirname(__FILE__) . '/includes/classes/hits.geoip.class.php'; } // Finally load the widget, dashboard, shortcode and scheduled events.