Page Visit Counter - Version 2.0.1

Version Description

Automatic updates should work great for you. As always, though, we recommend backing up your site prior to making any updates just to be sure nothing goes wrong.

Download this release

Release Info

Developer dots
Plugin Icon 128x128 Page Visit Counter
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

README.txt CHANGED
@@ -4,7 +4,7 @@ Plugin URI: http://multidots.com/
4
  Author: Multidots
5
  Author URI: http://multidots.com/
6
  Contributors: dots
7
- Stable tag: 2.0.0
8
  Tags: page counter,page visit
9
  Requires at least: 2.1
10
  Tested up to: 4.4.2
@@ -95,3 +95,7 @@ Automatic updates should work great for you. As always, though, we recommend ba
95
  * New - Exclude custom post type from Page / Post visit counter.
96
  * New - Eclude Specific IP and Registered Users from Page / Post visit Counter.
97
  * New - Display page visit count on bottom of page on entire site.
 
 
 
 
4
  Author: Multidots
5
  Author URI: http://multidots.com/
6
  Contributors: dots
7
+ Stable tag: 2.0.1
8
  Tags: page counter,page visit
9
  Requires at least: 2.1
10
  Tested up to: 4.4.2
95
  * New - Exclude custom post type from Page / Post visit counter.
96
  * New - Eclude Specific IP and Registered Users from Page / Post visit Counter.
97
  * New - Display page visit count on bottom of page on entire site.
