Post Views Counter - Version 1.3.5

Version Description

  • New: Option to hide admin bar chart
  • Fix: Small security bug with views label
  • Tweak: Remove unnecessary CSS on every page
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Post Views Counter
Version 1.3.5
Comparing to
See all releases

Code changes from version 1.3.4 to 1.3.5

includes/columns.php CHANGED
@@ -470,54 +470,57 @@ class Post_Views_Counter_Columns {
470
  * Add admin bar stats to a post.
471
  */
472
  public function admin_bar_menu( $admin_bar ) {
 
 
 
 
 
 
 
473
  $post = null;
474
-
475
  if ( is_admin() && ! wp_doing_ajax() ) {
476
  global $pagenow;
477
-
478
  $post = $pagenow == 'post.php' && ! empty( $_GET['post'] ) ? get_post( (int) $_GET['post'] ) : $post;
479
- } elseif ( is_singular() ) {
480
  global $post;
481
- }
482
-
483
  // get countable post types
484
  $post_types = Post_Views_Counter()->options['general']['post_types_count'];
485
 
486
  // whether to count this post type or not
487
  if ( empty( $post_types ) || empty( $post ) || ! in_array( $post->post_type, $post_types, true ) )
488
  return;
489
-
490
  $dt = new DateTime();
491
- $date = $dt->format( 'Y-m-d\TH:i:s.v' );
492
- $year = date_i18n( 'Y', $date );
493
- $month = date_i18n( 'm', $date );
494
- $week = date_i18n( 'W', $date );
495
- $day = date_i18n( 'd', $date );
496
-
497
  $views = pvc_get_views( array(
498
  'post_id' => $post->ID,
499
  'post_type' => $post->post_type,
500
  'fields' => 'date=>views',
501
  'views_query' => array(
502
- 'year' => $year,
503
- // 'week' => $week,
504
- 'month' => $month,
505
- // 'day' => $day
506
  )
507
  ) );
508
-
509
  $graph = '';
510
-
511
  // get highest value
512
  $views_copy = $views;
 
513
  arsort( $views_copy, SORT_NUMERIC );
 
514
  $highest = reset( $views_copy );
 
515
  // find the multiplier
516
  $multiplier = $highest * 0.05;
517
-
518
  // generate ranges
519
  $ranges = array();
520
-
521
  for ( $i = 1; $i <= 20; $i ++ ) {
522
  $ranges[$i] = round( $multiplier * $i );
523
  }
@@ -525,7 +528,7 @@ class Post_Views_Counter_Columns {
525
  // create graph
526
  foreach ( $views as $date => $count ) {
527
  $count_class = 0;
528
-
529
  if ( $count > 0 ) {
530
  foreach ( $ranges as $index => $range ) {
531
  if ( $count <= $range ) {
@@ -534,36 +537,44 @@ class Post_Views_Counter_Columns {
534
  }
535
  }
536
  }
537
-
538
  $graph .= '<span class="pvc-line-graph pvc-line-graph-' . $count_class . '" title="' . sprintf( _n( '%s post view', '%s post views', $count, 'post-views-counter' ), number_format_i18n( $count ) ) . '"></span>';
539
  }
540
-
541
- $admin_bar->add_menu( array(
542
- 'id' => 'pvc-post-views',
543
- 'title' => '<span class="pvc-graph-container">' . $graph . '</span>',
544
- 'href' => false,
545
- 'meta' => array(
546
- 'title' => false
547
- ),
548
- ) );
 
 
549
  }
550
-
551
  /**
552
  * Maybe add admin CSS.
553
  */
554
  public function admin_bar_maybe_add_style() {
 
 
 
 
 
 
 
555
  $post = null;
556
-
557
  if ( is_admin() && ! wp_doing_ajax() ) {
558
  global $pagenow;
559
-
560
- $post = $pagenow == 'post.php' && ! empty( $_GET['post'] ) ? get_post( (int) $_GET['post'] ) : $post;
561
- } elseif ( is_singular() ) {
562
  global $post;
563
- }
564
-
565
  // get countable post types
566
- $post_types = Post_Views_Counter()->options['general']['post_types_count'];
567
 
568
  // whether to count this post type or not
569
  if ( empty( $post_types ) || empty( $post ) || ! in_array( $post->post_type, $post_types, true ) )
@@ -571,35 +582,36 @@ class Post_Views_Counter_Columns {
571
 
572
  // on backend area
573
  add_action( 'admin_head', array( $this, 'admin_bar_css' ) );
 
574
  // on frontend area
575
  add_action( 'wp_head', array( $this, 'admin_bar_css' ) );
576
  }
577
-
578
  /**
579
  * Add admin CSS.
580
  */
581
  public function admin_bar_css() {
582
  $html = '
583
- <style type="text/css">
584
- #wp-admin-bar-pvc-post-views .pvc-graph-container { padding-top: 6px; padding-bottom: 6px; position: relative; display: block; height: 100%; box-sizing: border-box; }
585
- #wp-admin-bar-pvc-post-views .pvc-line-graph {
586
- display: inline-block;
587
- width: 1px;
588
- margin-right: 1px;
589
- background-color: #ccc;
590
- vertical-align: baseline;
591
- }
592
- #wp-admin-bar-pvc-post-views .pvc-line-graph:hover { background-color: #eee; }
593
- #wp-admin-bar-pvc-post-views .pvc-line-graph-0 { height: 1% }';
594
-
595
  for ( $i = 1; $i <= 20; $i ++ ) {
596
  $html .= '
597
- #wp-admin-bar-pvc-post-views .pvc-line-graph-' . $i . ' { height: ' . $i * 5 . '% }';
598
  }
599
-
600
  $html .= '
601
- </style>';
602
-
603
  echo $html;
604
  }
605
- }
470
  * Add admin bar stats to a post.
471
  */
472
  public function admin_bar_menu( $admin_bar ) {
473
+ // get main instance
474
+ $pvc = Post_Views_Counter();
475
+
476
+ // statistics enabled?
477
+ if ( ! apply_filters( 'pvc_display_toolbar_statistics', $pvc->options['display']['toolbar_statistics'] ) )
478
+ return;
479
+
480
  $post = null;
481
+
482
  if ( is_admin() && ! wp_doing_ajax() ) {
483
  global $pagenow;
484
+
485
  $post = $pagenow == 'post.php' && ! empty( $_GET['post'] ) ? get_post( (int) $_GET['post'] ) : $post;
486
+ } elseif ( is_singular() )
487
  global $post;
488
+
 
489
  // get countable post types
490
  $post_types = Post_Views_Counter()->options['general']['post_types_count'];
491
 
492
  // whether to count this post type or not
493
  if ( empty( $post_types ) || empty( $post ) || ! in_array( $post->post_type, $post_types, true ) )
494
  return;
495
+
496
  $dt = new DateTime();
497
+
498
+ // get post views
 
 
 
 
499
  $views = pvc_get_views( array(
500
  'post_id' => $post->ID,
501
  'post_type' => $post->post_type,
502
  'fields' => 'date=>views',
503
  'views_query' => array(
504
+ 'year' => $dt->format( 'Y' ),
505
+ 'month' => $dt->format( 'm' )
 
 
506
  )
507
  ) );
508
+
509
  $graph = '';
510
+
511
  // get highest value
512
  $views_copy = $views;
513
+
514
  arsort( $views_copy, SORT_NUMERIC );
515
+
516
  $highest = reset( $views_copy );
517
+
518
  // find the multiplier
519
  $multiplier = $highest * 0.05;
520
+
521
  // generate ranges
522
  $ranges = array();
523
+
524
  for ( $i = 1; $i <= 20; $i ++ ) {
525
  $ranges[$i] = round( $multiplier * $i );
526
  }
528
  // create graph
529
  foreach ( $views as $date => $count ) {
530
  $count_class = 0;
531
+
532
  if ( $count > 0 ) {
533
  foreach ( $ranges as $index => $range ) {
534
  if ( $count <= $range ) {
537
  }
538
  }
539
  }
540
+
541
  $graph .= '<span class="pvc-line-graph pvc-line-graph-' . $count_class . '" title="' . sprintf( _n( '%s post view', '%s post views', $count, 'post-views-counter' ), number_format_i18n( $count ) ) . '"></span>';
542
  }
543
+
544
+ $admin_bar->add_menu(
545
+ [
546
+ 'id' => 'pvc-post-views',
547
+ 'title' => '<span class="pvc-graph-container">' . $graph . '</span>',
548
+ 'href' => false,
549
+ 'meta' => [
550
+ 'title' => false
551
+ ]
552
+ ]
553
+ );
554
  }
555
+
556
  /**
557
  * Maybe add admin CSS.
558
  */
559
  public function admin_bar_maybe_add_style() {
560
+ // get main instance
561
+ $pvc = Post_Views_Counter();
562
+
563
+ // statistics enabled?
564
+ if ( ! $pvc->options['display']['toolbar_statistics'] )
565
+ return;
566
+
567
  $post = null;
568
+
569
  if ( is_admin() && ! wp_doing_ajax() ) {
570
  global $pagenow;
571
+
572
+ $post = ( $pagenow === 'post.php' && ! empty( $_GET['post'] ) ) ? get_post( (int) $_GET['post'] ) : $post;
573
+ } elseif ( is_singular() )
574
  global $post;
575
+
 
576
  // get countable post types
577
+ $post_types = $pvc->options['general']['post_types_count'];
578
 
579
  // whether to count this post type or not
580
  if ( empty( $post_types ) || empty( $post ) || ! in_array( $post->post_type, $post_types, true ) )
582
 
583
  // on backend area
584
  add_action( 'admin_head', array( $this, 'admin_bar_css' ) );
585
+
586
  // on frontend area
587
  add_action( 'wp_head', array( $this, 'admin_bar_css' ) );
588
  }
589
+
590
  /**
591
  * Add admin CSS.
592
  */
593
  public function admin_bar_css() {
594
  $html = '
595
+ <style type="text/css">
596
+ #wp-admin-bar-pvc-post-views .pvc-graph-container { padding-top: 6px; padding-bottom: 6px; position: relative; display: block; height: 100%; box-sizing: border-box; }
597
+ #wp-admin-bar-pvc-post-views .pvc-line-graph {
598
+ display: inline-block;
599
+ width: 1px;
600
+ margin-right: 1px;
601
+ background-color: #ccc;
602
+ vertical-align: baseline;
603
+ }
604
+ #wp-admin-bar-pvc-post-views .pvc-line-graph:hover { background-color: #eee; }
605
+ #wp-admin-bar-pvc-post-views .pvc-line-graph-0 { height: 1% }';
606
+
607
  for ( $i = 1; $i <= 20; $i ++ ) {
608
  $html .= '
609
+ #wp-admin-bar-pvc-post-views .pvc-line-graph-' . $i . ' { height: ' . $i * 5 . '% }';
610
  }
611
+
612
  $html .= '
613
+ </style>';
614
+
615
  echo $html;
616
  }
617
+ }
includes/counter.php CHANGED
@@ -674,15 +674,15 @@ class Post_Views_Counter_Counter {
674
 
675
  global $wpdb;
676
 
677
- // $result = $wpdb->query( "
678
- // INSERT INTO " . $wpdb->prefix . "post_views (id, type, period, count)
679
- // VALUES " . $this->db_insert_values . "
680
- // ON DUPLICATE KEY UPDATE count = count + VALUES(count)"
681
- // );
682
 
683
  $this->db_insert_values = '';
684
 
685
- // return $result;
686
  }
687
 
