Skip to content

Commit

Permalink
Make the Strict counts option actually work, make it encrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszarendt committed Mar 12, 2021
1 parent 7018d53 commit b205915
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion includes/counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ public function check_post( $id = 0 ) {
}
}
}

// strict counts?
if ( Post_Views_Counter()->options['general']['strict_counts'] ) {
// get IP cached visits
$ip_cache = get_transient( 'post_views_counter_ip_cache' );

if ( ! $ip_cache )
$ip_cache = array();

// get user IP address
$user_ip = $this->encrypt_ip( $this->get_user_ip() );

// get current time
$current_time = current_time( 'timestamp', true );

// visit exists in transient?
if ( isset( $ip_cache[$id][$user_ip] ) ) {
if ( $current_time < $ip_cache[$id][$user_ip] + $this->get_timestamp( Post_Views_Counter()->options['general']['time_between_counts']['type'], Post_Views_Counter()->options['general']['time_between_counts']['number'], false ) )
return;
}
}

// get groups to check them faster
$groups = Post_Views_Counter()->options['general']['exclude']['groups'];
Expand Down Expand Up @@ -365,6 +386,10 @@ private function save_cookie( $id, $cookie = array(), $expired = true ) {
*/
private function save_ip( $id ) {
$set_cookie = apply_filters( 'pvc_maybe_set_cookie', true );

// Cookie Notice compatibility
if ( function_exists( 'cn_cookies_accepted' ) && ! cn_cookies_accepted() )
$set_cookie = false;

if ( $set_cookie !== true )
return $id;
Expand All @@ -376,7 +401,7 @@ private function save_ip( $id ) {
$ip_cache = array();

// get user IP address
$user_ip = $this->get_user_ip();
$user_ip = $this->encrypt_ip( $this->get_user_ip() );

// get current time
$current_time = current_time( 'timestamp', true );
Expand Down

0 comments on commit b205915

Please sign in to comment.