98
+
99
+ = 2.0.1 - 24.02.2016 =
100
+ * Fixies - PHP error notice handled.
101
+ * New - Remove counter for the homepage.
admin/class-page-visit-counter-admin.php CHANGED
@@ -383,7 +383,7 @@ class page_visit_counter_Admin {
383
  $page_title = isset( $_POST['page_name'] ) ? $_POST['page_name'] : '';
384
  $page_date = isset( $_POST['page_date'] ) ? $_POST['page_date'] : '';
385
  $string ='';
386
- if( $page_date == '' && $page_title =='' ){
387
  $html .='<table id="example" class="display" cellpadding="0" cellspacing="0">
388
  <thead>
389
  <tr>
@@ -394,34 +394,44 @@ class page_visit_counter_Admin {
394
  </tr>
395
  </thead>
396
  <tbody>';
397
- $postperpage = -1;
398
- $args = array(
399
- 'post_type' => 'page',
400
- 'post_status' => 'publish',
401
- 'order' => 'ASC',
402
- 'posts_per_page' => $postperpage,
403
- );
404
- $posts_array = get_posts( $args );
405
- $counter = 0;
406
- foreach ( $posts_array as $results ){
407
- $counter = $counter + 1;
408
- $html .='<tr>';
409
- $html .='<td>'.$counter.'</td>';
410
- $html .='<td>'.$results->ID.'</td>';
411
- $html .='<td><a href="'.get_admin_url().'post.php?post='.$results->ID.'&action=edit">'.$results->post_title.'</a></td>';
412
- $count_visit = $wpdb->get_results("SELECT * from $table_name where page_id ='".$results->ID."'");
413
- $count = 0;
414
- foreach ( $count_visit as $countval){
415
- $count = $count + 1;
416
  }
417
- if ($count_visit[0]->page_visit == '') {
418
- $countC = 0;
419
- } else {
420
- $countC = $count_visit[0]->page_visit;
421
- }
422
- $html .='<td>'.$countC.'</td>';
423
- $html .='</tr>';
424
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  $html .='</tbody>
426
  <tfoot><tr>
427
  <th width="10%">No</th>
@@ -430,12 +440,12 @@ class page_visit_counter_Admin {
430
  <th width="20%">Total Count</th>
431
  </tr></tfoot></table>';
432
  echo $html;
433
- }else {
434
  if( $page_title != '' ){
435
  if($page_date){
436
- $string .= "wposts.post_title LIKE '".$page_title."%' AND ";
437
  }else{
438
- $string .= "wposts.post_title LIKE '".$page_title."%' ";
439
  }
440
  }
441
  if( $page_date != '' ){
@@ -446,9 +456,12 @@ class page_visit_counter_Admin {
446
  }
447
  }
448
  $clean = rtrim($string," AND ");
449
- $dataquery =$wpdb->get_results("SELECT DISTINCT wposts.* FROM $table_post wposts INNER JOIN $table_name ON (wposts.ID = $table_name.page_id) WHERE $clean");
450
- if(empty( $dataquery ) || $dataquery == ''){
451
- $notvisit =$wpdb->get_results("SELECT * from $table_post where post_title LIKE'".$page_title."%' AND post_status='publish' AND post_type='page'");
 
 
 
452
  $html .='<table id="example" class="display" cellpadding="0" cellspacing="0">
453
  <thead>
454
  <tr>
@@ -515,9 +528,13 @@ class page_visit_counter_Admin {
515
  } elseif ($page_date != '' ) {
516
  $count_visit = $wpdb->get_results("SELECT * from $table_name where page_id=$results->ID AND $remove");
517
  }
 
 
 
 
 
518
 
519
-
520
- $html .='<td>'.$count_visit[0]->page_visit.'</td>';
521
  $html .='</tr>';
522
  }
523
  $html .='</tbody><tfoot>
383
  $page_title = isset( $_POST['page_name'] ) ? $_POST['page_name'] : '';
384
  $page_date = isset( $_POST['page_date'] ) ? $_POST['page_date'] : '';
385
  $string ='';
386
+ if( $page_date == '' && $page_title =='' ) {
387
  $html .='<table id="example" class="display" cellpadding="0" cellspacing="0">
388
  <thead>
389
  <tr>
394
  </tr>
395
  </thead>
396
  <tbody>';
397
+ $postperpage = -1;
398
+ $post_types = get_post_types();
399
+ $posts_array = array();
400
+ if (isset($post_types) && !empty($post_types)) {
401
+ foreach ($post_types as $cpost) {
402
+ if($cpost != "attachment" && $cpost != "revision" && $cpost != "nav_menu_item" && $cpost != "product_variation" && $cpost != "shop_order" && $cpost != "shop_order_refund" && $cpost != "shop_coupon" && $cpost != "shop_webhook" && $cpost != "scheduled-action") {
403
+ $args = array(
404
+ 'post_type' => "$cpost",
405
+ 'post_status' => 'publish',
406
+ 'order' => 'ASC',
407
+ 'posts_per_page' => $postperpage,
408
+ );
409
+ $posts_array[] = get_posts( $args );
 
 
 
 
 
 
410
  }
411
+ }
412
+ }
413
+ $counter = 0;
414
+ foreach ( $posts_array as $result ) {
415
+ foreach ($result as $results) {
416
+ $counter = $counter + 1;
417
+ $html .='<tr>';
418
+ $html .='<td>'.$counter.'</td>';
419
+ $html .='<td>'.$results->ID.'</td>';
420
+ $html .='<td><a href="'.get_admin_url().'post.php?post='.$results->ID.'&action=edit">'.$results->post_title.'</a></td>';
421
+ $count_visit = $wpdb->get_results("SELECT SUM(page_visit) as page_visit from $table_name where page_id ='".$results->ID."'");
422
+ $count = 0;
423
+ foreach ( $count_visit as $countval){
424
+ $count = $count + 1;
425
+ }
426
+ if ($count_visit[0]->page_visit == '') {
427
+ $countC = 0;
428
+ } else {
429
+ $countC = $count_visit[0]->page_visit;
430
+ }
431
+ $html .='<td>'.$countC.'</td>';
432
+ $html .='</tr>';
433
+ }
434
+ }
435
  $html .='</tbody>
436
  <tfoot><tr>
437
  <th width="10%">No</th>
440
  <th width="20%">Total Count</th>
441
  </tr></tfoot></table>';
442
  echo $html;
443
+ } else {
444
  if( $page_title != '' ){
445
  if($page_date){
446
+ $string .= "wposts.post_title LIKE '$page_title%' AND ";
447
  }else{
448
+ $string .= "wposts.post_title LIKE '$page_title%' ";
449
  }
450
  }
451
  if( $page_date != '' ){
456
  }
457
  }
458
  $clean = rtrim($string," AND ");
459
+ $querySet = "SELECT DISTINCT wposts.* FROM $table_post wposts INNER JOIN $table_name ON (wposts.ID = $table_name.page_id) WHERE $clean";
460
+ //$querySet = "SELECT DISTINCT wposts.* FROM $table_post wposts WHERE $clean AND post_status='publish'";
461
+ $dataquery =$wpdb->get_results($querySet);
462
+ if(empty( $dataquery ) || $dataquery == ''){
463
+ $QUERY = "SELECT * from $table_post where post_title LIKE '$page_title%' AND post_status='publish'";
464
+ $notvisit = $wpdb->get_results($QUERY);
465
  $html .='<table id="example" class="display" cellpadding="0" cellspacing="0">
466
  <thead>
467
  <tr>
528
  } elseif ($page_date != '' ) {
529
  $count_visit = $wpdb->get_results("SELECT * from $table_name where page_id=$results->ID AND $remove");
530
  }
531
+ if ($count_visit[0]->page_visit == '') {
532
+ $countC = 0;
533
+ } else {
534
+ $countC = $count_visit[0]->page_visit;
535
+ }
536
 
537
+ $html .='<td>'.$countC.'</td>';
 
538
  $html .='</tr>';
539
  }
540
  $html .='</tbody><tfoot>
includes/class-page-visit-counter.php CHANGED
@@ -137,7 +137,12 @@ class page_visit_counter {
137
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
138
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
139
 
140
- //$this->loader->add_action( 'wp_ajax_insert_page_visit_counter', $plugin_public, 'insert_page_visit_counter' );
 
 
 
 
 
141
  $this->loader->add_action( 'wp', $plugin_public, 'insert_page_visit_counter' );
142
 
143
  $this->loader->add_filter( 'the_content', $plugin_public, 'insert_page_visit_counter_total_block',99 );
137
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
138
  $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
139
 
140
+ //$this->loader->add_action( 'wp_ajax_insert_page_visit_counter', $plugin_public, 'insert_page_visit_counter' );
141
+ //$this->loader->add_action( 'wp_ajax_nopriv_insert_page_visit_counter', $plugin_public, 'insert_page_visit_counter' );
142
+
143
+ $this->loader->add_action( 'wp_ajax_display_page_visit_counter_ajax', $plugin_public, 'display_page_visit_counter_ajax' );
144
+ $this->loader->add_action( 'wp_ajax_nopriv_display_page_visit_counter_ajax', $plugin_public, 'display_page_visit_counter_ajax' );
145
+
146
  $this->loader->add_action( 'wp', $plugin_public, 'insert_page_visit_counter' );
147
 
148
  $this->loader->add_filter( 'the_content', $plugin_public, 'insert_page_visit_counter_total_block',99 );
page_visit_counter.php CHANGED
@@ -7,7 +7,7 @@
7
  * Plugin URI: http://www.multidots.com/
8
  * Description: Plugin for show visited page
9
  * Author: Multidots
10
- * Version: 2.0.0
11
  * Author URI: http://www.multidots.com/
12
  */
13
  // If this file is called directly, abort.
@@ -63,63 +63,69 @@ function display_page_total_count($atts) {
63
  global $wpdb, $wp, $post;
64
 
65
 
66
- $pageID = $atts['id'];
67
 
68
- if ($pageID == '' || $pageID == null) {
 
 
69
 
70
- $pageID = get_the_ID();
71
-
72
- if ($pageID == 0) {
73
- $pageID = (int) get_option('page_on_front',true);
74
- if (empty($pageID) && !isset($pageID)) {
75
- $pageID = (int) get_option('page_for_posts',true);
76
- }
77
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- if ($pageID == 0) {
80
- $page = get_option('show_on_front',true);
81
- if ($page == 'posts') {
82
- $args = array(
83
- 'numberposts' => 1,
84
- 'orderby' => 'post_date',
85
- 'order' => 'DESC',
86
- 'post_type' => 'post',
87
- 'post_status' => 'publish',
88
- 'suppress_filters' => true );
89
-
90
- $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
91
- foreach( $recent_posts as $recent ){
92
- $pageID = (int) $recent["ID"];
93
  }
 
94
  }
95
-
 
96
  }
 
 
97
  }
98
 
99
- $post = get_post($pageID);
100
-
101
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
102
-
103
- $table_name = $wpdb->prefix."page_visit";
104
-
105
- $pageCount = $wpdb->get_results("SELECT SUM(page_visit) as total FROM $table_name WHERE `page_id` = $pageID");
106
-
107
- $total = (int) $pageCount[0]->total;
108
-
109
- $html = '';
110
-
111
- if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
112
- $html .= '<p class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /> '.$total.' total views.</p>';
113
- } else {
114
- $postTypeSelectedEncodeArr = json_decode($fetchSelecetedPostTypes);
115
- if (in_array($post->post_type,$postTypeSelectedEncodeArr)) {
116
- $innerSettings = get_post_meta($pageID,'get_page_count',true);
117
- if ($innerSettings == '' || $innerSettings == 'yes') {
118
- $html .= '<p class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /> '.$total.' total views.</p>';
119
- }
120
- }
121
- }
122
-
123
  echo $html;
124
  //echo $pageID;
125
 
7
  * Plugin URI: http://www.multidots.com/
8
  * Description: Plugin for show visited page
9
  * Author: Multidots
10
+ * Version: 2.0.1
11
  * Author URI: http://www.multidots.com/
12
  */
13
  // If this file is called directly, abort.
63
  global $wpdb, $wp, $post;
64
 
65
 
66
+ $pageID = (int) $atts['id'];
67
 
68
+ $html = '';
69
+
70
+ if ($pageID != '' && is_int($pageID)) {
71
 
72
+ // $pageID = get_the_ID();
73
+ //
74
+ // if ($pageID == 0) {
75
+ // $pageID = (int) get_option('page_on_front',true);
76
+ // if (empty($pageID) && !isset($pageID)) {
77
+ // $pageID = (int) get_option('page_for_posts',true);
78
+ // }
79
+ // }
80
+ //
81
+ // if ($pageID == 0) {
82
+ // $page = get_option('show_on_front',true);
83
+ // if ($page == 'posts') {
84
+ // $args = array(
85
+ // 'numberposts' => 1,
86
+ // 'orderby' => 'post_date',
87
+ // 'order' => 'DESC',
88
+ // 'post_type' => 'post',
89
+ // 'post_status' => 'publish',
90
+ // 'suppress_filters' => true );
91
+ //
92
+ // $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
93
+ // foreach( $recent_posts as $recent ){
94
+ // $pageID = (int) $recent["ID"];
95
+ // }
96
+ // }
97
+ //
98
+ // }
99
+
100
+ $post = get_post($pageID);
101
+
102
+ if (isset($post) && !empty($post) && $post != null) {
103
+ $fetchSelecetedPostTypes = get_option('wfap_post_type');
104
+
105
+ $table_name = $wpdb->prefix."page_visit";
106
 
107
+ $pageCount = $wpdb->get_results("SELECT SUM(page_visit) as total FROM $table_name WHERE `page_id` = $pageID");
108
+
109
+ $total = (int) $pageCount[0]->total;
110
+
111
+ if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
112
+ $html .= '<p id="page-visit-counter-shortcode-block" class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /><span id="shortcode_'.$pageID.'" style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_shortcode">'.$total.'</span>total views.</p>';
113
+ } else {
114
+ $postTypeSelectedEncodeArr = json_decode($fetchSelecetedPostTypes);
115
+ if (in_array($post->post_type,$postTypeSelectedEncodeArr)) {
116
+ $innerSettings = get_post_meta($pageID,'get_page_count',true);
117
+ if ($innerSettings == '' || $innerSettings == 'yes') {
118
+ $html .= '<p id="page-visit-counter-shortcode-block" class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /><span id="shortcode_'.$pageID.'" style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_shortcode">'.$total.'</span>total views.</p>';
 
 
119
  }
120
+ }
121
  }
122
+ } else {
123
+ $html .= 'Please enter the valid post or page id.';
124
  }
125
+ } else {
126
+ $html .= 'Please enter the valid post or page id.';
127
  }
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  echo $html;
130
  //echo $pageID;
131
 
public/class-page-visit-counter-public.php CHANGED
@@ -86,8 +86,10 @@ class page_visit_counter_Public {
86
  */
87
 
88
  public function insert_page_visit_counter() {
89
- global $wpdb, $wp, $post;
90
- $pageurl = $_POST['pageurl'];
 
 
91
 
92
  // Check the site running on HTTPS. If the site running on HTTPS then we are removing S from HTTPS
93
  if (is_ssl()) {
@@ -98,139 +100,85 @@ class page_visit_counter_Public {
98
  $page = url_to_postid( $actual_link );
99
  }
100
 
101
-
102
- if ($page == 0) {
103
- $page = (int) get_option('page_on_front',true);
104
- if (empty($page) && !isset($page)) {
105
- $page = (int) get_option('page_for_posts',true);
106
- }
107
- }
108
-
109
  if ($page == 0) {
110
- $page = get_option('show_on_front',true);
111
- if ($page == 'posts') {
112
- $args = array(
113
- 'numberposts' => 1,
114
- 'orderby' => 'post_date',
115
- 'order' => 'DESC',
116
- 'post_type' => 'post',
117
- 'post_status' => 'publish',
118
- 'suppress_filters' => true );
119
-
120
- $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
121
- foreach( $recent_posts as $recent ){
122
- $page = (int) $recent["ID"];
 
123
  }
 
124
  }
125
-
126
  }
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
- $table_name = $wpdb->prefix."page_visit";
130
- $last_date = '';
131
- $page_contet = get_post( $page );
132
-
133
- $currentdate= date("Y-m-d");
134
- $ipaddress = $_SERVER['REMOTE_ADDR'];
135
-
136
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
137
- $postTypeSelectedDecodeArr = !empty( $fetchSelecetedPostTypes ) ? $fetchSelecetedPostTypes : json_encode( array() );
138
-
139
-
140
- $fetchSelecetedIpAddress = get_option('ipaddress_visit');
141
- $optionsIpAddressDecodedArr = !empty( $fetchSelecetedIpAddress ) ? $fetchSelecetedIpAddress : json_encode( array() );
142
-
143
-
144
- $fetchSelecetedUserId = get_option('userlist_visit');
145
- $optionsUserIdDecodedArr = !empty( $fetchSelecetedUserId ) ? $fetchSelecetedUserId : json_encode( array() );
146
 
147
-
148
- $pageCount = $wpdb->get_results("SELECT * from $table_name where page_id=$page AND ipaddress = '$ipaddress' AND date = '$currentdate' LIMIT 1");
149
-
150
- $getPageSetting = get_post_meta($page,'get_page_count',true);
151
-
152
- // old version plugin
153
- if ($fetchSelecetedPostTypes == '') {
154
 
155
- // Check current page/post metabox settings is blank OR selected value is yes
156
- if ($getPageSetting == '' || $getPageSetting == 'yes') {
157
 
158
- // Check IP Address set in settings page if yes
159
- if (isset($fetchSelecetedIpAddress) && !empty($fetchSelecetedIpAddress)) {
160
- $optionsIpAddressEncodeArr = json_decode($optionsIpAddressDecodedArr);
161
- // Check IP Address not listed in settings page then go ahed
162
- if (!in_array($ipaddress,$optionsIpAddressEncodeArr)) {
163
-
164
- // Check users set in settings page if yes
165
- if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
166
-
167
- $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
168
- $user_id = get_current_user_id();
169
-
170
- // Check user not listed in settings page then go ahed
171
- if (!in_array($user_id,$optionsUserIdEncodeArr)) {
172
-
173
- if (isset($pageCount) && !empty($pageCount)) {
174
- $existingtotal = (int) $pageCount[0]->page_visit;
175
- $totalFinal = $existingtotal + 1;
176
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
177
- } else {
178
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
179
- }
180
- }
181
- } else {
182
- if (isset($pageCount) && !empty($pageCount)) {
183
- $existingtotal = (int) $pageCount[0]->page_visit;
184
- $totalFinal = $existingtotal + 1;
185
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
186
- } else {
187
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
188
- }
189
- }
190
- }
191
- } else {
192
- if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
193
-
194
- $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
195
- $user_id = get_current_user_id();
196
-
197
- // Check user not listed in settings page then go ahed
198
- if (!in_array($user_id,$optionsUserIdEncodeArr)) {
199
-
200
- if (isset($pageCount) && !empty($pageCount)) {
201
- $existingtotal = (int) $pageCount[0]->page_visit;
202
- $totalFinal = $existingtotal + 1;
203
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
204
- } else {
205
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
206
- }
207
- }
208
- } else {
209
- if (isset($pageCount) && !empty($pageCount)) {
210
- $existingtotal = (int) $pageCount[0]->page_visit;
211
- $totalFinal = $existingtotal + 1;
212
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
213
- } else {
214
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
215
- }
216
- }
217
- }
218
- }
219
 
220
- } else {
221
 
222
- $postTypeSelectedEncodeArr = json_decode($postTypeSelectedDecodeArr);
 
 
 
 
 
 
 
 
 
223
  $getPageSetting = get_post_meta($page,'get_page_count',true);
224
 
225
- // Check current page/post type exist in settings page array
226
- if (in_array($page_contet->post_type,$postTypeSelectedEncodeArr)) {
227
 
228
  // Check current page/post metabox settings is blank OR selected value is yes
229
  if ($getPageSetting == '' || $getPageSetting == 'yes') {
230
-
231
  // Check IP Address set in settings page if yes
232
  if (isset($fetchSelecetedIpAddress) && !empty($fetchSelecetedIpAddress)) {
233
-
234
  $optionsIpAddressEncodeArr = json_decode($optionsIpAddressDecodedArr);
235
  // Check IP Address not listed in settings page then go ahed
236
  if (!in_array($ipaddress,$optionsIpAddressEncodeArr)) {
@@ -263,9 +211,8 @@ class page_visit_counter_Public {
263
  }
264
  }
265
  } else {
266
- // Check users set in settings page if yes
267
  if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
268
-
269
  $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
270
  $user_id = get_current_user_id();
271
 
@@ -291,21 +238,95 @@ class page_visit_counter_Public {
291
  }
292
  }
293
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  }
295
  }
296
  }
297
 
298
-
299
-
300
- public function insert_page_visit_counter_total_block($content) {
301
  global $wpdb, $wp, $post;
302
 
 
 
303
  if (is_ssl()) {
304
- $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
305
- $pageID = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$actual_link));
306
  } else {
307
- $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
308
- $pageID = url_to_postid( $actual_link );
309
  }
310
 
311
  if ($pageID == 0) {
@@ -343,23 +364,81 @@ class page_visit_counter_Public {
343
  $pageCount = $wpdb->get_results("SELECT SUM(page_visit) as total FROM $table_name WHERE `page_id` = $pageID");
344
 
345
  $total = (int) $pageCount[0]->total;
 
 
346
 
347
- $html = '';
 
 
 
 
 
348
 
349
- if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
350
- $html .= '<p class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /> '.$total.' total views.</p>';
 
351
  } else {
352
- $postTypeSelectedEncodeArr = json_decode($fetchSelecetedPostTypes);
353
- if (in_array($post->post_type,$postTypeSelectedEncodeArr)) {
354
- $innerSettings = get_post_meta($pageID,'get_page_count',true);
355
- if ($innerSettings == '' || $innerSettings == 'yes') {
356
- $html .= '<p class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /> '.$total.' total views.</p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  }
358
  }
 
 
 
 
359
  }
360
 
361
- return $content.' '.$html;
362
-
363
  }
364
 
365
  /**
86
  */
87
 
88
  public function insert_page_visit_counter() {
89
+ global $wpdb, $wp, $post, $wp_query;
90
+
91
+ //$pageurl = $_POST['pageurl'];
92
+
93
 
94
  // Check the site running on HTTPS. If the site running on HTTPS then we are removing S from HTTPS
95
  if (is_ssl()) {
100
  $page = url_to_postid( $actual_link );
101
  }
102
 
 
 
 
 
 
 
 
 
103
  if ($page == 0) {
104
+ $page = get_the_ID();
105
+ if ($page == 0) {
106
+ $current_url = home_url( $wp->request );
107
+ if (is_ssl()) {
108
+ $page = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$current_url));
109
+ } else {
110
+ $page = url_to_postid( $current_url );
111
+ }
112
+ if ($page == 0) {
113
+ $queried_object = get_queried_object();
114
+
115
+ if ( $queried_object ) {
116
+ $post_id = $queried_object->ID;
117
+ $page = $post_id;
118
  }
119
+ }
120
  }
 
121
  }
122
 
123
+ // if ($page == 0) {
124
+ // $page = (int) get_option('page_on_front',true);
125
+ // if (empty($page) && !isset($page)) {
126
+ // $page = (int) get_option('page_for_posts',true);
127
+ // }
128
+ // }
129
+ //
130
+ // if ($page == 0) {
131
+ // $page = get_option('show_on_front',true);
132
+ // if ($page == 'posts') {
133
+ // $args = array(
134
+ // 'numberposts' => 1,
135
+ // 'orderby' => 'post_date',
136
+ // 'order' => 'DESC',
137
+ // 'post_type' => 'post',
138
+ // 'post_status' => 'publish',
139
+ // 'suppress_filters' => true );
140
+ //
141
+ // $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
142
+ // foreach( $recent_posts as $recent ){
143
+ // $page = (int) $recent["ID"];
144
+ // }
145
+ // }
146
+ //
147
+ // }
148
 
149
+ if ($page != 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ $table_name = $wpdb->prefix."page_visit";
152
+ $last_date = '';
153
+ $page_contet = get_post( $page );
 
 
 
 
154
 
155
+ $currentdate= date("Y-m-d");
156
+ $ipaddress = $_SERVER['REMOTE_ADDR'];
157
 
158
+ $fetchSelecetedPostTypes = get_option('wfap_post_type');
159
+ $postTypeSelectedDecodeArr = !empty( $fetchSelecetedPostTypes ) ? $fetchSelecetedPostTypes : json_encode( array() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
 
161
 
162
+ $fetchSelecetedIpAddress = get_option('ipaddress_visit');
163
+ $optionsIpAddressDecodedArr = !empty( $fetchSelecetedIpAddress ) ? $fetchSelecetedIpAddress : json_encode( array() );
164
+
165
+
166
+ $fetchSelecetedUserId = get_option('userlist_visit');
167
+ $optionsUserIdDecodedArr = !empty( $fetchSelecetedUserId ) ? $fetchSelecetedUserId : json_encode( array() );
168
+
169
+
170
+ $pageCount = $wpdb->get_results("SELECT * from $table_name where page_id=$page AND ipaddress = '$ipaddress' AND date = '$currentdate' LIMIT 1");
171
+
172
  $getPageSetting = get_post_meta($page,'get_page_count',true);
173
 
174
+ // old version plugin
175
+ if ($fetchSelecetedPostTypes == '') {
176
 
177
  // Check current page/post metabox settings is blank OR selected value is yes
178
  if ($getPageSetting == '' || $getPageSetting == 'yes') {
179
+
180
  // Check IP Address set in settings page if yes
181
  if (isset($fetchSelecetedIpAddress) && !empty($fetchSelecetedIpAddress)) {
 
182
  $optionsIpAddressEncodeArr = json_decode($optionsIpAddressDecodedArr);
183
  // Check IP Address not listed in settings page then go ahed
184
  if (!in_array($ipaddress,$optionsIpAddressEncodeArr)) {
211
  }
212
  }
213
  } else {
 
214
  if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
215
+
216
  $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
217
  $user_id = get_current_user_id();
218
 
238
  }
239
  }
240
  }
241
+
242
+ } else {
243
+
244
+ $postTypeSelectedEncodeArr = json_decode($postTypeSelectedDecodeArr);
245
+ $getPageSetting = get_post_meta($page,'get_page_count',true);
246
+
247
+ // Check current page/post type exist in settings page array
248
+ if (in_array($page_contet->post_type,$postTypeSelectedEncodeArr)) {
249
+
250
+ // Check current page/post metabox settings is blank OR selected value is yes
251
+ if ($getPageSetting == '' || $getPageSetting == 'yes') {
252
+
253
+ // Check IP Address set in settings page if yes
254
+ if (isset($fetchSelecetedIpAddress) && !empty($fetchSelecetedIpAddress)) {
255
+
256
+ $optionsIpAddressEncodeArr = json_decode($optionsIpAddressDecodedArr);
257
+ // Check IP Address not listed in settings page then go ahed
258
+ if (!in_array($ipaddress,$optionsIpAddressEncodeArr)) {
259
+
260
+ // Check users set in settings page if yes
261
+ if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
262
+
263
+ $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
264
+ $user_id = get_current_user_id();
265
+
266
+ // Check user not listed in settings page then go ahed
267
+ if (!in_array($user_id,$optionsUserIdEncodeArr)) {
268
+
269
+ if (isset($pageCount) && !empty($pageCount)) {
270
+ $existingtotal = (int) $pageCount[0]->page_visit;
271
+ $totalFinal = $existingtotal + 1;
272
+ $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
273
+ } else {
274
+ $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
275
+ }
276
+ }
277
+ } else {
278
+ if (isset($pageCount) && !empty($pageCount)) {
279
+ $existingtotal = (int) $pageCount[0]->page_visit;
280
+ $totalFinal = $existingtotal + 1;
281
+ $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
282
+ } else {
283
+ $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
284
+ }
285
+ }
286
+ }
287
+ } else {
288
+ // Check users set in settings page if yes
289
+ if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
290
+
291
+ $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
292
+ $user_id = get_current_user_id();
293
+
294
+ // Check user not listed in settings page then go ahed
295
+ if (!in_array($user_id,$optionsUserIdEncodeArr)) {
296
+
297
+ if (isset($pageCount) && !empty($pageCount)) {
298
+ $existingtotal = (int) $pageCount[0]->page_visit;
299
+ $totalFinal = $existingtotal + 1;
300
+ $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
301
+ } else {
302
+ $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
303
+ }
304
+ }
305
+ } else {
306
+ if (isset($pageCount) && !empty($pageCount)) {
307
+ $existingtotal = (int) $pageCount[0]->page_visit;
308
+ $totalFinal = $existingtotal + 1;
309
+ $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
310
+ } else {
311
+ $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
  }
318
  }
319
  }
320
 
321
+ public function display_page_visit_counter_ajax() {
 
 
322
  global $wpdb, $wp, $post;
323
 
324
+ $pageurl = $_POST['pageurl'];
325
+
326
  if (is_ssl()) {
327
+ $pageID = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$pageurl));
 
328
  } else {
329
+ $pageID = url_to_postid( $pageurl );
 
330
  }
331
 
332
  if ($pageID == 0) {
364
  $pageCount = $wpdb->get_results("SELECT SUM(page_visit) as total FROM $table_name WHERE `page_id` = $pageID");
365
 
366
  $total = (int) $pageCount[0]->total;
367
+
368
+ echo $total;
369
 
370
+ die();
371
+
372
+ }
373
+
374
+ public function insert_page_visit_counter_total_block($content) {
375
+ global $wpdb, $wp, $post;
376
 
377
+ if (is_ssl()) {
378
+ $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
379
+ $pageID = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$actual_link));
380
  } else {
381
+ $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
382
+ $pageID = url_to_postid( $actual_link );
383
+ }
384
+
385
+ // if ($pageID == 0) {
386
+ // $pageID = (int) get_option('page_on_front',true);
387
+ // if (empty($pageID) && !isset($pageID)) {
388
+ // $pageID = (int) get_option('page_for_posts',true);
389
+ // }
390
+ // }
391
+ //
392
+ // if ($pageID == 0) {
393
+ // $page = get_option('show_on_front',true);
394
+ // if ($page == 'posts') {
395
+ // $args = array(
396
+ // 'numberposts' => 1,
397
+ // 'orderby' => 'post_date',
398
+ // 'order' => 'DESC',
399
+ // 'post_type' => 'post',
400
+ // 'post_status' => 'publish',
401
+ // 'suppress_filters' => true );
402
+ //
403
+ // $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
404
+ // foreach( $recent_posts as $recent ){
405
+ // $pageID = (int) $recent["ID"];
406
+ // }
407
+ // }
408
+ //
409
+ // }
410
+
411
+ if ($pageID != 0) {
412
+
413
+ $post = get_post($pageID);
414
+
415
+ $fetchSelecetedPostTypes = get_option('wfap_post_type');
416
+
417
+ $table_name = $wpdb->prefix."page_visit";
418
+
419
+ $pageCount = $wpdb->get_results("SELECT SUM(page_visit) as total FROM $table_name WHERE `page_id` = $pageID");
420
+
421
+ $total = (int) $pageCount[0]->total;
422
+
423
+ $html = '';
424
+
425
+ if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
426
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.$total.'</span>total views.</p>';
427
+ } else {
428
+ $postTypeSelectedEncodeArr = json_decode($fetchSelecetedPostTypes);
429
+ if (in_array($post->post_type,$postTypeSelectedEncodeArr)) {
430
+ $innerSettings = get_post_meta($pageID,'get_page_count',true);
431
+ if ($innerSettings == '' || $innerSettings == 'yes') {
432
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block"><img src="'.site_url().'/wp-content/plugins/page-visit-counter/images/1456175371_vector_65_14.png" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.$total.'</span>total views.</p>';
433
+ }
434
  }
435
  }
436
+
437
+ return $content.' '.$html;
438
+ } else {
439
+ return $content;
440
  }
441
 
 
 
442
  }
443
 
444
  /**
public/js/custom.js CHANGED
@@ -1,10 +1,12 @@
1
  (function( $ ) {
2
 
3
  $(window).bind("load", function() {
 
4
  //var pageurl = '2';
5
  $.ajax({
6
  type: 'POST',
7
  url: pagevisit.ajaxurl,
 
8
  data: {
9
  action : 'insert_page_visit_counter',
10
  pageurl : pagevisit.pageurl
@@ -13,6 +15,24 @@
13
 
14
  }
15
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  });
17
 
18
  $('form').each(function(){
1
  (function( $ ) {
2
 
3
  $(window).bind("load", function() {
4
+ //$( document ).ready(function() {
5
  //var pageurl = '2';
6
  $.ajax({
7
  type: 'POST',
8
  url: pagevisit.ajaxurl,
9
+ async : false,
10
  data: {
11
  action : 'insert_page_visit_counter',
12
  pageurl : pagevisit.pageurl
15
 
16
  }
17
  });
18
+
19
+ $.ajax({
20
+ type: 'POST',
21
+ url: pagevisit.ajaxurl,
22
+ async : false,
23
+ data: {
24
+ action : 'display_page_visit_counter_ajax',
25
+ pageurl : pagevisit.pageurl
26
+ },
27
+ success: function( data ) {
28
+ if ($('#default-loop-page-visit-counter').length){
29
+ if(data != '') {
30
+ $('#default-loop-page-visit-counter .page_amount_visitor').text(data);
31
+ }
32
+ }
33
+ }
34
+ });
35
+
36
  });
37
 
38
  $('form').each(function(){