688
  /**
@@ -760,9 +760,9 @@ class Post_Views_Counter_Counter {
760
 
761
  return true;
762
  }
763
-
764
  /**
765
- * Encrypt user IP
766
  *
767
  * @param int $ip
768
  * @return string $encrypted_ip
@@ -772,7 +772,7 @@ class Post_Views_Counter_Counter {
772
  $auth_iv = defined( 'NONCE_KEY' ) ? NONCE_KEY : '';
773
 
774
  // mcrypt strong encryption
775
- if ( function_exists( 'mcrypt_encrypt' ) && defined( 'MCRYPT_BLOWFISH' ) ) {
776
  // get max key size of the mcrypt mode
777
  $max_key_size = mcrypt_get_key_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
778
  $max_iv_size = mcrypt_get_iv_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
@@ -781,7 +781,7 @@ class Post_Views_Counter_Counter {
781
  $encrypt_iv = mb_strimwidth( $auth_iv, 0, $max_iv_size );
782
 
783
  $encrypted_ip = strtr( base64_encode( mcrypt_encrypt( MCRYPT_BLOWFISH, $encrypt_key, $ip, MCRYPT_MODE_CBC, $encrypt_iv ) ), '+/=', '-_,' );
784
- // simple encryption
785
  } elseif ( function_exists( 'gzdeflate' ) )
786
  $encrypted_ip = base64_encode( convert_uuencode( gzdeflate( $ip ) ) );
787
  // no encryption
@@ -792,7 +792,7 @@ class Post_Views_Counter_Counter {
792
  }
793
 
794
  /**
795
- * Decrypt user IP
796
  *
797
  * @param int $encrypted_ip
798
  * @return string $ip
@@ -802,7 +802,7 @@ class Post_Views_Counter_Counter {
802
  $auth_iv = defined( 'NONCE_KEY' ) ? NONCE_KEY : '';
803
 
804
  // mcrypt strong encryption
805
- if ( function_exists( 'mcrypt_decrypt' ) && defined( 'MCRYPT_BLOWFISH' ) ) {
806
  // get max key size of the mcrypt mode
807
  $max_key_size = mcrypt_get_key_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
808
  $max_iv_size = mcrypt_get_iv_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
@@ -811,13 +811,12 @@ class Post_Views_Counter_Counter {
811
  $encrypt_iv = mb_strimwidth( $auth_iv, 0, $max_iv_size );
812
 
813
  $ip = mcrypt_decrypt( MCRYPT_BLOWFISH, $encrypt_key, base64_decode( strtr( $encrypted_ip, '-_,', '+/=' ) ), MCRYPT_MODE_CBC, $encrypt_iv );
814
- // simple encryption
815
- } elseif ( function_exists( 'gzinflate' ) ) {
816
  $ip = gzinflate( convert_uudecode( base64_decode( $encrypted_ip ) ) );
817
- // no encryption
818
- } else {
819
  $ip = convert_uudecode( base64_decode( strtr( $encrypted_ip, '-_,', '+/=' ) ) );
820
- }
821
 
822
  return $ip;
823
  }
674
 
675
  global $wpdb;
676
 
677
+ $result = $wpdb->query( "
678
+ INSERT INTO " . $wpdb->prefix . "post_views (id, type, period, count)
679
+ VALUES " . $this->db_insert_values . "
680
+ ON DUPLICATE KEY UPDATE count = count + VALUES(count)"
681
+ );
682
 
683
  $this->db_insert_values = '';
684
 
685
+ return $result;
686
  }
687
 
688
  /**
760
 
761
  return true;
762
  }
763
+
764
  /**
765
+ * Encrypt user IP.
766
  *
767
  * @param int $ip
768
  * @return string $encrypted_ip
772
  $auth_iv = defined( 'NONCE_KEY' ) ? NONCE_KEY : '';
773
 
774
  // mcrypt strong encryption
775
+ if ( function_exists( 'mcrypt_encrypt' ) && function_exists( 'mcrypt_get_key_size' ) && function_exists( 'mcrypt_get_iv_size' ) && defined( 'MCRYPT_BLOWFISH' ) ) {
776
  // get max key size of the mcrypt mode
777
  $max_key_size = mcrypt_get_key_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
778
  $max_iv_size = mcrypt_get_iv_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
781
  $encrypt_iv = mb_strimwidth( $auth_iv, 0, $max_iv_size );
782
 
783
  $encrypted_ip = strtr( base64_encode( mcrypt_encrypt( MCRYPT_BLOWFISH, $encrypt_key, $ip, MCRYPT_MODE_CBC, $encrypt_iv ) ), '+/=', '-_,' );
784
+ // simple encryption
785
  } elseif ( function_exists( 'gzdeflate' ) )
786
  $encrypted_ip = base64_encode( convert_uuencode( gzdeflate( $ip ) ) );
787
  // no encryption
792
  }
793
 
794
  /**
795
+ * Decrypt user IP.
796
  *
797
  * @param int $encrypted_ip
798
  * @return string $ip
802
  $auth_iv = defined( 'NONCE_KEY' ) ? NONCE_KEY : '';
803
 
804
  // mcrypt strong encryption
805
+ if ( function_exists( 'mcrypt_decrypt' ) && function_exists( 'mcrypt_get_key_size' ) && function_exists( 'mcrypt_get_iv_size' ) && defined( 'MCRYPT_BLOWFISH' ) ) {
806
  // get max key size of the mcrypt mode
807
  $max_key_size = mcrypt_get_key_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
808
  $max_iv_size = mcrypt_get_iv_size( MCRYPT_BLOWFISH, MCRYPT_MODE_CBC );
811
  $encrypt_iv = mb_strimwidth( $auth_iv, 0, $max_iv_size );
812
 
813
  $ip = mcrypt_decrypt( MCRYPT_BLOWFISH, $encrypt_key, base64_decode( strtr( $encrypted_ip, '-_,', '+/=' ) ), MCRYPT_MODE_CBC, $encrypt_iv );
814
+ // simple encryption
815
+ } elseif ( function_exists( 'gzinflate' ) )
816
  $ip = gzinflate( convert_uudecode( base64_decode( $encrypted_ip ) ) );
817
+ // no encryption
818
+ else
819
  $ip = convert_uudecode( base64_decode( strtr( $encrypted_ip, '-_,', '+/=' ) ) );
 
820
 
821
  return $ip;
822
  }
includes/functions.php CHANGED
@@ -394,7 +394,7 @@ if ( ! function_exists( 'pvc_post_views' ) ) {
394
  $icon_class = ( $options['icon_class'] !== '' ? esc_attr( $options['icon_class'] ) : '' );
395
 
396
  // add dashicons class if needed
397
- $icon_class = strpos( $icon_class, 'dashicons' ) === 0 ? 'dashicons ' . $icon_class : $icon_class;
398
 
399
  // prepare icon output
400
  $icon = apply_filters( 'pvc_post_views_icon', '<span class="post-views-icon ' . $icon_class . '"></span>', $post_id );
@@ -403,7 +403,7 @@ if ( ! function_exists( 'pvc_post_views' ) ) {
403
  'pvc_post_views_html',
404
  '<div class="post-views post-' . $post_id . ' entry-meta">
405
  ' . ( $options['display_style']['icon'] && $icon_class !== '' ? $icon : '' ) . '
406
- ' . ( $options['display_style']['text'] && $label !== '' ? '<span class="post-views-label">' . $label . ' </span>' : '' ) . '
407
  <span class="post-views-count">' . number_format_i18n( $views ) . '</span>
408
  </div>',
409
  $post_id,
394
  $icon_class = ( $options['icon_class'] !== '' ? esc_attr( $options['icon_class'] ) : '' );
395
 
396
  // add dashicons class if needed
397
+ $icon_class = strpos( $icon_class, 'dashicons ' ) === 0 ? $icon_class : 'dashicons ' . $icon_class;
398
 
399
  // prepare icon output
400
  $icon = apply_filters( 'pvc_post_views_icon', '<span class="post-views-icon ' . $icon_class . '"></span>', $post_id );
403
  'pvc_post_views_html',
404
  '<div class="post-views post-' . $post_id . ' entry-meta">
405
  ' . ( $options['display_style']['icon'] && $icon_class !== '' ? $icon : '' ) . '
406
+ ' . ( $options['display_style']['text'] && $label !== '' ? '<span class="post-views-label">' . esc_html( $label ) . '</span>' : '' ) . '
407
  <span class="post-views-count">' . number_format_i18n( $views ) . '</span>
408
  </div>',
409
  $post_id,
includes/settings.php CHANGED
@@ -1,816 +1,839 @@
1
- <?php
2
- // exit if accessed directly
3
- if ( ! defined( 'ABSPATH' ) )
4
- exit;
5
-
6
- /**
7
- * Post_Views_Counter_Settings class.
8
- *
9
- * @class Post_Views_Counter_Settings
10
- */
11
- class Post_Views_Counter_Settings {
12
-
13
- private $tabs;
14
- private $choices;
15
- private $modes;
16
- private $time_types;
17
- private $groups;
18
- private $user_roles;
19
- private $positions;
20
- private $display_styles;
21
- public $post_types;
22
- public $page_types;
23
-
24
- public function __construct() {
25
- // actions
26
- add_action( 'admin_init', array( $this, 'register_settings' ) );
27
- add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
28
- add_action( 'after_setup_theme', array( $this, 'load_defaults' ) );
29
- add_action( 'wp_loaded', array( $this, 'load_post_types' ) );
30
- }
31
-
32
- /**
33
- * Load default settings.
34
- */
35
- public function load_defaults() {
36
- if ( ! is_admin() )
37
- return;
38
-
39
- $this->modes = array(
40
- 'php' => __( 'PHP', 'post-views-counter' ),
41
- 'js' => __( 'JavaScript', 'post-views-counter' ),
42
- 'ajax' => __( 'Fast AJAX', 'post-views-counter' )
43
- );
44
-
45
- if ( function_exists( 'register_rest_route' ) )
46
- $this->modes['rest_api'] = __( 'REST API', 'post-views-counter' );
47
-
48
- $this->time_types = array(
49
- 'minutes' => __( 'minutes', 'post-views-counter' ),
50
- 'hours' => __( 'hours', 'post-views-counter' ),
51
- 'days' => __( 'days', 'post-views-counter' ),
52
- 'weeks' => __( 'weeks', 'post-views-counter' ),
53
- 'months' => __( 'months', 'post-views-counter' ),
54
- 'years' => __( 'years', 'post-views-counter' )
55
- );
56
-
57
- $this->groups = array(
58
- 'robots' => __( 'robots', 'post-views-counter' ),
59
- 'users' => __( 'logged in users', 'post-views-counter' ),
60
- 'guests' => __( 'guests', 'post-views-counter' ),
61
- 'roles' => __( 'selected user roles', 'post-views-counter' )
62
- );
63
-
64
- $this->positions = array(
65
- 'before' => __( 'before the content', 'post-views-counter' ),
66
- 'after' => __( 'after the content', 'post-views-counter' ),
67
- 'manual' => __( 'manual', 'post-views-counter' )
68
- );
69
-
70
- $this->display_styles = array(
71
- 'icon' => __( 'icon', 'post-views-counter' ),
72
- 'text' => __( 'label', 'post-views-counter' )
73
- );
74
-
75
- $this->tabs = array(
76
- 'general' => array(
77
- 'name' => __( 'General', 'post-views-counter' ),
78
- 'key' => 'post_views_counter_settings_general',
79
- 'submit' => 'save_pvc_general',
80
- 'reset' => 'reset_pvc_general'
81
- ),
82
- 'display' => array(
83
- 'name' => __( 'Display', 'post-views-counter' ),
84
- 'key' => 'post_views_counter_settings_display',
85
- 'submit' => 'save_pvc_display',
86
- 'reset' => 'reset_pvc_display'
87
- )
88
- );
89
-
90
- $this->user_roles = $this->get_user_roles();
91
-
92
- $this->page_types = apply_filters(
93
- 'pvc_page_types_display_options',
94
- array(
95
- 'home' => __( 'Home', 'post-views-counter' ),
96
- 'archive' => __( 'Archives', 'post-views-counter' ),
97
- 'singular' => __( 'Single pages', 'post-views-counter' ),
98
- 'search' => __( 'Search results', 'post-views-counter' ),
99
- )
100
- );
101
- }
102
-
103
- /**
104
- * Get post types avaiable for counting.
105
- */
106
- public function load_post_types() {
107
- if ( ! is_admin() )
108
- return;
109
-
110
- $post_types = array();
111
-
112
- // built in public post types
113
- foreach ( get_post_types( array( '_builtin' => true, 'public' => true ), 'objects', 'and' ) as $key => $post_type ) {
114
- $post_types[$key] = $post_type->labels->name;
115
- }
116
-
117
- // public custom post types
118
- foreach ( get_post_types( array( '_builtin' => false, 'public' => true ), 'objects', 'and' ) as $key => $post_type ) {
119
- $post_types[$key] = $post_type->labels->name;
120
- }
121
-
122
- // remove bbPress replies
123
- if ( class_exists( 'bbPress' ) && isset( $post_types['reply'] ) )
124
- unset( $post_types['reply'] );
125
-
126
- $post_types = apply_filters( 'pvc_available_post_types', $post_types );
127
-
128
- // sort post types alphabetically with their keys
129
- asort( $post_types, SORT_STRING );
130
-
131
- $this->post_types = $post_types;
132
- }
133
-
134
- /**
135
- * Get all user roles.
136
- *
137
- * @global object $wp_roles
138
- * @return array
139
- */
140
- public function get_user_roles() {
141
- global $wp_roles;
142
-
143
- $roles = array();
144
-
145
- foreach ( apply_filters( 'editable_roles', $wp_roles->roles ) as $role => $details ) {
146
- $roles[$role] = translate_user_role( $details['name'] );
147
- }
148
-
149
- asort( $roles, SORT_STRING );
150
-
151
- return $roles;
152
- }
153
-
154
- /**
155
- * Add options page.
156
- *
157
- * @return void
158
- */
159
- public function admin_menu_options() {
160
- add_options_page( __( 'Post Views Counter', 'post-views-counter' ), __( 'Post Views Counter', 'post-views-counter' ), 'manage_options', 'post-views-counter', array( $this, 'options_page' ) );
161
- }
162
-
163
- /**
164
- * Options page callback.
165
- *
166
- * @return void
167
- */
168
- public function options_page() {
169
- $tab_key = (isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'general');
170
-
171
- echo '
172
- <div class="wrap">
173
- <h2>' . __( 'Post Views Counter', 'post-views-counter' ) . '</h2>
174
- <h2 class="nav-tab-wrapper">';
175
-
176
- foreach ( $this->tabs as $key => $name ) {
177
- echo '
178
- <a class="nav-tab ' . ($tab_key == $key ? 'nav-tab-active' : '') . '" href="' . esc_url( admin_url( 'options-general.php?page=post-views-counter&tab=' . $key ) ) . '">' . $name['name'] . '</a>';
179
- }
180
-
181
- echo '
182
- </h2>
183
- <div class="post-views-counter-settings">
184
- <div class="df-credits">
185
- <h3 class="hndle">' . __( 'Post Views Counter', 'post-views-counter' ) . ' ' . Post_Views_Counter()->defaults['version'] . '</h3>
186
- <div class="inside">
187
- <h4 class="inner">' . __( 'Need support?', 'post-views-counter' ) . '</h4>
188
- <p class="inner">' . sprintf( __( 'If you are having problems with this plugin, please browse it\'s <a href="%s" target="_blank">Documentation</a> or talk about them in the <a href="%s" target="_blank">Support forum</a>', 'post-views-counter' ), 'https://www.dfactory.eu/docs/post-views-counter/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=docs', 'https://www.dfactory.eu/support/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=support' ) . '</p>
189
- <hr />
190
- <h4 class="inner">' . __( 'Do you like this plugin?', 'post-views-counter' ) . '</h4>
191
- <p class="inner">' . sprintf( __( '<a href="%s" target="_blank">Rate it 5</a> on WordPress.org', 'post-views-counter' ), 'https://wordpress.org/support/plugin/post-views-counter/reviews/?filter=5' ) . '<br />' .
192
- sprintf( __( 'Blog about it & link to the <a href="%s" target="_blank">plugin page</a>.', 'post-views-counter' ), 'https://dfactory.eu/plugins/post-views-counter/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=blog-about' ) . '<br />' .
193
- sprintf( __( 'Check out our other <a href="%s" target="_blank">WordPress plugins</a>.', 'post-views-counter' ), 'https://dfactory.eu/plugins/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=other-plugins' ) . '
194
- </p>
195
- <hr />
196
- <p class="df-link inner"><a href="http://www.dfactory.eu/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="Digital Factory"><img src="//pvc-53eb.kxcdn.com/df-black-sm.png' . '" alt="Digital Factory" /></a></p>
197
- </div>
198
- </div>
199
- <form action="options.php" method="post">';
200
-
201
- wp_nonce_field( 'update-options' );
202
- settings_fields( $this->tabs[$tab_key]['key'] );
203
- do_settings_sections( $this->tabs[$tab_key]['key'] );
204
-
205
- echo '
206
- <p class="submit">';
207
-
208
- submit_button( '', 'primary', $this->tabs[$tab_key]['submit'], false );
209
-
210
- echo ' ';
211
-
212
- submit_button( __( 'Reset to defaults', 'post-views-counter' ), 'secondary reset_pvc_settings', $this->tabs[$tab_key]['reset'], false );
213
-
214
- echo '
215
- </p>
216
- </form>
217
- </div>
218
- <div class="clear"></div>
219
- </div>';
220
- }
221
-
222
- /**
223
- * Register settings callback.
224
- */
225
- public function register_settings() {
226
- // general options
227
- register_setting( 'post_views_counter_settings_general', 'post_views_counter_settings_general', array( $this, 'validate_settings' ) );
228
- add_settings_section( 'post_views_counter_settings_general', __( 'General settings', 'post-views-counter' ), '', 'post_views_counter_settings_general' );
229
- add_settings_field( 'pvc_post_types_count', __( 'Post Types Count', 'post-views-counter' ), array( $this, 'post_types_count' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
230
- add_settings_field( 'pvc_counter_mode', __( 'Counter Mode', 'post-views-counter' ), array( $this, 'counter_mode' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
231
- add_settings_field( 'pvc_post_views_column', __( 'Post Views Column', 'post-views-counter' ), array( $this, 'post_views_column' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
232
- add_settings_field( 'pvc_restrict_edit_views', __( 'Restrict Edit', 'post-views-counter' ), array( $this, 'restrict_edit_views' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
233
- add_settings_field( 'pvc_time_between_counts', __( 'Count Interval', 'post-views-counter' ), array( $this, 'time_between_counts' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
234
- add_settings_field( 'pvc_reset_counts', __( 'Reset Data Interval', 'post-views-counter' ), array( $this, 'reset_counts' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
235
- add_settings_field( 'pvc_flush_interval', __( 'Flush Object Cache Interval', 'post-views-counter' ), array( $this, 'flush_interval' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
236
- add_settings_field( 'pvc_exclude', __( 'Exclude Visitors', 'post-views-counter' ), array( $this, 'exclude' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
237
- add_settings_field( 'pvc_exclude_ips', __( 'Exclude IPs', 'post-views-counter' ), array( $this, 'exclude_ips' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
238
- add_settings_field( 'pvc_strict_counts', __( 'Strict counts', 'post-views-counter' ), array( $this, 'strict_counts' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
239
- add_settings_field( 'pvc_wp_postviews', __( 'Tools', 'post-views-counter' ), array( $this, 'wp_postviews' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
240
- add_settings_field( 'pvc_deactivation_delete', __( 'Deactivation', 'post-views-counter' ), array( $this, 'deactivation_delete' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
241
-
242
- // display options
243
- register_setting( 'post_views_counter_settings_display', 'post_views_counter_settings_display', array( $this, 'validate_settings' ) );
244
- add_settings_section( 'post_views_counter_settings_display', __( 'Display settings', 'post-views-counter' ), '', 'post_views_counter_settings_display' );
245
- add_settings_field( 'pvc_post_views_label', __( 'Post Views Label', 'post-views-counter' ), array( $this, 'post_views_label' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
246
- add_settings_field( 'pvc_post_types_display', __( 'Post Type', 'post-views-counter' ), array( $this, 'post_types_display' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
247
- add_settings_field( 'pvc_page_types_display', __( 'Page Type', 'post-views-counter' ), array( $this, 'page_types_display' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
248
- add_settings_field( 'pvc_restrict_display', __( 'User Type', 'post-views-counter' ), array( $this, 'restrict_display' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
249
- add_settings_field( 'pvc_position', __( 'Position', 'post-views-counter' ), array( $this, 'position' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
250
- add_settings_field( 'pvc_display_style', __( 'Display Style', 'post-views-counter' ), array( $this, 'display_style' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
251
- add_settings_field( 'pvc_icon_class', __( 'Icon Class', 'post-views-counter' ), array( $this, 'icon_class' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
252
- }
253
-
254
- /**
255
- * Post views label option.
256
- */
257
- public function post_views_label() {
258
- echo '
259
- <div id="pvc_post_views_label">
260
- <fieldset>
261
- <input type="text" class="large-text" name="post_views_counter_settings_display[label]" value="' . esc_attr( Post_Views_Counter()->options['display']['label'] ) . '" />
262
- <p class="description">' . __( 'Enter the label for the post views counter field.', 'post-views-counter' ) . '</p>
263
- </fieldset>
264
- </div>';
265
- }
266
-
267
- /**
268
- * Post types to count option.
269
- */
270
- public function post_types_count() {
271
- echo '
272
- <div id="pvc_post_types_count">';
273
-
274
- foreach ( $this->post_types as $post_type => $post_type_name ) {
275
- echo '
276
- <label><input id="pvc_post_types_count-' . esc_attr( $post_type ) . '" type="checkbox" name="post_views_counter_settings_general[post_types_count][' . esc_attr( $post_type ) . ']" value="1" ' . checked( in_array( $post_type, Post_Views_Counter()->options['general']['post_types_count'], true ), true, false ) . ' />' . esc_html( $post_type_name ) . ' </label>';
277
- }
278
-
279
- echo '
280
- <p class="description">' . __( 'Select post types for which post views will be counted.', 'post-views-counter' ) . '</p>
281
- </div>';
282
- }
283
-
284
- /**
285
- * Post types to display option.
286
- */
287
- public function post_types_display() {
288
- echo '
289
- <div id="pvc_post_types_display">';
290
-
291
- foreach ( $this->post_types as $post_type => $post_type_name ) {
292
- echo '
293
- <label><input id="pvc_post_types_display-' . esc_attr( $post_type ) . '" type="checkbox" name="post_views_counter_settings_display[post_types_display][' . esc_attr( $post_type ) . ']" value="1" ' . checked( in_array( $post_type, Post_Views_Counter()->options['display']['post_types_display'], true ), true, false ) . ' />' . esc_html( $post_type_name ) . '</label>';
294
- }
295
-
296
- echo '
297
- <p class="description">' . __( 'Select post types for which the views count will be displayed.', 'post-views-counter' ) . '</p>
298
- </div>';
299
- }
300
-
301
- /**
302
- * Counter mode option.
303
- */
304
- public function counter_mode() {
305
- echo '
306
- <div id="pvc_counter_mode">';
307
-
308
- foreach ( $this->modes as $key => $value ) {
309
- $key = esc_attr( $key );
310
-
311
- echo '
312
- <label><input type="radio" name="post_views_counter_settings_general[counter_mode]" value="' . $key . '" ' . checked( $key, Post_Views_Counter()->options['general']['counter_mode'], false ) . ' />' . esc_html( $value ) . '</label>';
313
- }
314
-
315
- echo '
316
- <p class="description">' . __( 'Select the method of collecting post views data. If you are using any of the caching plugins select Javascript or REST API (if available).', 'post-views-counter' ) . '<br />' . __( 'Optionally try the Fast AJAX experimental method, usually 10+ times faster than Javascript or REST API.', 'post-views-counter' ) . '</p>
317
- </div>';
318
- }
319
-
320
- /**
321
- * Post views column option.
322
- */
323
- public function post_views_column() {
324
- echo '
325
- <div id="pvc_post_views_column">
326
- <label><input id="pvc-post-views-column-enable" type="checkbox" name="post_views_counter_settings_general[post_views_column]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['post_views_column'], false ) . ' />' . __( 'Enable to display post views count column for each of the selected post types.', 'post-views-counter' ) . '</label>
327
- </div>';
328
- }
329
-
330
- /**
331
- * Time between counts option.
332
- */
333
- public function time_between_counts() {
334
- echo '
335
- <div id="pvc_time_between_counts">
336
- <input size="4" type="text" name="post_views_counter_settings_general[time_between_counts][number]" value="' . esc_attr( Post_Views_Counter()->options['general']['time_between_counts']['number'] ) . '" />
337
- <select class="pvc-chosen-short" name="post_views_counter_settings_general[time_between_counts][type]">';
338
-
339
- foreach ( $this->time_types as $type => $type_name ) {
340
- echo '
341
- <option value="' . esc_attr( $type ) . '" ' . selected( $type, Post_Views_Counter()->options['general']['time_between_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
342
- }
343
-
344
- echo '
345
- </select>
346
- <p class="description">' . __( 'Enter the time between single user visit count.', 'post-views-counter' ) . '</p>
347
- </div>';
348
- }
349
-
350
- /**
351
- * Reset counts option.
352
- */
353
- public function reset_counts() {
354
- echo '
355
- <div id="pvc_reset_counts">
356
- <input size="4" type="text" name="post_views_counter_settings_general[reset_counts][number]" value="' . esc_attr( Post_Views_Counter()->options['general']['reset_counts']['number'] ) . '" />
357
- <select class="pvc-chosen-short" name="post_views_counter_settings_general[reset_counts][type]">';
358
-
359
- foreach ( array_slice( $this->time_types, 2, null, true ) as $type => $type_name ) {
360
- echo '
361
- <option value="' . esc_attr( $type ) . '" ' . selected( $type, Post_Views_Counter()->options['general']['reset_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
362
- }
363
-
364
- echo '
365
- </select>
366
- <p class="description">' . __( 'Delete single day post views data older than specified above. Enter 0 (number zero) if you want to preserve your data regardless of its age.', 'post-views-counter' ) . '</p>
367
- </div>';
368
- }
369
-
370
- /**
371
- * Flush interval option.
372
- */
373
- public function flush_interval() {
374
- echo '
375
- <div id="pvc_flush_interval">
376
- <input size="4" type="text" name="post_views_counter_settings_general[flush_interval][number]" value="' . esc_attr( Post_Views_Counter()->options['general']['flush_interval']['number'] ) . '" />
377
- <select class="pvc-chosen-short" name="post_views_counter_settings_general[flush_interval][type]">';
378
-
379
- foreach ( $this->time_types as $type => $type_name ) {
380
- echo '
381
- <option value="' . esc_attr( $type ) . '" ' . selected( $type, Post_Views_Counter()->options['general']['flush_interval']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
382
- }
383
-
384
- echo '
385
- </select>
386
- <p class="description">' . __( 'How often to flush cached view counts from the object cache into the database. This feature is used only if a persistent object cache is detected and the interval is greater than 0 (number zero). When used, view counts will be collected and stored in the object cache instead of the database and will then be asynchronously flushed to the database according to the specified interval.<br /><strong>Notice:</strong> Potential data loss may occur if the object cache is cleared/unavailable for the duration of the interval.', 'post-views-counter' ) . '</p>
387
- </div>';
388
- }
389
-
390
- /**
391
- * Exlude user groups option.
392
- */
393
- public function exclude() {
394
- echo '
395
- <div id="pvc_exclude">
396
- <fieldset>';
397
-
398
- foreach ( $this->groups as $type => $type_name ) {
399
- echo '
400
- <label><input id="pvc_exclude-' . $type . '" type="checkbox" name="post_views_counter_settings_general[exclude][groups][' . $type . ']" value="1" ' . checked( in_array( $type, Post_Views_Counter()->options['general']['exclude']['groups'], true ), true, false ) . ' />' . esc_html( $type_name ) . '</label>';
401
- }
402
-
403
- echo '
404
- <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
405
- <div class="pvc_user_roles"' . (in_array( 'roles', Post_Views_Counter()->options['general']['exclude']['groups'], true ) ? '' : ' style="display: none;"') . '>';
406
-
407
- foreach ( $this->user_roles as $role => $role_name ) {
408
- echo '
409
- <label><input type="checkbox" name="post_views_counter_settings_general[exclude][roles][' . $role . ']" value="1" ' . checked( in_array( $role, Post_Views_Counter()->options['general']['exclude']['roles'], true ), true, false ) . '>' . esc_html( $role_name ) . '</label>';
410
- }
411
-
412
- echo ' <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
413
- </div>
414
- </fieldset>
415
- </div>';
416
- }
417
-
418
- /**
419
- * Exclude IPs option.
420
- */
421
- public function exclude_ips() {
422
- // lovely php 5.2 limitations
423
- $ips = Post_Views_Counter()->options['general']['exclude_ips'];
424
-
425
- echo '
426
- <div id="pvc_exclude_ips">';
427
-
428
- if ( ! empty( $ips ) ) {
429
- foreach ( $ips as $key => $ip ) {
430
- echo '
431
- <div class="ip-box">
432
- <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="' . esc_attr( $ip ) . '" /> <a href="#" class="remove-exclude-ip" title="' . esc_attr__( 'Remove', 'post-views-counter' ) . '">' . esc_attr__( 'Remove', 'post-views-counter' ) . '</a>
433
- </div>';
434
- }
435
- } else {
436
- echo '
437
- <div class="ip-box">
438
- <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="" /> <a href="#" class="remove-exclude-ip" title="' . esc_attr__( 'Remove', 'post-views-counter' ) . '">' . esc_attr__( 'Remove', 'post-views-counter' ) . '</a>
439
- </div>';
440
- }
441
-
442
- echo '
443
- <p><input type="button" class="button button-secondary add-exclude-ip" value="' . esc_attr__( 'Add new', 'post-views-counter' ) . '" /> <input type="button" class="button button-secondary add-current-ip" value="' . esc_attr__( 'Add my current IP', 'post-views-counter' ) . '" data-rel="' . esc_attr( $_SERVER['REMOTE_ADDR'] ) . '" /></p>
444
- <p class="description">' . __( 'Enter the IP addresses to be excluded from post views count.', 'post-views-counter' ) . '</p>
445
- </div>';
446
- }
447
-
448
- /**
449
- * Strict counts option.
450
- */
451
- public function strict_counts() {
452
- echo '
453
- <div id="pvc_strict_counts">
454
- <label><input id="pvc-strict-counts" type="checkbox" name="post_views_counter_settings_general[strict_counts]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['strict_counts'], false ) . ' />' . __( 'Enable to prevent bypassing the counts interval (for e.g. using incognito browser window or by clearing cookies).', 'post-views-counter' ) . '</label>
455
- </div>';
456
- }
457
-
458
- /**
459
- * WP-PostViews import option.
460
- */
461
- public function wp_postviews() {
462
- echo '
463
- <div id="pvc_wp_postviews">
464
- <fieldset>
465
- <input type="submit" class="button button-secondary" name="post_views_counter_import_wp_postviews" value="' . __( 'Import views', 'post-views-counter' ) . '"/> <label><input id="pvc-wp-postviews" type="checkbox" name="post_views_counter_import_wp_postviews_override" value="1" />' . __( 'Override existing views data.', 'post-views-counter' ) . '</label>
466
- <p class="description">' . __( 'Import post views data from WP-PostViews plugin.', 'post-views-counter' ) . '</p>
467
- <input type="submit" class="button button-secondary" name="post_views_counter_reset_views" value="' . __( 'Delete views', 'post-views-counter' ) . '"/>
468
- <p class="description">' . __( 'Delete ALL the existing post views data.', 'post-views-counter' ) . '</p>
469
- </fieldset>
470
- </div>';
471
- }
472
-
473
- /**
474
- * Limit views edit to admins.
475
- */
476
- public function restrict_edit_views() {
477
- echo '
478
- <div id="pvc_restrict_edit_views">
479
- <label><input type="checkbox" name="post_views_counter_settings_general[restrict_edit_views]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['restrict_edit_views'], false ) . ' />' . __( 'Enable to restrict post views editing to admins only.', 'post-views-counter' ) . '</label>
480
- </div>';
481
- }
482
-
483
- /**
484
- * Plugin deactivation option.
485
- */
486
- public function deactivation_delete() {
487
- echo '
488
- <div id="pvc_deactivation_delete">
489
- <label><input type="checkbox" name="post_views_counter_settings_general[deactivation_delete]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['deactivation_delete'], false ) . ' />' . __( 'Enable to delete all plugin data on deactivation.', 'post-views-counter' ) . '</label>
490
- </div>';
491
- }
492
-
493
- /**
494
- * Visibility option.
495
- */
496
- public function page_types_display() {
497
- echo '
498
- <div id="pvc_post_types_display">';
499
-
500
- foreach ( $this->page_types as $key => $label ) {
501
- echo '
502
- <label><input id="pvc_page_types_display-' . esc_attr( $key ) . '" type="checkbox" name="post_views_counter_settings_display[page_types_display][' . esc_attr( $key ) . ']" value="1" ' . checked( in_array( $key, Post_Views_Counter()->options['display']['page_types_display'], true ), true, false ) . ' />' . esc_html( $label ) . '</label>';
503
- }
504
-
505
- echo '
506
- <p class="description">' . __( 'Select page types where the views count will be displayed.', 'post-views-counter' ) . '</p>
507
- </div>';
508
- }
509
-
510
- /**
511
- * Counter position option.
512
- */
513
- public function position() {
514
- echo '
515
- <div id="pvc_position">
516
- <select class="pvc-chosen-short" name="post_views_counter_settings_display[position]">';
517
-
518
- foreach ( $this->positions as $position => $position_name ) {
519
- echo '
520
- <option value="' . esc_attr( $position ) . '" ' . selected( $position, Post_Views_Counter()->options['display']['position'], false ) . '>' . esc_html( $position_name ) . '</option>';
521
- }
522
-
523
- echo '
524
- </select>
525
- <p class="description">' . __( 'Select where would you like to display the post views counter. Use [post-views] shortcode for manual display.', 'post-views-counter' ) . '</p>
526
- </div>';
527
- }
528
-
529
- /**
530
- * Counter style option.
531
- */
532
- public function display_style() {
533
- echo '
534
- <div id="pvc_display_style">';
535
-
536
- foreach ( $this->display_styles as $display => $style ) {
537
- $display = esc_attr( $display );
538
-
539
- echo '
540
- <label><input type="checkbox" name="post_views_counter_settings_display[display_style][' . $display . ']" value="1" ' . checked( true, Post_Views_Counter()->options['display']['display_style'][$display], false ) . ' />' . esc_html( $style ) . '</label>';
541
- }
542
-
543
- echo '
544
- <p class="description">' . __( 'Choose how to display the post views counter.', 'post-views-counter' ) . '</p>
545
- </div>';
546
- }
547
-
548
- /**
549
- * Counter icon class option.
550
- */
551
- public function icon_class() {
552
- echo '
553
- <div id="pvc_icon_class">
554
- <input type="text" name="post_views_counter_settings_display[icon_class]" class="large-text" value="' . esc_attr( Post_Views_Counter()->options['display']['icon_class'] ) . '" />
555
- <p class="description">' . sprintf( __( 'Enter the post views icon class. Any of the <a href="%s" target="_blank">Dashicons</a> classes are available.', 'post-views-counter' ), 'https://developer.wordpress.org/resource/dashicons/' ) . '</p>
556
- </div>';
557
- }
558
-
559
- /**
560
- * Restrict display option.
561
- */
562
- public function restrict_display() {
563
- echo '
564
- <div id="pvc_restrict_display">
565
- <fieldset>';
566
-
567
- foreach ( $this->groups as $type => $type_name ) {
568
-
569
- if ( $type === 'robots' )
570
- continue;
571
-
572
- echo '
573
- <label><input id="pvc_restrict_display-' . $type . '" type="checkbox" name="post_views_counter_settings_display[restrict_display][groups][' . esc_html( $type ) . ']" value="1" ' . checked( in_array( $type, Post_Views_Counter()->options['display']['restrict_display']['groups'], true ), true, false ) . ' />' . esc_html( $type_name ) . '</label>';
574
- }
575
-
576
- echo '
577
- <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
578
- <div class="pvc_user_roles"' . (in_array( 'roles', Post_Views_Counter()->options['display']['restrict_display']['groups'], true ) ? '' : ' style="display: none;"') . '>';
579
-
580
- foreach ( $this->user_roles as $role => $role_name ) {
581
- echo '
582
- <label><input type="checkbox" name="post_views_counter_settings_display[restrict_display][roles][' . $role . ']" value="1" ' . checked( in_array( $role, Post_Views_Counter()->options['display']['restrict_display']['roles'], true ), true, false ) . ' />' . esc_html( $role_name ) . '</label>';
583
- }
584
-
585
- echo '
586
- <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
587
- </div>
588
- </fieldset>
589
- </div>';
590
- }
591
-
592
- /**
593
- * Validate general settings.
594
- */
595
- public function validate_settings( $input ) {
596
- // get main instance
597
- $pvc = Post_Views_Counter();
598
-
599
- if ( isset( $_POST['post_views_counter_import_wp_postviews'] ) ) {
600
- global $wpdb;
601
-
602
- $meta_key = esc_attr( apply_filters( 'pvc_import_meta_key', 'views' ) );
603
-
604
- $views = $wpdb->get_results( "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '" . $meta_key . "'", ARRAY_A, 0 );
605
-
606
- if ( ! empty( $views ) ) {
607
- $input = $pvc->defaults['general'];
608
- $input['wp_postviews_import'] = true;
609
-
610
- $sql = array();
611
-
612
- foreach ( $views as $view ) {
613
- $sql[] = "(" . $view['post_id'] . ", 4, 'total', " . $view['meta_value'] . ")";
614
- }
615
-
616
- $wpdb->query( "INSERT INTO " . $wpdb->prefix . "post_views(id, type, period, count) VALUES " . implode( ',', $sql ) . " ON DUPLICATE KEY UPDATE count = " . (isset( $_POST['post_views_counter_import_wp_postviews_override'] ) ? '' : 'count + ') . "VALUES(count)" );
617
-
618
- add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'Post views data imported succesfully.', 'post-views-counter' ), 'updated' );
619
- } else {
620
- add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'There was no post views data to import.', 'post-views-counter' ), 'updated' );
621
- }
622
- } elseif ( isset( $_POST['post_views_counter_reset_views'] ) ) {
623
- global $wpdb;
624
-
625
- if ( $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . 'post_views' ) )
626
- add_settings_error( 'reset_post_views', 'reset_post_views', __( 'All existing data deleted succesfully.', 'post-views-counter' ), 'updated' );
627
- else
628
- add_settings_error( 'reset_post_views', 'reset_post_views', __( 'Error occurred. All existing data were not deleted.', 'post-views-counter' ), 'error' );
629
- } elseif ( isset( $_POST['save_pvc_general'] ) ) {
630
- // post types count
631
- if ( isset( $input['post_types_count'] ) ) {
632
- $post_types = array();
633
-
634
- foreach ( $input['post_types_count'] as $post_type => $set ) {
635
- if ( isset( $this->post_types[$post_type] ) )
636
- $post_types[] = $post_type;
637
- }
638
-
639
- $input['post_types_count'] = array_unique( $post_types );
640
- } else
641
- $input['post_types_count'] = array();
642
-
643
- // counter mode
644
- $input['counter_mode'] = isset( $input['counter_mode'], $this->modes[$input['counter_mode']] ) ? $input['counter_mode'] : $pvc->defaults['general']['counter_mode'];
645
-
646
- // post views column
647
- $input['post_views_column'] = isset( $input['post_views_column'] );
648
-
649
- // time between counts
650
- $input['time_between_counts']['number'] = (int) ( isset( $input['time_between_counts']['number'] ) ? $input['time_between_counts']['number'] : $pvc->defaults['general']['time_between_counts']['number'] );
651
- $input['time_between_counts']['type'] = isset( $input['time_between_counts']['type'], $this->time_types[$input['time_between_counts']['type']] ) ? $input['time_between_counts']['type'] : $pvc->defaults['general']['time_between_counts']['type'];
652
-
653
- // flush interval
654
- $input['flush_interval']['number'] = (int) ( isset( $input['flush_interval']['number'] ) ? $input['flush_interval']['number'] : $pvc->defaults['general']['flush_interval']['number'] );
655
- $input['flush_interval']['type'] = isset( $input['flush_interval']['type'], $this->time_types[$input['flush_interval']['type']] ) ? $input['flush_interval']['type'] : $pvc->defaults['general']['flush_interval']['type'];
656
-
657
- // Since the settings are about to be saved and cache flush interval could've changed,
658
- // we want to make sure that any changes done on the settings page are in effect immediately
659
- // (instead of having to wait for the previous schedule to occur).
660
- // We achieve that by making sure to clear any previous cache flush schedules and
661
- // schedule the new one if the specified interval is > 0
662
- $pvc->remove_cache_flush();
663
-
664
- if ( $input['flush_interval']['number'] > 0 ) {
665
- $pvc->schedule_cache_flush();
666
- }
667
-
668
- // reset counts
669
- $input['reset_counts']['number'] = (int) ( isset( $input['reset_counts']['number'] ) ? $input['reset_counts']['number'] : $pvc->defaults['general']['reset_counts']['number'] );
670
- $input['reset_counts']['type'] = isset( $input['reset_counts']['type'], $this->time_types[$input['reset_counts']['type']] ) ? $input['reset_counts']['type'] : $pvc->defaults['general']['reset_counts']['type'];
671
-
672
- // run cron on next visit?
673
- $input['cron_run'] = ($input['reset_counts']['number'] > 0 ? true : false);
674
- $input['cron_update'] = ($input['cron_run'] && ( $pvc->options['general']['reset_counts']['number'] !== $input['reset_counts']['number'] || $pvc->options['general']['reset_counts']['type'] !== $input['reset_counts']['type'] ) ? true : false);
675
-
676
- // exclude
677
- if ( isset( $input['exclude']['groups'] ) ) {
678
- $groups = array();
679
-
680
- foreach ( $input['exclude']['groups'] as $group => $set ) {
681
- if ( isset( $this->groups[$group] ) )
682
- $groups[] = $group;
683
- }
684
-
685
- $input['exclude']['groups'] = array_unique( $groups );
686
- } else {
687
- $input['exclude']['groups'] = array();
688
- }
689
-
690
- if ( in_array( 'roles', $input['exclude']['groups'], true ) && isset( $input['exclude']['roles'] ) ) {
691
- $roles = array();
692
-
693
- foreach ( $input['exclude']['roles'] as $role => $set ) {
694
- if ( isset( $this->user_roles[$role] ) )
695
- $roles[] = $role;
696
- }
697
-
698
- $input['exclude']['roles'] = array_unique( $roles );
699
- } else
700
- $input['exclude']['roles'] = array();
701
-
702
- // exclude ips
703
- if ( isset( $input['exclude_ips'] ) ) {
704
- $ips = array();
705
-
706
- foreach ( $input['exclude_ips'] as $ip ) {
707
- if ( strpos( $ip, '*' ) !== false ) {
708
- $new_ip = str_replace( '*', '0', $ip );
709
-
710
- if ( filter_var( $new_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
711
- $ips[] = $ip;
712
- } elseif ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
713
- $ips[] = $ip;
714
- }
715
-
716
- $input['exclude_ips'] = array_unique( $ips );
717
- }
718
-
719
- // restrict edit views
720
- $input['restrict_edit_views'] = isset( $input['restrict_edit_views'] );
721
-
722
- // strict counts
723
- $input['strict_counts'] = isset( $input['strict_counts'] );
724
-
725
- // deactivation delete
726
- $input['deactivation_delete'] = isset( $input['deactivation_delete'] );
727
-
728
- $input['update_version'] = $pvc->options['general']['update_version'];
729
- $input['update_notice'] = $pvc->options['general']['update_notice'];
730
- } elseif ( isset( $_POST['save_pvc_display'] ) ) {
731
-
732
- // post views label
733
- $input['label'] = isset( $input['label'] ) ? $input['label'] : $pvc->defaults['general']['label'];
734
-
735
- if ( function_exists( 'icl_register_string' ) )
736
- icl_register_string( 'Post Views Counter', 'Post Views Label', $input['label'] );
737
-
738
- // position
739
- $input['position'] = isset( $input['position'], $this->positions[$input['position']] ) ? $input['position'] : $pvc->defaults['general']['position'];
740
-
741
- // display style
742
- $input['display_style']['icon'] = isset( $input['display_style']['icon'] );
743
- $input['display_style']['text'] = isset( $input['display_style']['text'] );
744
-
745
- // link to post
746
- $input['link_to_post'] = isset( $input['link_to_post'] ) ? $input['link_to_post'] : $pvc->defaults['display']['link_to_post'];
747
-
748
- // icon class
749
- $input['icon_class'] = isset( $input['icon_class'] ) ? trim( $input['icon_class'] ) : $pvc->defaults['general']['icon_class'];
750
-
751
- // post types display
752
- if ( isset( $input['post_types_display'] ) ) {
753
- $post_types = array();
754
-
755
- foreach ( $input['post_types_display'] as $post_type => $set ) {
756
- if ( isset( $this->post_types[$post_type] ) )
757
- $post_types[] = $post_type;
758
- }
759
-
760
- $input['post_types_display'] = array_unique( $post_types );
761
- } else
762
- $input['post_types_display'] = array();
763
-
764
- // page types display
765
- if ( isset( $input['page_types_display'] ) ) {
766
- $page_types = array();
767
-
768
- foreach ( $input['page_types_display'] as $page_type => $set ) {
769
- if ( isset( $this->page_types[$page_type] ) )
770
- $page_types[] = $page_type;
771
- }
772
-
773
- $input['page_types_display'] = array_unique( $page_types );
774
- } else
775
- $input['page_types_display'] = array();
776
-
777
- // restrict display
778
- if ( isset( $input['restrict_display']['groups'] ) ) {
779
- $groups = array();
780
-
781
- foreach ( $input['restrict_display']['groups'] as $group => $set ) {
782
- if ( $group === 'robots' )
783
- continue;
784
-
785
- if ( isset( $this->groups[$group] ) )
786
- $groups[] = $group;
787
- }
788
-
789
- $input['restrict_display']['groups'] = array_unique( $groups );
790
- } else
791
- $input['restrict_display']['groups'] = array();
792
-
793
- if ( in_array( 'roles', $input['restrict_display']['groups'], true ) && isset( $input['restrict_display']['roles'] ) ) {
794
- $roles = array();
795
-
796
- foreach ( $input['restrict_display']['roles'] as $role => $set ) {
797
- if ( isset( $this->user_roles[$role] ) )
798
- $roles[] = $role;
799
- }
800
-
801
- $input['restrict_display']['roles'] = array_unique( $roles );
802
- } else
803
- $input['restrict_display']['roles'] = array();
804
- } elseif ( isset( $_POST['reset_pvc_general'] ) ) {
805
- $input = $pvc->defaults['general'];
806
-
807
- add_settings_error( 'reset_general_settings', 'settings_reset', __( 'General settings restored to defaults.', 'post-views-counter' ), 'updated' );
808
- } elseif ( isset( $_POST['reset_pvc_display'] ) ) {
809
- $input = $pvc->defaults['display'];
810
-
811
- add_settings_error( 'reset_general_settings', 'settings_reset', __( 'Display settings restored to defaults.', 'post-views-counter' ), 'updated' );
812
- }
813
-
814
- return $input;
815
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
816
  }
1
+ <?php
2
+ // exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) )
4
+ exit;
5
+
6
+ /**
7
+ * Post_Views_Counter_Settings class.
8
+ *
9
+ * @class Post_Views_Counter_Settings
10
+ */
11
+ class Post_Views_Counter_Settings {
12
+
13
+ private $tabs;
14
+ private $choices;
15
+ private $modes;
16
+ private $time_types;
17
+ private $groups;
18
+ private $user_roles;
19
+ private $positions;
20
+ private $display_styles;
21
+ public $post_types;
22
+ public $page_types;
23
+
24
+ public function __construct() {
25
+ // actions
26
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
27
+ add_action( 'admin_menu', array( $this, 'admin_menu_options' ) );
28
+ add_action( 'after_setup_theme', array( $this, 'load_defaults' ) );
29
+ add_action( 'wp_loaded', array( $this, 'load_post_types' ) );
30
+ }
31
+
32
+ /**
33
+ * Load default settings.
34
+ */
35
+ public function load_defaults() {
36
+ if ( ! is_admin() )
37
+ return;
38
+
39
+ $this->modes = array(
40
+ 'php' => __( 'PHP', 'post-views-counter' ),
41
+ 'js' => __( 'JavaScript', 'post-views-counter' ),
42
+ 'ajax' => __( 'Fast AJAX', 'post-views-counter' )
43
+ );
44
+
45
+ if ( function_exists( 'register_rest_route' ) )
46
+ $this->modes['rest_api'] = __( 'REST API', 'post-views-counter' );
47
+
48
+ $this->time_types = array(
49
+ 'minutes' => __( 'minutes', 'post-views-counter' ),
50
+ 'hours' => __( 'hours', 'post-views-counter' ),
51
+ 'days' => __( 'days', 'post-views-counter' ),
52
+ 'weeks' => __( 'weeks', 'post-views-counter' ),
53
+ 'months' => __( 'months', 'post-views-counter' ),
54
+ 'years' => __( 'years', 'post-views-counter' )
55
+ );
56
+
57
+ $this->groups = array(
58
+ 'robots' => __( 'robots', 'post-views-counter' ),
59
+ 'users' => __( 'logged in users', 'post-views-counter' ),
60
+ 'guests' => __( 'guests', 'post-views-counter' ),
61
+ 'roles' => __( 'selected user roles', 'post-views-counter' )
62
+ );
63
+
64
+ $this->positions = array(
65
+ 'before' => __( 'before the content', 'post-views-counter' ),
66
+ 'after' => __( 'after the content', 'post-views-counter' ),
67
+ 'manual' => __( 'manual', 'post-views-counter' )
68
+ );
69
+
70
+ $this->display_styles = array(
71
+ 'icon' => __( 'icon', 'post-views-counter' ),
72
+ 'text' => __( 'label', 'post-views-counter' )
73
+ );
74
+
75
+ $this->tabs = array(
76
+ 'general' => array(
77
+ 'name' => __( 'General', 'post-views-counter' ),
78
+ 'key' => 'post_views_counter_settings_general',
79
+ 'submit' => 'save_pvc_general',
80
+ 'reset' => 'reset_pvc_general'
81
+ ),
82
+ 'display' => array(
83
+ 'name' => __( 'Display', 'post-views-counter' ),
84
+ 'key' => 'post_views_counter_settings_display',
85
+ 'submit' => 'save_pvc_display',
86
+ 'reset' => 'reset_pvc_display'
87
+ )
88
+ );
89
+
90
+ $this->user_roles = $this->get_user_roles();
91
+
92
+ $this->page_types = apply_filters(
93
+ 'pvc_page_types_display_options',
94
+ array(
95
+ 'home' => __( 'Home', 'post-views-counter' ),
96
+ 'archive' => __( 'Archives', 'post-views-counter' ),
97
+ 'singular' => __( 'Single pages', 'post-views-counter' ),
98
+ 'search' => __( 'Search results', 'post-views-counter' ),
99
+ )
100
+ );
101
+ }
102
+
103
+ /**
104
+ * Get post types avaiable for counting.
105
+ */
106
+ public function load_post_types() {
107
+ if ( ! is_admin() )
108
+ return;
109
+
110
+ $post_types = array();
111
+
112
+ // built in public post types
113
+ foreach ( get_post_types( array( '_builtin' => true, 'public' => true ), 'objects', 'and' ) as $key => $post_type ) {
114
+ $post_types[$key] = $post_type->labels->name;
115
+ }
116
+
117
+ // public custom post types
118
+ foreach ( get_post_types( array( '_builtin' => false, 'public' => true ), 'objects', 'and' ) as $key => $post_type ) {
119
+ $post_types[$key] = $post_type->labels->name;
120
+ }
121
+
122
+ // remove bbPress replies
123
+ if ( class_exists( 'bbPress' ) && isset( $post_types['reply'] ) )
124
+ unset( $post_types['reply'] );
125
+
126
+ $post_types = apply_filters( 'pvc_available_post_types', $post_types );
127
+
128
+ // sort post types alphabetically with their keys
129
+ asort( $post_types, SORT_STRING );
130
+
131
+ $this->post_types = $post_types;
132
+ }
133
+
134
+ /**
135
+ * Get all user roles.
136
+ *
137
+ * @global object $wp_roles
138
+ * @return array
139
+ */
140
+ public function get_user_roles() {
141
+ global $wp_roles;
142
+
143
+ $roles = array();
144
+
145
+ foreach ( apply_filters( 'editable_roles', $wp_roles->roles ) as $role => $details ) {
146
+ $roles[$role] = translate_user_role( $details['name'] );
147
+ }
148
+
149
+ asort( $roles, SORT_STRING );
150
+
151
+ return $roles;
152
+ }
153
+
154
+ /**
155
+ * Add options page.
156
+ *
157
+ * @return void
158
+ */
159
+ public function admin_menu_options() {
160
+ add_options_page( __( 'Post Views Counter', 'post-views-counter' ), __( 'Post Views Counter', 'post-views-counter' ), 'manage_options', 'post-views-counter', array( $this, 'options_page' ) );
161
+ }
162
+
163
+ /**
164
+ * Options page callback.
165
+ *
166
+ * @return void
167
+ */
168
+ public function options_page() {
169
+ $tab_key = (isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : 'general');
170
+
171
+ echo '
172
+ <div class="wrap">
173
+ <h2>' . __( 'Post Views Counter', 'post-views-counter' ) . '</h2>
174
+ <h2 class="nav-tab-wrapper">';
175
+
176
+ foreach ( $this->tabs as $key => $name ) {
177
+ echo '
178
+ <a class="nav-tab ' . ($tab_key == $key ? 'nav-tab-active' : '') . '" href="' . esc_url( admin_url( 'options-general.php?page=post-views-counter&tab=' . $key ) ) . '">' . $name['name'] . '</a>';
179
+ }
180
+
181
+ echo '
182
+ </h2>
183
+ <div class="post-views-counter-settings">
184
+ <div class="df-credits">
185
+ <h3 class="hndle">' . __( 'Post Views Counter', 'post-views-counter' ) . ' ' . Post_Views_Counter()->defaults['version'] . '</h3>
186
+ <div class="inside">
187
+ <h4 class="inner">' . __( 'Need support?', 'post-views-counter' ) . '</h4>
188
+ <p class="inner">' . sprintf( __( 'If you are having problems with this plugin, please browse it\'s <a href="%s" target="_blank">Documentation</a> or talk about them in the <a href="%s" target="_blank">Support forum</a>', 'post-views-counter' ), 'https://www.dfactory.eu/docs/post-views-counter/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=docs', 'https://www.dfactory.eu/support/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=support' ) . '</p>
189
+ <hr />
190
+ <h4 class="inner">' . __( 'Do you like this plugin?', 'post-views-counter' ) . '</h4>
191
+ <p class="inner">' . sprintf( __( '<a href="%s" target="_blank">Rate it 5</a> on WordPress.org', 'post-views-counter' ), 'https://wordpress.org/support/plugin/post-views-counter/reviews/?filter=5' ) . '<br />' .
192
+ sprintf( __( 'Blog about it & link to the <a href="%s" target="_blank">plugin page</a>.', 'post-views-counter' ), 'https://dfactory.eu/plugins/post-views-counter/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=blog-about' ) . '<br />' .
193
+ sprintf( __( 'Check out our other <a href="%s" target="_blank">WordPress plugins</a>.', 'post-views-counter' ), 'https://dfactory.eu/plugins/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=other-plugins' ) . '
194
+ </p>
195
+ <hr />
196
+ <p class="df-link inner"><a href="http://www.dfactory.eu/?utm_source=post-views-counter-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="Digital Factory"><img src="//pvc-53eb.kxcdn.com/df-black-sm.png' . '" alt="Digital Factory" /></a></p>
197
+ </div>
198
+ </div>
199
+ <form action="options.php" method="post">';
200
+
201
+ wp_nonce_field( 'update-options' );
202
+ settings_fields( $this->tabs[$tab_key]['key'] );
203
+ do_settings_sections( $this->tabs[$tab_key]['key'] );
204
+
205
+ echo '
206
+ <p class="submit">';
207
+
208
+ submit_button( '', 'primary', $this->tabs[$tab_key]['submit'], false );
209
+
210
+ echo ' ';
211
+
212
+ submit_button( __( 'Reset to defaults', 'post-views-counter' ), 'secondary reset_pvc_settings', $this->tabs[$tab_key]['reset'], false );
213
+
214
+ echo '
215
+ </p>
216
+ </form>
217
+ </div>
218
+ <div class="clear"></div>
219
+ </div>';
220
+ }
221
+
222
+ /**
223
+ * Register settings callback.
224
+ */
225
+ public function register_settings() {
226
+ // general options
227
+ register_setting( 'post_views_counter_settings_general', 'post_views_counter_settings_general', array( $this, 'validate_settings' ) );
228
+ add_settings_section( 'post_views_counter_settings_general', __( 'General settings', 'post-views-counter' ), '', 'post_views_counter_settings_general' );
229
+ add_settings_field( 'pvc_post_types_count', __( 'Post Types Count', 'post-views-counter' ), array( $this, 'post_types_count' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
230
+ add_settings_field( 'pvc_counter_mode', __( 'Counter Mode', 'post-views-counter' ), array( $this, 'counter_mode' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
231
+ add_settings_field( 'pvc_post_views_column', __( 'Post Views Column', 'post-views-counter' ), array( $this, 'post_views_column' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
232
+ add_settings_field( 'pvc_restrict_edit_views', __( 'Restrict Edit', 'post-views-counter' ), array( $this, 'restrict_edit_views' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
233
+ add_settings_field( 'pvc_time_between_counts', __( 'Count Interval', 'post-views-counter' ), array( $this, 'time_between_counts' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
234
+ add_settings_field( 'pvc_reset_counts', __( 'Reset Data Interval', 'post-views-counter' ), array( $this, 'reset_counts' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
235
+ add_settings_field( 'pvc_flush_interval', __( 'Flush Object Cache Interval', 'post-views-counter' ), array( $this, 'flush_interval' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
236
+ add_settings_field( 'pvc_exclude', __( 'Exclude Visitors', 'post-views-counter' ), array( $this, 'exclude' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
237
+ add_settings_field( 'pvc_exclude_ips', __( 'Exclude IPs', 'post-views-counter' ), array( $this, 'exclude_ips' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
238
+ add_settings_field( 'pvc_strict_counts', __( 'Strict counts', 'post-views-counter' ), array( $this, 'strict_counts' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
239
+ add_settings_field( 'pvc_wp_postviews', __( 'Tools', 'post-views-counter' ), array( $this, 'wp_postviews' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
240
+ add_settings_field( 'pvc_deactivation_delete', __( 'Deactivation', 'post-views-counter' ), array( $this, 'deactivation_delete' ), 'post_views_counter_settings_general', 'post_views_counter_settings_general' );
241
+
242
+ // display options
243
+ register_setting( 'post_views_counter_settings_display', 'post_views_counter_settings_display', array( $this, 'validate_settings' ) );
244
+ add_settings_section( 'post_views_counter_settings_display', __( 'Display settings', 'post-views-counter' ), '', 'post_views_counter_settings_display' );
245
+ add_settings_field( 'pvc_post_views_label', __( 'Post Views Label', 'post-views-counter' ), array( $this, 'post_views_label' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
246
+ add_settings_field( 'pvc_post_types_display', __( 'Post Type', 'post-views-counter' ), array( $this, 'post_types_display' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
247
+ add_settings_field( 'pvc_page_types_display', __( 'Page Type', 'post-views-counter' ), array( $this, 'page_types_display' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
248
+ add_settings_field( 'pvc_restrict_display', __( 'User Type', 'post-views-counter' ), array( $this, 'restrict_display' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
249
+ add_settings_field( 'pvc_position', __( 'Position', 'post-views-counter' ), array( $this, 'position' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
250
+ add_settings_field( 'pvc_display_style', __( 'Display Style', 'post-views-counter' ), array( $this, 'display_style' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
251
+ add_settings_field( 'pvc_icon_class', __( 'Icon Class', 'post-views-counter' ), array( $this, 'icon_class' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
252
+ add_settings_field( 'pvc_toolbar_statistics', __( 'Toolbar Chart', 'post-views-counter' ), array( $this, 'toolbar_statistics' ), 'post_views_counter_settings_display', 'post_views_counter_settings_display' );
253
+ }
254
+
255
+ /**
256
+ * Post views label option.
257
+ */
258
+ public function post_views_label() {
259
+ echo '
260
+ <div id="pvc_post_views_label">
261
+ <fieldset>
262
+ <input type="text" class="large-text" name="post_views_counter_settings_display[label]" value="' . esc_attr( Post_Views_Counter()->options['display']['label'] ) . '" />
263
+ <p class="description">' . __( 'Enter the label for the post views counter field.', 'post-views-counter' ) . '</p>
264
+ </fieldset>
265
+ </div>';
266
+ }
267
+
268
+ /**
269
+ * Post types to count option.
270
+ */
271
+ public function post_types_count() {
272
+ echo '
273
+ <div id="pvc_post_types_count">';
274
+
275
+ foreach ( $this->post_types as $post_type => $post_type_name ) {
276
+ echo '
277
+ <label><input id="pvc_post_types_count-' . esc_attr( $post_type ) . '" type="checkbox" name="post_views_counter_settings_general[post_types_count][' . esc_attr( $post_type ) . ']" value="1" ' . checked( in_array( $post_type, Post_Views_Counter()->options['general']['post_types_count'], true ), true, false ) . ' />' . esc_html( $post_type_name ) . ' </label>';
278
+ }
279
+
280
+ echo '
281
+ <p class="description">' . __( 'Select post types for which post views will be counted.', 'post-views-counter' ) . '</p>
282
+ </div>';
283
+ }
284
+
285
+ /**
286
+ * Post types to display option.
287
+ */
288
+ public function post_types_display() {
289
+ echo '
290
+ <div id="pvc_post_types_display">';
291
+
292
+ foreach ( $this->post_types as $post_type => $post_type_name ) {
293
+ echo '
294
+ <label><input id="pvc_post_types_display-' . esc_attr( $post_type ) . '" type="checkbox" name="post_views_counter_settings_display[post_types_display][' . esc_attr( $post_type ) . ']" value="1" ' . checked( in_array( $post_type, Post_Views_Counter()->options['display']['post_types_display'], true ), true, false ) . ' />' . esc_html( $post_type_name ) . '</label>';
295
+ }
296
+
297
+ echo '
298
+ <p class="description">' . __( 'Select post types for which the views count will be displayed.', 'post-views-counter' ) . '</p>
299
+ </div>';
300
+ }
301
+
302
+ /**
303
+ * Counter mode option.
304
+ */
305
+ public function counter_mode() {
306
+ echo '
307
+ <div id="pvc_counter_mode">';
308
+
309
+ foreach ( $this->modes as $key => $value ) {
310
+ $key = esc_attr( $key );
311
+
312
+ echo '
313
+ <label><input type="radio" name="post_views_counter_settings_general[counter_mode]" value="' . $key . '" ' . checked( $key, Post_Views_Counter()->options['general']['counter_mode'], false ) . ' />' . esc_html( $value ) . '</label>';
314
+ }
315
+
316
+ echo '
317
+ <p class="description">' . __( 'Select the method of collecting post views data. If you are using any of the caching plugins select Javascript or REST API (if available).', 'post-views-counter' ) . '<br />' . __( 'Optionally try the Fast AJAX experimental method, usually 10+ times faster than Javascript or REST API.', 'post-views-counter' ) . '</p>
318
+ </div>';
319
+ }
320
+
321
+ /**
322
+ * Post views column option.
323
+ */
324
+ public function post_views_column() {
325
+ echo '
326
+ <div id="pvc_post_views_column">
327
+ <label><input id="pvc-post-views-column-enable" type="checkbox" name="post_views_counter_settings_general[post_views_column]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['post_views_column'], false ) . ' />' . __( 'Enable to display post views count column for each of the selected post types.', 'post-views-counter' ) . '</label>
328
+ </div>';
329
+ }
330
+
331
+ /**
332
+ * Time between counts option.
333
+ */
334
+ public function time_between_counts() {
335
+ echo '
336
+ <div id="pvc_time_between_counts">
337
+ <input size="4" type="text" name="post_views_counter_settings_general[time_between_counts][number]" value="' . esc_attr( Post_Views_Counter()->options['general']['time_between_counts']['number'] ) . '" />
338
+ <select class="pvc-chosen-short" name="post_views_counter_settings_general[time_between_counts][type]">';
339
+
340
+ foreach ( $this->time_types as $type => $type_name ) {
341
+ echo '
342
+ <option value="' . esc_attr( $type ) . '" ' . selected( $type, Post_Views_Counter()->options['general']['time_between_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
343
+ }
344
+
345
+ echo '
346
+ </select>
347
+ <p class="description">' . __( 'Enter the time between single user visit count.', 'post-views-counter' ) . '</p>
348
+ </div>';
349
+ }
350
+
351
+ /**
352
+ * Reset counts option.
353
+ */
354
+ public function reset_counts() {
355
+ echo '
356
+ <div id="pvc_reset_counts">
357
+ <input size="4" type="text" name="post_views_counter_settings_general[reset_counts][number]" value="' . esc_attr( Post_Views_Counter()->options['general']['reset_counts']['number'] ) . '" />
358
+ <select class="pvc-chosen-short" name="post_views_counter_settings_general[reset_counts][type]">';
359
+
360
+ foreach ( array_slice( $this->time_types, 2, null, true ) as $type => $type_name ) {
361
+ echo '
362
+ <option value="' . esc_attr( $type ) . '" ' . selected( $type, Post_Views_Counter()->options['general']['reset_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
363
+ }
364
+
365
+ echo '
366
+ </select>
367
+ <p class="description">' . __( 'Delete single day post views data older than specified above. Enter 0 (number zero) if you want to preserve your data regardless of its age.', 'post-views-counter' ) . '</p>
368
+ </div>';
369
+ }
370
+
371
+ /**
372
+ * Flush interval option.
373
+ */
374
+ public function flush_interval() {
375
+ echo '
376
+ <div id="pvc_flush_interval">
377
+ <input size="4" type="text" name="post_views_counter_settings_general[flush_interval][number]" value="' . esc_attr( Post_Views_Counter()->options['general']['flush_interval']['number'] ) . '" />
378
+ <select class="pvc-chosen-short" name="post_views_counter_settings_general[flush_interval][type]">';
379
+
380
+ foreach ( $this->time_types as $type => $type_name ) {
381
+ echo '
382
+ <option value="' . esc_attr( $type ) . '" ' . selected( $type, Post_Views_Counter()->options['general']['flush_interval']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
383
+ }
384
+
385
+ echo '
386
+ </select>
387
+ <p class="description">' . __( 'How often to flush cached view counts from the object cache into the database. This feature is used only if a persistent object cache is detected and the interval is greater than 0 (number zero). When used, view counts will be collected and stored in the object cache instead of the database and will then be asynchronously flushed to the database according to the specified interval.<br /><strong>Notice:</strong> Potential data loss may occur if the object cache is cleared/unavailable for the duration of the interval.', 'post-views-counter' ) . '</p>
388
+ </div>';
389
+ }
390
+
391
+ /**
392
+ * Exlude user groups option.
393
+ */
394
+ public function exclude() {
395
+ echo '
396
+ <div id="pvc_exclude">
397
+ <fieldset>';
398
+
399
+ foreach ( $this->groups as $type => $type_name ) {
400
+ echo '
401
+ <label><input id="pvc_exclude-' . $type . '" type="checkbox" name="post_views_counter_settings_general[exclude][groups][' . $type . ']" value="1" ' . checked( in_array( $type, Post_Views_Counter()->options['general']['exclude']['groups'], true ), true, false ) . ' />' . esc_html( $type_name ) . '</label>';
402
+ }
403
+
404
+ echo '
405
+ <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
406
+ <div class="pvc_user_roles"' . (in_array( 'roles', Post_Views_Counter()->options['general']['exclude']['groups'], true ) ? '' : ' style="display: none;"') . '>';
407
+
408
+ foreach ( $this->user_roles as $role => $role_name ) {
409
+ echo '
410
+ <label><input type="checkbox" name="post_views_counter_settings_general[exclude][roles][' . $role . ']" value="1" ' . checked( in_array( $role, Post_Views_Counter()->options['general']['exclude']['roles'], true ), true, false ) . '>' . esc_html( $role_name ) . '</label>';
411
+ }
412
+
413
+ echo '
414
+ <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
415
+ </div>
416
+ </fieldset>
417
+ </div>';
418
+ }
419
+
420
+ /**
421
+ * Exclude IPs option.
422
+ */
423
+ public function exclude_ips() {
424
+ // lovely php 5.2 limitations
425
+ $ips = Post_Views_Counter()->options['general']['exclude_ips'];
426
+
427
+ echo '
428
+ <div id="pvc_exclude_ips">';
429
+
430
+ if ( ! empty( $ips ) ) {
431
+ foreach ( $ips as $key => $ip ) {
432
+ echo '
433
+ <div class="ip-box">
434
+ <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="' . esc_attr( $ip ) . '" /> <a href="#" class="remove-exclude-ip" title="' . esc_attr__( 'Remove', 'post-views-counter' ) . '">' . esc_attr__( 'Remove', 'post-views-counter' ) . '</a>
435
+ </div>';
436
+ }
437
+ } else {
438
+ echo '
439
+ <div class="ip-box">
440
+ <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="" /> <a href="#" class="remove-exclude-ip" title="' . esc_attr__( 'Remove', 'post-views-counter' ) . '">' . esc_attr__( 'Remove', 'post-views-counter' ) . '</a>
441
+ </div>';
442
+ }
443
+
444
+ echo '
445
+ <p><input type="button" class="button button-secondary add-exclude-ip" value="' . esc_attr__( 'Add new', 'post-views-counter' ) . '" /> <input type="button" class="button button-secondary add-current-ip" value="' . esc_attr__( 'Add my current IP', 'post-views-counter' ) . '" data-rel="' . esc_attr( $_SERVER['REMOTE_ADDR'] ) . '" /></p>
446
+ <p class="description">' . __( 'Enter the IP addresses to be excluded from post views count.', 'post-views-counter' ) . '</p>
447
+ </div>';
448
+ }
449
+
450
+ /**
451
+ * Strict counts option.
452
+ */
453
+ public function strict_counts() {
454
+ echo '
455
+ <div id="pvc_strict_counts">
456
+ <label><input id="pvc-strict-counts" type="checkbox" name="post_views_counter_settings_general[strict_counts]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['strict_counts'], false ) . ' />' . __( 'Enable to prevent bypassing the counts interval (for e.g. using incognito browser window or by clearing cookies).', 'post-views-counter' ) . '</label>
457
+ </div>';
458
+ }
459
+
460
+ /**
461
+ * WP-PostViews import option.
462
+ */
463
+ public function wp_postviews() {
464
+ echo '
465
+ <div id="pvc_wp_postviews">
466
+ <fieldset>
467
+ <input type="submit" class="button button-secondary" name="post_views_counter_import_wp_postviews" value="' . __( 'Import views', 'post-views-counter' ) . '"/> <label><input id="pvc-wp-postviews" type="checkbox" name="post_views_counter_import_wp_postviews_override" value="1" />' . __( 'Override existing views data.', 'post-views-counter' ) . '</label>
468
+ <p class="description">' . __( 'Import post views data from WP-PostViews plugin.', 'post-views-counter' ) . '</p>
469
+ <br /><input type="submit" class="button button-secondary" name="post_views_counter_reset_views" value="' . __( 'Delete views', 'post-views-counter' ) . '"/>
470
+ <p class="description">' . __( 'Delete ALL the existing post views data.', 'post-views-counter' ) . '</p>
471
+ </fieldset>
472
+ </div>';
473
+ }
474
+
475
+ /**
476
+ * Limit views edit to admins.
477
+ */
478
+ public function restrict_edit_views() {
479
+ echo '
480
+ <div id="pvc_restrict_edit_views">
481
+ <label><input type="checkbox" name="post_views_counter_settings_general[restrict_edit_views]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['restrict_edit_views'], false ) . ' />' . __( 'Enable to restrict post views editing to admins only.', 'post-views-counter' ) . '</label>
482
+ </div>';
483
+ }
484
+
485
+ /**
486
+ * Plugin deactivation option.
487
+ */
488
+ public function deactivation_delete() {
489
+ echo '
490
+ <div id="pvc_deactivation_delete">
491
+ <label><input type="checkbox" name="post_views_counter_settings_general[deactivation_delete]" value="1" ' . checked( true, Post_Views_Counter()->options['general']['deactivation_delete'], false ) . ' />' . __( 'Enable to delete all plugin data on deactivation.', 'post-views-counter' ) . '</label>
492
+ </div>';
493
+ }
494
+
495
+ /**
496
+ * Visibility option.
497
+ */
498
+ public function page_types_display() {
499
+ echo '
500
+ <div id="pvc_post_types_display">';
501
+
502
+ foreach ( $this->page_types as $key => $label ) {
503
+ echo '
504
+ <label><input id="pvc_page_types_display-' . esc_attr( $key ) . '" type="checkbox" name="post_views_counter_settings_display[page_types_display][' . esc_attr( $key ) . ']" value="1" ' . checked( in_array( $key, Post_Views_Counter()->options['display']['page_types_display'], true ), true, false ) . ' />' . esc_html( $label ) . '</label>';
505
+ }
506
+
507
+ echo '
508
+ <p class="description">' . __( 'Select page types where the views count will be displayed.', 'post-views-counter' ) . '</p>
509
+ </div>';
510
+ }
511
+
512
+ /**
513
+ * Counter position option.
514
+ */
515
+ public function position() {
516
+ echo '
517
+ <div id="pvc_position">
518
+ <select class="pvc-chosen-short" name="post_views_counter_settings_display[position]">';
519
+
520
+ foreach ( $this->positions as $position => $position_name ) {
521
+ echo '
522
+ <option value="' . esc_attr( $position ) . '" ' . selected( $position, Post_Views_Counter()->options['display']['position'], false ) . '>' . esc_html( $position_name ) . '</option>';
523
+ }
524
+
525
+ echo '
526
+ </select>
527
+ <p class="description">' . __( 'Select where would you like to display the post views counter. Use [post-views] shortcode for manual display.', 'post-views-counter' ) . '</p>
528
+ </div>';
529
+ }
530
+
531
+ /**
532
+ * Counter style option.
533
+ */
534
+ public function display_style() {
535
+ echo '
536
+ <div id="pvc_display_style">';
537
+
538
+ foreach ( $this->display_styles as $display => $style ) {
539
+ $display = esc_attr( $display );
540
+
541
+ echo '
542
+ <label><input type="checkbox" name="post_views_counter_settings_display[display_style][' . $display . ']" value="1" ' . checked( true, Post_Views_Counter()->options['display']['display_style'][$display], false ) . ' />' . esc_html( $style ) . '</label>';
543
+ }
544
+
545
+ echo '
546
+ <p class="description">' . __( 'Choose how to display the post views counter.', 'post-views-counter' ) . '</p>
547
+ </div>';
548
+ }
549
+
550
+ /**
551
+ * Counter icon class option.
552
+ */
553
+ public function icon_class() {
554
+ echo '
555
+ <div id="pvc_icon_class">
556
+ <input type="text" name="post_views_counter_settings_display[icon_class]" class="large-text" value="' . esc_attr( Post_Views_Counter()->options['display']['icon_class'] ) . '" />
557
+ <p class="description">' . sprintf( __( 'Enter the post views icon class. Any of the <a href="%s" target="_blank">Dashicons</a> classes are available.', 'post-views-counter' ), 'https://developer.wordpress.org/resource/dashicons/' ) . '</p>
558
+ </div>';
559
+ }
560
+
561
+ /**
562
+ * Toolbar statistics.
563
+ */
564
+ public function toolbar_statistics() {
565
+ echo '
566
+ <div id="pvc_toolbar_statistics">
567
+ <label><input type="checkbox" name="post_views_counter_settings_display[toolbar_statistics]" value="1" ' . checked( true, Post_Views_Counter()->options['display']['toolbar_statistics'], false ) . ' />' . __( 'Enable to display the post views chart at the toolbar.', 'post-views-counter' ) . '</label>
568
+ <p class="description">' . __( 'The post views chart will be displayed for the post types that are being counted.', 'post-views-counter' ) . '</p>
569
+ </div>';
570
+ }
571
+
572
+ /**
573
+ * Restrict display option.
574
+ */
575
+ public function restrict_display() {
576
+ echo '
577
+ <div id="pvc_restrict_display">
578
+ <fieldset>';
579
+
580
+ foreach ( $this->groups as $type => $type_name ) {
581
+
582
+ if ( $type === 'robots' )
583
+ continue;
584
+
585
+ echo '
586
+ <label><input id="pvc_restrict_display-' . $type . '" type="checkbox" name="post_views_counter_settings_display[restrict_display][groups][' . esc_html( $type ) . ']" value="1" ' . checked( in_array( $type, Post_Views_Counter()->options['display']['restrict_display']['groups'], true ), true, false ) . ' />' . esc_html( $type_name ) . '</label>';
587
+ }
588
+
589
+ echo '
590
+ <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
591
+ <div class="pvc_user_roles"' . (in_array( 'roles', Post_Views_Counter()->options['display']['restrict_display']['groups'], true ) ? '' : ' style="display: none;"') . '>';
592
+
593
+ foreach ( $this->user_roles as $role => $role_name ) {
594
+ echo '
595
+ <label><input type="checkbox" name="post_views_counter_settings_display[restrict_display][roles][' . $role . ']" value="1" ' . checked( in_array( $role, Post_Views_Counter()->options['display']['restrict_display']['roles'], true ), true, false ) . ' />' . esc_html( $role_name ) . '</label>';
596
+ }
597
+
598
+ echo '
599
+ <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
600
+ </div>
601
+ </fieldset>
602
+ </div>';
603
+ }
604
+
605
+ /**
606
+ * Validate general settings.
607
+ */
608
+ public function validate_settings( $input ) {
609
+ // get main instance
610
+ $pvc = Post_Views_Counter();
611
+
612
+ // import post views data from another plugin
613
+ if ( isset( $_POST['post_views_counter_import_wp_postviews'] ) ) {
614
+ // make sure we do not change anything in the settings
615
+ $input = $pvc->options['general'];
616
+
617
+ global $wpdb;
618
+
619
+ $meta_key = esc_attr( apply_filters( 'pvc_import_meta_key', 'views' ) );
620
+
621
+ $views = $wpdb->get_results( "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '" . $meta_key . "'", ARRAY_A, 0 );
622
+
623
+ if ( ! empty( $views ) ) {
624
+ $sql = array();
625
+
626
+ foreach ( $views as $view ) {
627
+ $sql[] = "(" . $view['post_id'] . ", 4, 'total', " . $view['meta_value'] . ")";
628
+ }
629
+
630
+ $wpdb->query( "INSERT INTO " . $wpdb->prefix . "post_views(id, type, period, count) VALUES " . implode( ',', $sql ) . " ON DUPLICATE KEY UPDATE count = " . ( isset( $_POST['post_views_counter_import_wp_postviews_override'] ) ? '' : 'count + ' ) . "VALUES(count)" );
631
+
632
+ add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'Post views data imported succesfully.', 'post-views-counter' ), 'updated' );
633
+ } else {
634
+ add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'There was no post views data to import.', 'post-views-counter' ), 'updated' );
635
+ }
636
+ // delete all post views data
637
+ } elseif ( isset( $_POST['post_views_counter_reset_views'] ) ) {
638
+ // make sure we do not change anything in the settings
639
+ $input = $pvc->options['general'];
640
+
641
+ global $wpdb;
642
+
643
+ if ( $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . 'post_views' ) )
644
+ add_settings_error( 'reset_post_views', 'reset_post_views', __( 'All existing data deleted succesfully.', 'post-views-counter' ), 'updated' );
645
+ else
646
+ add_settings_error( 'reset_post_views', 'reset_post_views', __( 'Error occurred. All existing data were not deleted.', 'post-views-counter' ), 'error' );
647
+ // save general settings
648
+ } elseif ( isset( $_POST['save_pvc_general'] ) ) {
649
+ // post types count
650
+ if ( isset( $input['post_types_count'] ) ) {
651
+ $post_types = array();
652
+
653
+ foreach ( $input['post_types_count'] as $post_type => $set ) {
654
+ if ( isset( $this->post_types[$post_type] ) )
655
+ $post_types[] = $post_type;
656
+ }
657
+
658
+ $input['post_types_count'] = array_unique( $post_types );
659
+ } else
660
+ $input['post_types_count'] = array();
661
+
662
+ // counter mode
663
+ $input['counter_mode'] = isset( $input['counter_mode'], $this->modes[$input['counter_mode']] ) ? $input['counter_mode'] : $pvc->defaults['general']['counter_mode'];
664
+
665
+ // post views column
666
+ $input['post_views_column'] = isset( $input['post_views_column'] );
667
+
668
+ // time between counts
669
+ $input['time_between_counts']['number'] = (int) ( isset( $input['time_between_counts']['number'] ) ? $input['time_between_counts']['number'] : $pvc->defaults['general']['time_between_counts']['number'] );
670
+ $input['time_between_counts']['type'] = isset( $input['time_between_counts']['type'], $this->time_types[$input['time_between_counts']['type']] ) ? $input['time_between_counts']['type'] : $pvc->defaults['general']['time_between_counts']['type'];
671
+
672
+ // flush interval
673
+ $input['flush_interval']['number'] = (int) ( isset( $input['flush_interval']['number'] ) ? $input['flush_interval']['number'] : $pvc->defaults['general']['flush_interval']['number'] );
674
+ $input['flush_interval']['type'] = isset( $input['flush_interval']['type'], $this->time_types[$input['flush_interval']['type']] ) ? $input['flush_interval']['type'] : $pvc->defaults['general']['flush_interval']['type'];
675
+
676
+ // Since the settings are about to be saved and cache flush interval could've changed,
677
+ // we want to make sure that any changes done on the settings page are in effect immediately
678
+ // (instead of having to wait for the previous schedule to occur).
679
+ // We achieve that by making sure to clear any previous cache flush schedules and
680
+ // schedule the new one if the specified interval is > 0
681
+ $pvc->remove_cache_flush();
682
+
683
+ if ( $input['flush_interval']['number'] > 0 )
684
+ $pvc->schedule_cache_flush();
685
+
686
+ // reset counts
687
+ $input['reset_counts']['number'] = (int) ( isset( $input['reset_counts']['number'] ) ? $input['reset_counts']['number'] : $pvc->defaults['general']['reset_counts']['number'] );
688
+ $input['reset_counts']['type'] = isset( $input['reset_counts']['type'], $this->time_types[$input['reset_counts']['type']] ) ? $input['reset_counts']['type'] : $pvc->defaults['general']['reset_counts']['type'];
689
+
690
+ // run cron on next visit?
691
+ $input['cron_run'] = ( $input['reset_counts']['number'] > 0 );
692
+ $input['cron_update'] = ( $input['cron_run'] && ( $pvc->options['general']['reset_counts']['number'] !== $input['reset_counts']['number'] || $pvc->options['general']['reset_counts']['type'] !== $input['reset_counts']['type'] ) );
693
+
694
+ // exclude
695
+ if ( isset( $input['exclude']['groups'] ) ) {
696
+ $groups = array();
697
+
698
+ foreach ( $input['exclude']['groups'] as $group => $set ) {
699
+ if ( isset( $this->groups[$group] ) )
700
+ $groups[] = $group;
701
+ }
702
+
703
+ $input['exclude']['groups'] = array_unique( $groups );
704
+ } else {
705
+ $input['exclude']['groups'] = array();
706
+ }
707
+
708
+ if ( in_array( 'roles', $input['exclude']['groups'], true ) && isset( $input['exclude']['roles'] ) ) {
709
+ $roles = array();
710
+
711
+ foreach ( $input['exclude']['roles'] as $role => $set ) {
712
+ if ( isset( $this->user_roles[$role] ) )
713
+ $roles[] = $role;
714
+ }
715
+
716
+ $input['exclude']['roles'] = array_unique( $roles );
717
+ } else
718
+ $input['exclude']['roles'] = array();
719
+
720
+ // exclude ips
721
+ if ( isset( $input['exclude_ips'] ) ) {
722
+ $ips = array();
723
+
724
+ foreach ( $input['exclude_ips'] as $ip ) {
725
+ if ( strpos( $ip, '*' ) !== false ) {
726
+ $new_ip = str_replace( '*', '0', $ip );
727
+
728
+ if ( filter_var( $new_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
729
+ $ips[] = $ip;
730
+ } elseif ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
731
+ $ips[] = $ip;
732
+ }
733
+
734
+ $input['exclude_ips'] = array_unique( $ips );
735
+ }
736
+
737
+ // restrict edit views
738
+ $input['restrict_edit_views'] = isset( $input['restrict_edit_views'] );
739
+
740
+ // strict counts
741
+ $input['strict_counts'] = isset( $input['strict_counts'] );
742
+
743
+ // deactivation delete
744
+ $input['deactivation_delete'] = isset( $input['deactivation_delete'] );
745
+
746
+ $input['update_version'] = $pvc->options['general']['update_version'];
747
+ $input['update_notice'] = $pvc->options['general']['update_notice'];
748
+ // save display settings
749
+ } elseif ( isset( $_POST['save_pvc_display'] ) ) {
750
+
751
+ // post views label
752
+ $input['label'] = isset( $input['label'] ) ? $input['label'] : $pvc->defaults['display']['label'];
753
+
754
+ if ( function_exists( 'icl_register_string' ) )
755
+ icl_register_string( 'Post Views Counter', 'Post Views Label', $input['label'] );
756
+
757
+ // position
758
+ $input['position'] = isset( $input['position'], $this->positions[$input['position']] ) ? $input['position'] : $pvc->defaults['display']['position'];
759
+
760
+ // display style
761
+ $input['display_style']['icon'] = isset( $input['display_style']['icon'] );
762
+ $input['display_style']['text'] = isset( $input['display_style']['text'] );
763
+
764
+ // link to post
765
+ $input['link_to_post'] = isset( $input['link_to_post'] ) ? $input['link_to_post'] : $pvc->defaults['display']['link_to_post'];
766
+
767
+ // icon class
768
+ $input['icon_class'] = isset( $input['icon_class'] ) ? trim( $input['icon_class'] ) : $pvc->defaults['display']['icon_class'];
769
+
770
+ $input['toolbar_statistics'] = isset( $input['toolbar_statistics'] ) ? trim( $input['toolbar_statistics'] ) : $pvc->defaults['display']['toolbar_statistics'];
771
+
772
+ // post types display
773
+ if ( isset( $input['post_types_display'] ) ) {
774
+ $post_types = array();
775
+
776
+ foreach ( $input['post_types_display'] as $post_type => $set ) {
777
+ if ( isset( $this->post_types[$post_type] ) )
778
+ $post_types[] = $post_type;
779
+ }
780
+
781
+ $input['post_types_display'] = array_unique( $post_types );
782
+ } else
783
+ $input['post_types_display'] = array();
784
+
785
+ // page types display
786
+ if ( isset( $input['page_types_display'] ) ) {
787
+ $page_types = array();
788
+
789
+ foreach ( $input['page_types_display'] as $page_type => $set ) {
790
+ if ( isset( $this->page_types[$page_type] ) )
791
+ $page_types[] = $page_type;
792
+ }
793
+
794
+ $input['page_types_display'] = array_unique( $page_types );
795
+ } else
796
+ $input['page_types_display'] = array();
797
+
798
+ // restrict display
799
+ if ( isset( $input['restrict_display']['groups'] ) ) {
800
+ $groups = array();
801
+
802
+ foreach ( $input['restrict_display']['groups'] as $group => $set ) {
803
+ if ( $group === 'robots' )
804
+ continue;
805
+
806
+ if ( isset( $this->groups[$group] ) )
807
+ $groups[] = $group;
808
+ }
809
+
810
+ $input['restrict_display']['groups'] = array_unique( $groups );
811
+ } else
812
+ $input['restrict_display']['groups'] = array();
813
+
814
+ if ( in_array( 'roles', $input['restrict_display']['groups'], true ) && isset( $input['restrict_display']['roles'] ) ) {
815
+ $roles = array();
816
+
817
+ foreach ( $input['restrict_display']['roles'] as $role => $set ) {
818
+ if ( isset( $this->user_roles[$role] ) )
819
+ $roles[] = $role;
820
+ }
821
+
822
+ $input['restrict_display']['roles'] = array_unique( $roles );
823
+ } else
824
+ $input['restrict_display']['roles'] = array();
825
+ // reset general settings
826
+ } elseif ( isset( $_POST['reset_pvc_general'] ) ) {
827
+ $input = $pvc->defaults['general'];
828
+
829
+ add_settings_error( 'reset_general_settings', 'settings_reset', __( 'General settings restored to defaults.', 'post-views-counter' ), 'updated' );
830
+ // reset display settings
831
+ } elseif ( isset( $_POST['reset_pvc_display'] ) ) {
832
+ $input = $pvc->defaults['display'];
833
+
834
+ add_settings_error( 'reset_general_settings', 'settings_reset', __( 'Display settings restored to defaults.', 'post-views-counter' ), 'updated' );
835
+ }
836
+
837
+ return $input;
838
+ }
839
  }
languages/post-views-counter.pot CHANGED
@@ -2,7 +2,7 @@
2
  msgid ""
3
  msgstr ""
4
  "Project-Id-Version: Post Views Counter\n"
5
- "POT-Creation-Date: 2021-03-11 16:50+0100\n"
6
  "PO-Revision-Date: 2015-04-08 18:59+0100\n"
7
  "Last-Translator: Bartosz Arendt <info@dfactory.eu>\n"
8
  "Language-Team: dFactory <info@dfactory.eu>\n"
@@ -21,9 +21,9 @@ msgstr ""
21
  #: ../includes/columns.php:51 ../includes/columns.php:154
22
  #: ../includes/columns.php:197 ../includes/columns.php:348
23
  #: ../includes/columns.php:354 ../includes/columns.php:404
24
- #: ../includes/dashboard.php:60 ../includes/dashboard.php:252
25
- #: ../includes/dashboard.php:347 ../includes/dashboard.php:356
26
- #: ../includes/dashboard.php:365 ../includes/dashboard.php:451
27
  msgid "Post Views"
28
  msgstr ""
29
 
@@ -32,7 +32,7 @@ msgstr ""
32
  msgid "You are not allowed to edit this item."
33
  msgstr ""
34
 
35
- #: ../includes/columns.php:114 ../includes/counter.php:220
36
  msgid "Invalid post ID."
37
  msgstr ""
38
 
@@ -52,11 +52,11 @@ msgstr ""
52
  msgid "OK"
53
  msgstr ""
54
 
55
- #: ../includes/counter.php:212
56
  msgid "REST API method is disabled."
57
  msgstr ""
58
 
59
- #: ../includes/counter.php:226
60
  msgid "Post type excluded."
61
  msgstr ""
62
 
@@ -73,39 +73,39 @@ msgstr ""
73
  msgid "Post Views Counter"
74
  msgstr ""
75
 
76
- #: ../includes/dashboard.php:60
77
  msgid ""
78
  "Displays the chart of most viewed post types for a selected time period."
79
  msgstr ""
80
 
81
- #: ../includes/dashboard.php:79
82
  msgid "Top Posts"
83
  msgstr ""
84
 
85
- #: ../includes/dashboard.php:79
86
  msgid "Displays the list of most viewed posts and pages on your website."
87
  msgstr ""
88
 
89
- #: ../includes/dashboard.php:136 ../includes/dashboard.php:207
90
- #: ../includes/dashboard.php:210 ../includes/dashboard.php:296
91
- #: ../includes/dashboard.php:299
92
  msgid "You do not have permission to access this page."
93
  msgstr ""
94
 
95
- #: ../includes/dashboard.php:251
96
- msgid "Post"
97
  msgstr ""
98
 
99
- #: ../includes/dashboard.php:275 ../includes/widgets.php:58
100
- msgid "No most viewed posts found"
101
  msgstr ""
102
 
103
- #: ../includes/dashboard.php:364
104
- msgid "Year"
105
  msgstr ""
106
 
107
- #: ../includes/dashboard.php:379 ../includes/dashboard.php:465
108
- msgid "Total Views"
109
  msgstr ""
110
 
111
  #: ../includes/functions.php:476
@@ -333,47 +333,51 @@ msgstr ""
333
  msgid "Icon Class"
334
  msgstr ""
335
 
336
- #: ../includes/settings.php:262
 
 
 
 
337
  msgid "Enter the label for the post views counter field."
338
  msgstr ""
339
 
340
- #: ../includes/settings.php:280
341
  msgid "Select post types for which post views will be counted."
342
  msgstr ""
343
 
344
- #: ../includes/settings.php:297
345
  msgid "Select post types for which the views count will be displayed."
346
  msgstr ""
347
 
348
- #: ../includes/settings.php:316
349
  msgid ""
350
  "Select the method of collecting post views data. If you are using any of the "
351
  "caching plugins select Javascript or REST API (if available)."
352
  msgstr ""
353
 
354
- #: ../includes/settings.php:316
355
  msgid ""
356
  "Optionally try the Fast AJAX experimental method, usually 10+ times faster "
357
  "than Javascript or REST API."
358
  msgstr ""
359
 
360
- #: ../includes/settings.php:326
361
  msgid ""
362
  "Enable to display post views count column for each of the selected post "
363
  "types."
364
  msgstr ""
365
 
366
- #: ../includes/settings.php:346
367
  msgid "Enter the time between single user visit count."
368
  msgstr ""
369
 
370
- #: ../includes/settings.php:366
371
  msgid ""
372
  "Delete single day post views data older than specified above. Enter 0 "
373
  "(number zero) if you want to preserve your data regardless of its age."
374
  msgstr ""
375
 
376
- #: ../includes/settings.php:386
377
  msgid ""
378
  "How often to flush cached view counts from the object cache into the "
379
  "database. This feature is used only if a persistent object cache is detected "
@@ -385,106 +389,116 @@ msgid ""
385
  "interval."
386
  msgstr ""
387
 
388
- #: ../includes/settings.php:404 ../includes/settings.php:577
389
  msgid "Use it to hide the post views counter from selected type of visitors."
390
  msgstr ""
391
 
392
- #: ../includes/settings.php:412 ../includes/settings.php:586
393
  msgid "Use it to hide the post views counter from selected user roles."
394
  msgstr ""
395
 
396
- #: ../includes/settings.php:432 ../includes/settings.php:438
397
  msgid "Remove"
398
  msgstr ""
399
 
400
- #: ../includes/settings.php:443
401
  msgid "Add new"
402
  msgstr ""
403
 
404
- #: ../includes/settings.php:443
405
  msgid "Add my current IP"
406
  msgstr ""
407
 
408
- #: ../includes/settings.php:444
409
  msgid "Enter the IP addresses to be excluded from post views count."
410
  msgstr ""
411
 
412
- #: ../includes/settings.php:454
413
  msgid ""
414
  "Enable to prevent bypassing the counts interval (for e.g. using incognito "
415
  "browser window or by clearing cookies)."
416
  msgstr ""
417
 
418
- #: ../includes/settings.php:465
419
  msgid "Import views"
420
  msgstr ""
421
 
422
- #: ../includes/settings.php:465
423
  msgid "Override existing views data."
424
  msgstr ""
425
 
426
- #: ../includes/settings.php:466
427
  msgid "Import post views data from WP-PostViews plugin."
428
  msgstr ""
429
 
430
- #: ../includes/settings.php:467
431
  msgid "Delete views"
432
  msgstr ""
433
 
434
- #: ../includes/settings.php:468
435
  msgid "Delete ALL the existing post views data."
436
  msgstr ""
437
 
438
- #: ../includes/settings.php:479
439
  msgid "Enable to restrict post views editing to admins only."
440
  msgstr ""
441
 
442
- #: ../includes/settings.php:489
443
  msgid "Enable to delete all plugin data on deactivation."
444
  msgstr ""
445
 
446
- #: ../includes/settings.php:506
447
  msgid "Select page types where the views count will be displayed."
448
  msgstr ""
449
 
450
- #: ../includes/settings.php:525
451
  msgid ""
452
  "Select where would you like to display the post views counter. Use [post-"
453
  "views] shortcode for manual display."
454
  msgstr ""
455
 
456
- #: ../includes/settings.php:544
457
  msgid "Choose how to display the post views counter."
458
  msgstr ""
459
 
460
- #: ../includes/settings.php:555
461
  #, php-format
462
  msgid ""
463
  "Enter the post views icon class. Any of the <a href=\"%s\" target=\"_blank"
464
  "\">Dashicons</a> classes are available."
465
  msgstr ""
466
 
467
- #: ../includes/settings.php:618
 
 
 
 
 
 
 
 
 
 
468
  msgid "Post views data imported succesfully."
469
  msgstr ""
470
 
471
- #: ../includes/settings.php:620
472
  msgid "There was no post views data to import."
473
  msgstr ""
474
 
475
- #: ../includes/settings.php:626
476
  msgid "All existing data deleted succesfully."
477
  msgstr ""
478
 
479
- #: ../includes/settings.php:628
480
  msgid "Error occurred. All existing data were not deleted."
481
  msgstr ""
482
 
483
- #: ../includes/settings.php:807
484
  msgid "General settings restored to defaults."
485
  msgstr ""
486
 
487
- #: ../includes/settings.php:811
488
  msgid "Display settings restored to defaults."
489
  msgstr ""
490
 
@@ -566,28 +580,28 @@ msgstr ""
566
  msgid "Thumbnail size"
567
  msgstr ""
568
 
569
- #: ../post-views-counter.php:252
570
  #, php-format
571
  msgid ""
572
  "Hey, you've been using <strong>Post Views Counter</strong> for more than %s."
573
  msgstr ""
574
 
575
- #: ../post-views-counter.php:252
576
  msgid ""
577
  "Could you please do me a BIG favor and give it a 5-star rating on WordPress "
578
  "to help us spread the word and boost our motivation."
579
  msgstr ""
580
 
581
- #: ../post-views-counter.php:252
582
  msgid "Your help is much appreciated. Thank you very much"
583
  msgstr ""
584
 
585
- #: ../post-views-counter.php:252
586
  #, php-format
587
  msgid "founder of <a href=\"%s\" target=\"_blank\">dFactory</a> plugins."
588
  msgstr ""
589
 
590
- #: ../post-views-counter.php:252
591
  #, php-format
592
  msgid ""
593
  "<a href=\"%s\" class=\"pvc-dismissible-notice\" target=\"_blank\" rel="
@@ -597,18 +611,18 @@ msgid ""
597
  "notice\" rel=\"noopener\">I already did</a>"
598
  msgstr ""
599
 
600
- #: ../post-views-counter.php:534
601
  msgid "Are you sure you want to reset these settings to defaults?"
602
  msgstr ""
603
 
604
- #: ../post-views-counter.php:535
605
  msgid "Are you sure you want to delete all existing data?"
606
  msgstr ""
607
 
608
- #: ../post-views-counter.php:589
609
  msgid "Support"
610
  msgstr ""
611
 
612
- #: ../post-views-counter.php:613
613
  msgid "Settings"
614
  msgstr ""
2
  msgid ""
3
  msgstr ""
4
  "Project-Id-Version: Post Views Counter\n"
5
+ "POT-Creation-Date: 2021-08-18 09:35+0200\n"
6
  "PO-Revision-Date: 2015-04-08 18:59+0100\n"
7
  "Last-Translator: Bartosz Arendt <info@dfactory.eu>\n"
8
  "Language-Team: dFactory <info@dfactory.eu>\n"
21
  #: ../includes/columns.php:51 ../includes/columns.php:154
22
  #: ../includes/columns.php:197 ../includes/columns.php:348
23
  #: ../includes/columns.php:354 ../includes/columns.php:404
24
+ #: ../includes/dashboard.php:94 ../includes/dashboard.php:198
25
+ #: ../includes/dashboard.php:207 ../includes/dashboard.php:216
26
+ #: ../includes/dashboard.php:302 ../includes/dashboard.php:432
27
  msgid "Post Views"
28
  msgstr ""
29
 
32
  msgid "You are not allowed to edit this item."
33
  msgstr ""
34
 
35
+ #: ../includes/columns.php:114 ../includes/counter.php:241
36
  msgid "Invalid post ID."
37
  msgstr ""
38
 
52
  msgid "OK"
53
  msgstr ""
54
 
55
+ #: ../includes/counter.php:233
56
  msgid "REST API method is disabled."
57
  msgstr ""
58
 
59
+ #: ../includes/counter.php:247
60
  msgid "Post type excluded."
61
  msgstr ""
62
 
73
  msgid "Post Views Counter"
74
  msgstr ""
75
 
76
+ #: ../includes/dashboard.php:94
77
  msgid ""
78
  "Displays the chart of most viewed post types for a selected time period."
79
  msgstr ""
80
 
81
+ #: ../includes/dashboard.php:118
82
  msgid "Top Posts"
83
  msgstr ""
84
 
85
+ #: ../includes/dashboard.php:118
86
  msgid "Displays the list of most viewed posts and pages on your website."
87
  msgstr ""
88
 
89
+ #: ../includes/dashboard.php:147 ../includes/dashboard.php:150
90
+ #: ../includes/dashboard.php:387 ../includes/dashboard.php:390
91
+ #: ../includes/dashboard.php:504
92
  msgid "You do not have permission to access this page."
93
  msgstr ""
94
 
95
+ #: ../includes/dashboard.php:215
96
+ msgid "Year"
97
  msgstr ""
98
 
99
+ #: ../includes/dashboard.php:230 ../includes/dashboard.php:316
100
+ msgid "Total Views"
101
  msgstr ""
102
 
103
+ #: ../includes/dashboard.php:431
104
+ msgid "Post"
105
  msgstr ""
106
 
107
+ #: ../includes/dashboard.php:455 ../includes/widgets.php:58
108
+ msgid "No most viewed posts found"
109
  msgstr ""
110
 
111
  #: ../includes/functions.php:476
333
  msgid "Icon Class"
334
  msgstr ""
335
 
336
+ #: ../includes/settings.php:252
337
+ msgid "Toolbar Chart"
338
+ msgstr ""
339
+
340
+ #: ../includes/settings.php:263
341
  msgid "Enter the label for the post views counter field."
342
  msgstr ""
343
 
344
+ #: ../includes/settings.php:281
345
  msgid "Select post types for which post views will be counted."
346
  msgstr ""
347
 
348
+ #: ../includes/settings.php:298
349
  msgid "Select post types for which the views count will be displayed."
350
  msgstr ""
351
 
352
+ #: ../includes/settings.php:317
353
  msgid ""
354
  "Select the method of collecting post views data. If you are using any of the "
355
  "caching plugins select Javascript or REST API (if available)."
356
  msgstr ""
357
 
358
+ #: ../includes/settings.php:317
359
  msgid ""
360
  "Optionally try the Fast AJAX experimental method, usually 10+ times faster "
361
  "than Javascript or REST API."
362
  msgstr ""
363
 
364
+ #: ../includes/settings.php:327
365
  msgid ""
366
  "Enable to display post views count column for each of the selected post "
367
  "types."
368
  msgstr ""
369
 
370
+ #: ../includes/settings.php:347
371
  msgid "Enter the time between single user visit count."
372
  msgstr ""
373
 
374
+ #: ../includes/settings.php:367
375
  msgid ""
376
  "Delete single day post views data older than specified above. Enter 0 "
377
  "(number zero) if you want to preserve your data regardless of its age."
378
  msgstr ""
379
 
380
+ #: ../includes/settings.php:387
381
  msgid ""
382
  "How often to flush cached view counts from the object cache into the "
383
  "database. This feature is used only if a persistent object cache is detected "
389
  "interval."
390
  msgstr ""
391
 
392
+ #: ../includes/settings.php:405 ../includes/settings.php:590
393
  msgid "Use it to hide the post views counter from selected type of visitors."
394
  msgstr ""
395
 
396
+ #: ../includes/settings.php:414 ../includes/settings.php:599
397
  msgid "Use it to hide the post views counter from selected user roles."
398
  msgstr ""
399
 
400
+ #: ../includes/settings.php:434 ../includes/settings.php:440
401
  msgid "Remove"
402
  msgstr ""
403
 
404
+ #: ../includes/settings.php:445
405
  msgid "Add new"
406
  msgstr ""
407
 
408
+ #: ../includes/settings.php:445
409
  msgid "Add my current IP"
410
  msgstr ""
411
 
412
+ #: ../includes/settings.php:446
413
  msgid "Enter the IP addresses to be excluded from post views count."
414
  msgstr ""
415
 
416
+ #: ../includes/settings.php:456
417
  msgid ""
418
  "Enable to prevent bypassing the counts interval (for e.g. using incognito "
419
  "browser window or by clearing cookies)."
420
  msgstr ""
421
 
422
+ #: ../includes/settings.php:467
423
  msgid "Import views"
424
  msgstr ""
425
 
426
+ #: ../includes/settings.php:467
427
  msgid "Override existing views data."
428
  msgstr ""
429
 
430
+ #: ../includes/settings.php:468
431
  msgid "Import post views data from WP-PostViews plugin."
432
  msgstr ""
433
 
434
+ #: ../includes/settings.php:469
435
  msgid "Delete views"
436
  msgstr ""
437
 
438
+ #: ../includes/settings.php:470
439
  msgid "Delete ALL the existing post views data."
440
  msgstr ""
441
 
442
+ #: ../includes/settings.php:481
443
  msgid "Enable to restrict post views editing to admins only."
444
  msgstr ""
445
 
446
+ #: ../includes/settings.php:491
447
  msgid "Enable to delete all plugin data on deactivation."
448
  msgstr ""
449
 
450
+ #: ../includes/settings.php:508
451
  msgid "Select page types where the views count will be displayed."
452
  msgstr ""
453
 
454
+ #: ../includes/settings.php:527
455
  msgid ""
456
  "Select where would you like to display the post views counter. Use [post-"
457
  "views] shortcode for manual display."
458
  msgstr ""
459
 
460
+ #: ../includes/settings.php:546
461
  msgid "Choose how to display the post views counter."
462
  msgstr ""
463
 
464
+ #: ../includes/settings.php:557
465
  #, php-format
466
  msgid ""
467
  "Enter the post views icon class. Any of the <a href=\"%s\" target=\"_blank"
468
  "\">Dashicons</a> classes are available."
469
  msgstr ""
470
 
471
+ #: ../includes/settings.php:567
472
+ msgid "Enable to display the post views chart at the toolbar."
473
+ msgstr ""
474
+
475
+ #: ../includes/settings.php:568
476
+ msgid ""
477
+ "The post views chart will be displayed for the post types that are being "
478
+ "counted."
479
+ msgstr ""
480
+
481
+ #: ../includes/settings.php:632
482
  msgid "Post views data imported succesfully."
483
  msgstr ""
484
 
485
+ #: ../includes/settings.php:634
486
  msgid "There was no post views data to import."
487
  msgstr ""
488
 
489
+ #: ../includes/settings.php:644
490
  msgid "All existing data deleted succesfully."
491
  msgstr ""
492
 
493
+ #: ../includes/settings.php:646
494
  msgid "Error occurred. All existing data were not deleted."
495
  msgstr ""
496
 
497
+ #: ../includes/settings.php:829
498
  msgid "General settings restored to defaults."
499
  msgstr ""
500
 
501
+ #: ../includes/settings.php:834
502
  msgid "Display settings restored to defaults."
503
  msgstr ""
504
 
580
  msgid "Thumbnail size"
581
  msgstr ""
582
 
583
+ #: ../post-views-counter.php:253
584
  #, php-format
585
  msgid ""
586
  "Hey, you've been using <strong>Post Views Counter</strong> for more than %s."
587
  msgstr ""
588
 
589
+ #: ../post-views-counter.php:253
590
  msgid ""
591
  "Could you please do me a BIG favor and give it a 5-star rating on WordPress "
592
  "to help us spread the word and boost our motivation."
593
  msgstr ""
594
 
595
+ #: ../post-views-counter.php:253
596
  msgid "Your help is much appreciated. Thank you very much"
597
  msgstr ""
598
 
599
+ #: ../post-views-counter.php:253
600
  #, php-format
601
  msgid "founder of <a href=\"%s\" target=\"_blank\">dFactory</a> plugins."
602
  msgstr ""
603
 
604
+ #: ../post-views-counter.php:253
605
  #, php-format
606
  msgid ""
607
  "<a href=\"%s\" class=\"pvc-dismissible-notice\" target=\"_blank\" rel="
611
  "notice\" rel=\"noopener\">I already did</a>"
612
  msgstr ""
613
 
614
+ #: ../post-views-counter.php:535
615
  msgid "Are you sure you want to reset these settings to defaults?"
616
  msgstr ""
617
 
618
+ #: ../post-views-counter.php:536
619
  msgid "Are you sure you want to delete all existing data?"
620
  msgstr ""
621
 
622
+ #: ../post-views-counter.php:590
623
  msgid "Support"
624
  msgstr ""
625
 
626
+ #: ../post-views-counter.php:614
627
  msgid "Settings"
628
  msgstr ""
post-views-counter.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Post Views Counter
4
  Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5
- Version: 1.3.4
6
  Author: Digital Factory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
@@ -31,60 +31,61 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
- * @version 1.3.4
35
  */
36
  final class Post_Views_Counter {
37
 
38
  private static $instance;
39
  public $options;
40
  public $defaults = array(
41
- 'general' => array(
42
- 'post_types_count' => array( 'post' ),
43
- 'counter_mode' => 'php',
44
- 'post_views_column' => true,
45
- 'time_between_counts' => array(
46
  'number' => 24,
47
  'type' => 'hours'
48
  ),
49
- 'reset_counts' => array(
50
  'number' => 30,
51
  'type' => 'days'
52
  ),
53
- 'flush_interval' => array(
54
  'number' => 0,
55
  'type' => 'minutes'
56
  ),
57
- 'exclude' => array(
58
  'groups' => array(),
59
  'roles' => array()
60
  ),
61
- 'exclude_ips' => array(),
62
- 'strict_counts' => false,
63
- 'restrict_edit_views' => false,
64
- 'deactivation_delete' => false,
65
- 'cron_run' => true,
66
- 'cron_update' => true,
67
  'update_version' => 1,
68
  'update_notice' => true,
69
  'update_delay_date' => 0
70
  ),
71
- 'display' => array(
72
- 'label' => 'Post Views:',
73
- 'post_types_display' => array( 'post' ),
74
- 'page_types_display' => array( 'singular' ),
75
- 'restrict_display' => array(
76
  'groups' => array(),
77
  'roles' => array()
78
  ),
79
- 'position' => 'after',
80
- 'display_style' => array(
81
  'icon' => true,
82
  'text' => true
83
  ),
84
- 'link_to_post' => true,
85
- 'icon_class' => 'dashicons-chart-bar'
 
86
  ),
87
- 'version' => '1.3.4'
88
  );
89
 
90
  /**
2
  /*
3
  Plugin Name: Post Views Counter
4
  Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5
+ Version: 1.3.5
6
  Author: Digital Factory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
+ * @version 1.3.5
35
  */
36
  final class Post_Views_Counter {
37
 
38
  private static $instance;
39
  public $options;
40
  public $defaults = array(
41
+ 'general' => array(
42
+ 'post_types_count' => array( 'post' ),
43
+ 'counter_mode' => 'php',
44
+ 'post_views_column' => true,
45
+ 'time_between_counts' => array(
46
  'number' => 24,
47
  'type' => 'hours'
48
  ),
49
+ 'reset_counts' => array(
50
  'number' => 30,
51
  'type' => 'days'
52
  ),
53
+ 'flush_interval' => array(
54
  'number' => 0,
55
  'type' => 'minutes'
56
  ),
57
+ 'exclude' => array(
58
  'groups' => array(),
59
  'roles' => array()
60
  ),
61
+ 'exclude_ips' => array(),
62
+ 'strict_counts' => false,
63
+ 'restrict_edit_views' => false,
64
+ 'deactivation_delete' => false,
65
+ 'cron_run' => true,
66
+ 'cron_update' => true,
67
  'update_version' => 1,
68
  'update_notice' => true,
69
  'update_delay_date' => 0
70
  ),
71
+ 'display' => array(
72
+ 'label' => 'Post Views:',
73
+ 'post_types_display' => array( 'post' ),
74
+ 'page_types_display' => array( 'singular' ),
75
+ 'restrict_display' => array(
76
  'groups' => array(),
77
  'roles' => array()
78
  ),
79
+ 'position' => 'after',
80
+ 'display_style' => array(
81
  'icon' => true,
82
  'text' => true
83
  ),
84
+ 'link_to_post' => true,
85
+ 'icon_class' => 'dashicons-chart-bar',
86
+ 'toolbar_statistics' => true
87
  ),
88
+ 'version' => '1.3.5'
89
  );
90
 
91
  /**
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: http://dfactory.eu/
4
  Tags: counter, hits, posts, postviews, post views, views, count, statistics, stats, analytics, pageviews, tracking
5
  Requires at least: 5.0
6
  Requires PHP: 5.2.4
7
- Tested up to: 5.7
8
- Stable tag: 1.3.4
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
@@ -62,6 +62,11 @@ No questions yet.
62
 
63
  == Changelog ==
64
 
 
 
 
 
 
65
  = 1.3.4 =
66
  * New: Post Views stats preview in the admin bar
67
  * New: Top Posts data available in the dashboard widget
@@ -211,8 +216,7 @@ Initial release
211
 
212
  == Upgrade Notice ==
213
 
214
- = 1.3.4 =
215
- * New: Post Views stats preview in the admin bar
216
- * New: Top Posts data available in the dashboard widget
217
- * Tweak: Improved privacy using IP encrypting
218
- * Tweak: PHP 8.x compatibility
4
  Tags: counter, hits, posts, postviews, post views, views, count, statistics, stats, analytics, pageviews, tracking
5
  Requires at least: 5.0
6
  Requires PHP: 5.2.4
7
+ Tested up to: 5.8
8
+ Stable tag: 1.3.5
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.3.5 =
66
+ * New: Option to hide admin bar chart
67
+ * Fix: Small security bug with views label
68
+ * Tweak: Remove unnecessary CSS on every page
69
+
70
  = 1.3.4 =
71
  * New: Post Views stats preview in the admin bar
72
  * New: Top Posts data available in the dashboard widget
216
 
217
  == Upgrade Notice ==
218
 
219
+ = 1.3.5 =
220
+ * New: Option to hide admin bar chart
221
+ * Fix: Small security bug with views label
222
+ * Tweak: Remove unnecessary CSS on every page