/**
  * helper
  */
 function countryByIp($ip)
 {
     if ($ip == '127.0.0.1') {
         /* ignore localhost */
         return;
     }
     $query3 = sprintf("select ip, country from #__joomlawatch where (ip = '%s' and country is not NULL) limit 1", JoomlaWatchHelper::sanitize($ip));
     $this->database->setQuery($query3);
     $this->database->query();
     $row3 = $this->database->loadResult();
     if (@(!$row3->country)) {
         $iplook = new ip2country($ip);
         $iplook->UseDB = true;
         $iplook->db_tablename = "#__joomlawatch_ip2c";
         if ($iplook->LookUp()) {
             $country = strtolower($iplook->Country);
             $query3 = sprintf("update #__joomlawatch set country = '%s' where ip = '%s'", JoomlaWatchHelper::sanitize($country), JoomlaWatchHelper::sanitize($ip));
             $this->database->setQuery($query3);
             $this->database->query();
         }
     } else {
         $country = $row3->country;
     }
     return @$country;
 }