settings = get_option( 'adfoxly_settings' );
if ( isset( $this->settings[ 'statistics-status' ] ) && ! empty( $this->settings[ 'statistics-status' ] ) ) {
$this->setStatus( $this->settings[ 'statistics-status' ] );
}
$this->model = new AdfoxlyStatisticsModel();
}
/**
*
*/
public function setVisitor() {
$this->visitor = $this->getIpLocationJSON();
}
/**
* @return mixed
*/
public function getIpLocationJSON() {
return json_decode( $this->getIpLocation() );
}
/**
* @return bool|mixed
*/
public function getIpLocation() {
$ip = Adfoxly::ip();
if ( $ip === '::1' || $ip === '::' ) {
$ip = '104.27.178.42';
}
$ipApi = wp_remote_get( 'http://ip-api.com/json/' . $ip . '?fields=status,message,country,countryCode,region,regionName,city,zip,timezone' );
if ( isset( $ipApi ) && is_array( $ipApi ) && ( ! empty( $ipApi ) ) && isset( $ipApi[ 'body' ] ) && ! empty( $ipApi[ 'body' ] ) ) {
return $ipApi[ 'body' ];
}
return false;
}
/**
* @param $status
*/
public function setStatus( $status ) {
$this->status = $status;
}
/**
*
*/
public function insertTables() {
$this->model->insertTables();
}
/**
* @return string
*/
public function getFingerPrint() {
$ip = Adfoxly::ip();
if ( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) && ! empty( $_SERVER[ 'HTTP_USER_AGENT' ] ) ) {
$browser = $_SERVER[ 'HTTP_USER_AGENT' ];
} else {
$browser = 'NULL';
}
if ( isset( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] ) && ! empty( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] ) ) {
$language = $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ];
} else {
$language = 'NULL';
}
$fingerprint = "$ip + $browser + $language";
return md5( $fingerprint );
}
/**
* @param $id
*/
public function saveView( $id ) {
$this->model->saveView( $id, $this->getFingerPrint() );
}
public function saveSingleAdView( $id ) {
if( adfoxly_wa_fs()->can_use_premium_code__premium_only() ) {
$this->model->saveSingleAdView($id, $this->getFingerPrint());
}
}
/**
* @param null $id
*
* @return mixed
*/
public function render( $id = null ) {
if ( $this->status === 'enabled' ) {
if ( $this->settings[ 'statistics-type' ] === 'google-analytics' ) {
if ( ! empty( $this->settings ) ) {
if ( ! empty( $this->settings[ 'statistics-gaid-select' ] ) ) {
$gaid = $this->settings[ 'statistics-gaid-select' ];
} else if ( ! empty( $this->settings[ 'adfoxly-statistics-custom-gaid' ] ) ) {
$gaid = $this->settings[ 'adfoxly-statistics-custom-gaid' ];
}
}
if ( isset( $gaid ) && ! empty( $gaid ) ) {
add_action( 'wp_footer', function() use( $id, $gaid )
{
$render = '';
echo $render;
} );
}
} else if ( $this->settings[ 'statistics-type' ] === 'piwik' ) {
add_action( 'wp_footer', function() use( $id )
{
$render = '';
return $render;
} );
} else {
add_action( 'wp_footer', function() use( $id )
{
$render = '';
echo $render;
} );
}
if ( ! empty( $render ) ) {
return $render;
}
}
}
}