Example #1
0
 public function Visitors()
 {
     global $wp_query, $WP_Statistics;
     // Get the pages or posts ID if it exists.
     if (is_object($wp_query)) {
         $this->current_page_id = $wp_query->get_queried_object_id();
     }
     if ($this->get_option('use_honeypot') && $this->get_option('honeypot_postid') > 0 && $this->get_option('honeypot_postid') == $this->current_page_id && $this->current_page_id > 0) {
         $this->exclusion_match = TRUE;
         $this->exclusion_reason = "honeypot";
     }
     // If we're a webcrawler or referral from ourselves or an excluded address don't record the visit.
     // The exception here is if we've matched a honey page, we want to lookup the user and flag them
     // as having been trapped in the honey pot for later exclusions.
     if ($this->exclusion_reason == 'honeypot' || !$this->exclusion_match) {
         // Check to see if we already have an entry in the database.
         if ($this->ip_hash != false) {
             $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip_hash}'");
         } else {
             $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip}' AND `agent` = '{$this->agent['browser']}' AND `platform` = '{$this->agent['platform']}' AND `version` = '{$this->agent['version']}'");
         }
         // Check to see if this is a visit to the honey pot page, flag it when we create the new entry.
         $honeypot = 0;
         if ($this->exclusion_reason == 'honeypot') {
             $honeypot = 1;
         }
         // If we don't create a new one, otherwise update the old one.
         if (!$this->result) {
             // If we've been told to store the entire user agent, do so.
             if ($this->get_option('store_ua') == true) {
                 $ua = $_SERVER['HTTP_USER_AGENT'];
             } else {
                 $ua = '';
             }
             // Store the result.
             // We'd normally use the WordPress insert function, but since we may run in to a race condition where another hit to the site has already created a new entry in the database
             // for this IP address we want to do an "INSERT IGNORE" which WordPress doesn't support.
             $sqlstring = $this->db->prepare('INSERT IGNORE INTO ' . $this->tb_prefix . 'statistics_visitor (last_counter, referred, agent, platform, version, ip, location, UAString, hits, honeypot) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, 1, %s )', $this->Current_date('Y-m-d'), $this->get_Referred(), $this->agent['browser'], $this->agent['platform'], $this->agent['version'], $this->ip_hash ? $this->ip_hash : $this->ip, $this->location, $ua, $honeypot);
             $this->db->query($sqlstring);
             // Now parse the referrer and store the results in the search table if the database has been converted.
             // Also make sure we actually inserted a row on the INSERT IGNORE above or we'll create duplicate entries.
             if ($this->get_option('search_converted') && $this->db->insert_id) {
                 $search_engines = wp_statistics_searchengine_list();
                 $referred = $this->get_Referred();
                 // Parse the URL in to it's component parts.
                 $parts = parse_url($referred);
                 // Loop through the SE list until we find which search engine matches.
                 foreach ($search_engines as $key => $value) {
                     $search_regex = wp_statistics_searchengine_regex($key);
                     preg_match('/' . $search_regex . '/', $parts['host'], $matches);
                     if (isset($matches[1])) {
                         $data['last_counter'] = $this->Current_date('Y-m-d');
                         $data['engine'] = $key;
                         $data['words'] = $WP_Statistics->Search_Engine_QueryString($referred);
                         $data['host'] = $parts['host'];
                         $data['visitor'] = $this->db->insert_id;
                         if ($data['words'] == 'No search query found!') {
                             $data['words'] = '';
                         }
                         $this->db->insert($this->db->prefix . 'statistics_search', $data);
                     }
                 }
             }
         } else {
             // Normally we've done all of our exclusion matching during the class creation, however for the robot threshold is calculated here to avoid another call the database.
             if ($this->get_option('robot_threshold') > 0 && $this->result->hits + 1 > $this->get_option('robot_threshold')) {
                 $this->exclusion_match = TRUE;
                 $this->exclusion_reason = "robot_threshold";
             } else {
                 if ($this->result->honeypot) {
                     $this->exclusion_match = TRUE;
                     $this->exclusion_reason = "honeypot";
                 } else {
                     $sqlstring = $this->db->prepare('UPDATE ' . $this->tb_prefix . 'statistics_visitor SET `hits` = `hits` + %d, `honeypot` = %d WHERE `ID` = %d', 1 - $honeypot, $honeypot, $this->result->ID);
                     $this->db->query($sqlstring);
                 }
             }
         }
     }
     if ($this->exclusion_match) {
         $this->RecordExclusion();
     }
 }
Example #2
0
 public function Search_Engine_QueryString($url = false)
 {
     // If no URL was passed in, get the current referrer for the session.
     if (!$url) {
         $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
     }
     // If there is no URL and no referrer, always return false.
     if ($url == false) {
         return false;
     }
     // Parse the URL in to it's component parts.
     $parts = parse_url($url);
     // Check to see if there is a query component in the URL (everything after the ?).  If there isn't one
     // set an empty array so we don't get errors later.
     if (array_key_exists('query', $parts)) {
         parse_str($parts['query'], $query);
     } else {
         $query = array();
     }
     // Get the list of search engines we currently support.
     $search_engines = wp_statistics_searchengine_list();
     // Loop through the SE list until we find which search engine matches.
     foreach ($search_engines as $key => $value) {
         $search_regex = wp_statistics_searchengine_regex($key);
         preg_match('/' . $search_regex . '/', $parts['host'], $matches);
         if (isset($matches[1])) {
             // Check to see if the query key the SE uses exists in the query part of the URL.
             if (array_key_exists($search_engines[$key]['querykey'], $query)) {
                 $words = strip_tags($query[$search_engines[$key]['querykey']]);
             } else {
                 $words = '';
             }
             // If no words were found, return a pleasant default.
             if ($words == '') {
                 $words = 'No search query found!';
             }
             return $words;
         }
     }
     // We should never actually get to this point, but let's make sure we return something
     // just in case something goes terribly wrong.
     return 'No search query found!';
 }