Exemple #1
0
 /**
  * Detects a 'visit'
  *
  * This function updates the agent and domain table hits for a particular
  * visitor.  The user agent is recorded/incremented if this is the first visit.
  * A cookie is set to mark the first visit.
  */
 function detect()
 {
     if (mamboCore::get('mosConfig_enable_stats') == 1) {
         if (mosGetParam($_COOKIE, 'mosvisitor', 0)) {
             return;
         }
         setcookie("mosvisitor", "1");
         $agent = $_SERVER['HTTP_USER_AGENT'];
         $browser = mosGetBrowser($agent);
         $os = mosGetOS($agent);
         $domain = gethostbyaddr($_SERVER['REMOTE_ADDR']);
         // tease out the last element of the domain
         $tldomain = split("\\.", $domain);
         $tldomain = $tldomain[count($tldomain) - 1];
         if (is_numeric($tldomain)) {
             $tldomain = "Unknown";
         }
         $this->_db->setQuery("SELECT count(*), type FROM #__stats_agents WHERE (agent='{$browser}' AND type=0) OR (agent='{$os}' AND type=1) OR (agent='{$tldomain}' AND type=2) GROUP BY type");
         $stats = $this->_db->loadObjectList();
         $sql['browser'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('{$browser}',0)";
         $sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('{$os}',1)";
         $sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('{$tldomain}',2)";
         if ($stats) {
             foreach ($stats as $stat) {
                 if ($stat->type == 0) {
                     $sql['browser'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='{$browser}' AND type=0";
                 }
                 if ($stat->type == 1) {
                     $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='{$os}' AND type=1";
                 }
                 if ($stat->type == 2) {
                     $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='{$tldomain}' AND type=2";
                 }
             }
         }
         $this->_db->setQuery(implode('; ', $sql));
         $this->_db->query_batch();
     }
 }
Exemple #2
0
 /**
  * Detects a 'visit'
  *
  * This function updates the agent and domain table hits for a particular
  * visitor.  The user agent is recorded/incremented if this is the first visit.
  * A cookie is set to mark the first visit.
  */
 function detect()
 {
     global $mosConfig_enable_stats;
     if ($mosConfig_enable_stats == 1) {
         if (mosGetParam($_COOKIE, 'mosvisitor', 0)) {
             return;
         }
         setcookie('mosvisitor', 1);
         if (phpversion() <= '4.2.1') {
             $agent = getenv('HTTP_USER_AGENT');
             $domain = @gethostbyaddr(getenv("REMOTE_ADDR"));
         } else {
             if (isset($_SERVER['HTTP_USER_AGENT'])) {
                 $agent = $_SERVER['HTTP_USER_AGENT'];
             } else {
                 $agent = 'Unknown';
             }
             $domain = @gethostbyaddr($_SERVER['REMOTE_ADDR']);
         }
         $browser = mosGetBrowser($agent);
         $query = "SELECT COUNT(*)" . "\n FROM #__stats_agents" . "\n WHERE agent = " . $this->_db->Quote($browser) . "\n AND type = 0";
         $this->_db->setQuery($query);
         if ($this->_db->loadResult()) {
             $query = "UPDATE #__stats_agents" . "\n SET hits = ( hits + 1 )" . "\n WHERE agent = " . $this->_db->Quote($browser) . "\n AND type = 0";
             $this->_db->setQuery($query);
         } else {
             $query = "INSERT INTO #__stats_agents" . "\n ( agent, type )" . "\n VALUES ( " . $this->_db->Quote($browser) . ", 0 )";
             $this->_db->setQuery($query);
         }
         $this->_db->query();
         $os = mosGetOS($agent);
         $query = "SELECT COUNT(*)" . "\n FROM #__stats_agents" . "\n WHERE agent = " . $this->_db->Quote($os) . "\n AND type = 1";
         $this->_db->setQuery($query);
         if ($this->_db->loadResult()) {
             $query = "UPDATE #__stats_agents" . "\n SET hits = ( hits + 1 )" . "\n WHERE agent = " . $this->_db->Quote($os) . "\n AND type = 1";
             $this->_db->setQuery($query);
         } else {
             $query = "INSERT INTO #__stats_agents" . "\n ( agent, type )" . "\n VALUES ( " . $this->_db->Quote($os) . ", 1 )";
             $this->_db->setQuery($query);
         }
         $this->_db->query();
         // tease out the last element of the domain
         $tldomain = split("\\.", $domain);
         $tldomain = $tldomain[count($tldomain) - 1];
         if (is_numeric($tldomain)) {
             $tldomain = "Unknown";
         }
         $query = "SELECT COUNT(*)" . "\n FROM #__stats_agents" . "\n WHERE agent = " . $this->_db->Quote($tldomain) . "\n AND type = 2";
         $this->_db->setQuery($query);
         if ($this->_db->loadResult()) {
             $query = "UPDATE #__stats_agents" . "\n SET hits = ( hits + 1 )" . "\n WHERE agent = " . $this->_db->Quote($tldomain) . "\n AND type = 2";
             $this->_db->setQuery($query);
         } else {
             $query = "INSERT INTO #__stats_agents" . "\n ( agent, type )" . "\n VALUES ( " . $this->_db->Quote($tldomain) . ", 2 )";
             $this->_db->setQuery($query);
         }
         $this->_db->query();
     }
 }