/**
  * visitor
  */
 function updateVisitByBrowser($uri, $referer, $title = null, $params = null)
 {
     $referer = urldecode($referer);
     // url comes url-encoded by default
     ExtraWatchLog::debug("updateVisitByBrowser - uri: {$uri}, referer: {$referer}, title: {$title}, params: " . print_r($params, true));
     if (@_EW_CLOUD_MODE) {
         $this->runAtMidnight();
         //executing this again, but won't be called if it was already executed. Because of cloud version which doesn't call insertVisit
     }
     $ip = addslashes(strip_tags(@$this->getRemoteIPAddress()));
     $isCachingEnabled = $this->env->isPHPCachingEnabled();
     if (@_EW_CLOUD_MODE || $isCachingEnabled) {
         //there's no insertVisit in cloud mode because of script
         ExtraWatchLog::debug("Insert bot visit: uri: {$uri} referer: {$referer} title: {$title} ip: {$ip}");
         $this->insertBotVisit($uri, $referer, $title, $ip);
     }
     $this->config->initializeTranslations();
     if (!$title) {
         $title = _EW_NO_TITLE;
     }
     $newUsername = @$this->env->getUsername();
     $liveSite = $this->config->getLiveSite();
     if (@_EW_CLOUD_MODE && $this->areVisitsEmpty()) {
         $projectUrl = $this->config->getDomainFromLiveSiteByUsername(_EW_PROJECT_ID);
         @mail(_EW_CLOUD_NOTIFY_EMAIL, "First visit for {$projectUrl}", "First visit for {$projectUrl}");
     }
     if ($this->heatmap->isHeatmapLoaded()) {
         return TRUE;
     }
     if ($this->config->isIgnored('IP', $ip) || $this->config->isIgnored('URI', $uri) || $this->config->isIgnored('USER', $newUsername)) {
         return TRUE;
     }
     if (@$title) {
         $query = sprintf("update #__extrawatch_uri set `title` = '%s' where (uri = '%s' and (title = '' or title is NULL)) ", $this->database->getEscaped($title), $this->database->getEscaped(htmlentities($uri)));
         $this->database->executeQuery($query);
     }
     $this->referer->checkSocialMedia($referer);
     $this->addUri2Title($uri, $title);
     $userAgent = addslashes(strip_tags(@$_SERVER['HTTP_USER_AGENT']));
     $this->updateRefererForIP($referer, $ip);
     $this->updateBrowserForIP($userAgent, $ip);
     if (@$referer) {
         // check if there is referer, otherwise there's no point to execute the code in this block
         //if (@ !$this->isVisitFromSameSite($referer))  {
         $isSameSite = $this->isVisitFromSameSite($referer);
         ExtraWatchLog::debug("referer: {$referer}, same site: " . (int) $isSameSite);
         if (@(!$isSameSite)) {
             /* from some other website */
             preg_match('@^(?:http[s]*://)?([^/]+)@i', $referer, $matches);
             $host = @$matches[1];
             $this->stat->increaseKeyValueInGroup(EW_DB_KEY_REFERERS, $host);
             $phrase = $this->extractPhraseFromUrl($referer);
             $phrase = str_replace("%2B", "+", $phrase);
             if (@$phrase) {
                 $this->stat->increaseKeyValueInGroup(EW_DB_KEY_KEYPHRASE, $phrase);
             }
             $this->insertSearchResultPage($uri, $phrase, $referer, $title);
             $keywords = explode(' ', $phrase);
             //using space instead of + because google has changed it
             if (trim($phrase)) {
                 $this->insertUri2KeyphraseByUriKeyphraseTitle($uri, $phrase, $title);
             }
             foreach ($keywords as $keyword) {
                 $keyword = @trim(strtolower($keyword));
                 if ($keyword && strlen($keyword) >= 3) {
                     //keyword leght must be >= as 3
                     $this->stat->increaseKeyValueInGroup(EW_DB_KEY_KEYWORDS, $keyword);
                 }
             }
         } else {
             /* starts with the live site */
             //this is now obsolete, because live site is now relative!
             //$referer = str_replace($liveSite, "", $referer);
             if (substr($referer, 0, 4) != "http" && substr($referer, 0, 1) != "/") {
                 $referer = "/" . $referer;
                 // add / prefix, because live site contains already / and it's replaced
             }
             $from = $referer;
             $from = str_replace(ExtraWatchHelper::getAbsoluteWebURL(), "", $from);
             //stripping liveSite
             $query = sprintf("select id from #__extrawatch_internal where (`from` = '%s' and `to` = '%s') ", $this->database->getEscaped($from), $this->database->getEscaped($uri));
             $id = $this->database->resultQuery($query);
             if (!@$id) {
                 $query = sprintf("insert into #__extrawatch_internal (`from`,`to`,`timestamp`) values ('%s', '%s', '%d') ", $this->database->getEscaped($from), $this->database->getEscaped($uri), (int) ExtraWatchDate::getUTCTimestamp());
                 $this->database->executeQuery($query);
                 $query = sprintf("select id from #__extrawatch_internal where (`from` = '%s' and `to` = '%s') ", $this->database->getEscaped($from), $this->database->getEscaped($uri));
                 $id = $this->database->resultQuery($query);
             }
             $query = sprintf("update #__extrawatch_internal set `timestamp` = '%d' where (id = '%d') ", $this->date->getUTCTimestamp(), (int) $id);
             $this->database->executeQuery($query);
             $this->stat->increaseKeyValueInGroup(EW_DB_KEY_INTERNAL, $id);
         }
     }
     if ($this->date->getUTCTimestamp() % 10 == 0) {
         $this->deleteOldVisits();
         $this->seo->cleanUnimportantKeyphrases();
     }
     $query = sprintf(" update #__extrawatch_uri LEFT JOIN #__extrawatch ON #__extrawatch_uri.fk = #__extrawatch.id\n                         set title = '%s'  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n                         where #__extrawatch_uri.uri = '%s' and #__extrawatch.ip = '%s'", $this->database->getEscaped(htmlentities($title, ENT_QUOTES, 'UTF-8')), $this->database->getEscaped($uri), $this->database->getEscaped($ip));
     $this->database->executeQuery($query);
     $this->makeVisitorActive($ip);
     $username = $this->getUsernameForIp($ip);
     if (@$username) {
         $this->updateUsernameForIp($username, $ip);
     }
     if (@$newUsername) {
         $this->stat->increaseKeyValueInGroup(EW_DB_KEY_USERS, $newUsername);
     }
     if ($this->config->getConfigValue('EXTRAWATCH_IP_STATS')) {
         $this->stat->increaseKeyValueInGroup(EW_DB_KEY_IP, $ip);
         //add ip watching
     }
     $this->stat->increaseKeyValueInGroup(EW_DB_KEY_HITS, EW_DB_KEY_HITS);
     $this->goal->checkGoals($title, $newUsername, $ip, $referer, $liveSite);
     $this->updateBrowserStats($ip, $userAgent);
     $query = sprintf("select #__extrawatch_uri.uri from #__extrawatch left join #__extrawatch_uri on #__extrawatch.id = #__extrawatch_uri.fk  where (#__extrawatch.ip = '%s') order by #__extrawatch_uri.timestamp desc limit 2", $this->database->getEscaped($ip));
     $rows = @$this->database->objectListQuery($query);
     $row = @$rows[0];
     $uri = @$row->uri;
     if (@$rows[1]) {
         $lastUriRow = $rows[1];
         $lastUri = $lastUriRow->uri;
     }
     $this->stat->increaseKeyValueInGroup(EW_DB_KEY_URI, $uri);
     $this->stat->increaseKeyValueInGroup(EW_DB_KEY_LOADS, EW_DB_KEY_LOADS);
     //$referer = $this->getReferer();
     if ($this->isVisitFromSameSite($referer)) {
         if (@$lastUri) {
             $this->flow->insertFlow($lastUri, $uri);
         }
     }
     //      if (time()%2 == 0) {
     $query = sprintf("update #__extrawatch  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\tset inactive = 1 where id in (  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\t\tSELECT fk FROM (  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\t\t\tSELECT MAX( TIMESTAMP ) AS maxTimestamp, fk  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\t\t\t\tFROM #__extrawatch_uri  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\t\t\t\tJOIN #__extrawatch on #__extrawatch.id = #__extrawatch_uri.fk  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\t\t\t\tWHERE #__extrawatch.inactive = 0  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t\t\t\tGROUP BY fk\n\t\t\t\t\t\t\t) AS T\n\t\t\t\t\t\tWHERE T.maxTimestamp < UNIX_TIMESTAMP( ) -600  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n\t\t\t\t\t)");
     //deactivate those which are on site longer than 10 minutes
     @$this->database->objectListQuery($query);
     //      }
     $this->saveGetParams($params, $uri);
 }