<commit_before><?php namespace Controller;

class BaseController {
	
	public function __construct(){
		\Bootie\App::load_database();
	}

	public function ip2geo(){
		extract($_POST);

		$ip = getenv('REMOTE_ADDR');

		if( $ip != '127.0.0.1' ) {

			$blog = config('blog');
			$geoip = self::ip2geolocation($ip);
			//$geoip = curl_request('http://www.telize.com/geoip/' . $ip);
			$hit = new \Model\Hit();

			if($geoip)
			{
				if(isset($geoip->city))
				{
					$hit->city = $geoip->city;
				}

				if(isset($geoip->country))
				{
					$hit->country = $geoip->country;
				}

				if(isset($geoip->region))
				{
					$hit->region = $geoip->region;
				}

				if(isset($geoip->latitude))
				{
					$hit->latitude = $geoip->latitude;
				}

				if(isset($geoip->longitude))
				{
					$hit->longitude = $geoip->longitude;
				}
			}

			$hit->path = $path;
			$hit->user_id = $blog->data->id;
			$hit->user_agent = getenv('HTTP_USER_AGENT');
			$hit->created = TIME;
			$hit->updated = TIME;
			$hit->save();

			return TRUE;
		}
		return FALSE;
	}	

	private function ip2geolocation($ip)
	{
	    $apiurl = 'http://ip-api.com/json/' . $ip;
	    //$apiurl = 'http://freegeoip.net/json/' . $ip;
	    //$apiurl = 'http://www.telize.com/geoip/' . $ip;
	    
	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $apiurl);
	    curl_setopt($ch, CURLOPT_HEADER, false);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<commit_msg>Geodata provider<commit_after><?php namespace Controller;

class BaseController {
	
	public function __construct(){
		\Bootie\App::load_database();
	}

	public function ip2geo(){
		extract($_POST);

		$ip = getenv('REMOTE_ADDR');

		if( $ip != '127.0.0.1' ) {

			$blog = config('blog');
			$geoip = self::ip2geolocation($ip);
			//$geoip = curl_request('http://www.telize.com/geoip/' . $ip);
			$hit = new \Model\Hit();

			if($geoip)
			{
				if(isset($geoip->city))
				{
					$hit->city = $geoip->city;
				}

				if(isset($geoip->country))
				{
					$hit->country = $geoip->country;
				}

				if(isset($geoip->region))
				{
					$hit->region = $geoip->region;
				}

				if(isset($geoip->latitude))
				{
					$hit->latitude = $geoip->lat;
				}

				if(isset($geoip->longitude))
				{
					$hit->longitude = $geoip->lon;
				}
			}

			$hit->path = $path;
			$hit->user_id = $blog->data->id;
			$hit->user_agent = getenv('HTTP_USER_AGENT');
			$hit->created = TIME;
			$hit->updated = TIME;
			$hit->save();

			return TRUE;
		}
		return FALSE;
	}	

	private function ip2geolocation($ip)
	{
	    $apiurl = 'http://ip-api.com/json/' . $ip;
	    //$apiurl = 'http://freegeoip.net/json/' . $ip;
	    //$apiurl = 'http://www.telize.com/geoip/' . $ip;
	    
	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $apiurl);
	    curl_setopt($ch, CURLOPT_HEADER, false);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
{'fraction_non_alphanumeric': 0.2030704815073273, 'fraction_numerical': 0.00628053035589672, 'mean_word_length': 2.6756410256410255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236731', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1103, 'n_words': 164}