Page Visit Counter - Version 4.7

Version Description

  • 10-08-2018 =
  • minor bug fixed.
Download this release

Release Info

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

Code changes from version 4.6 to 4.7

README.txt CHANGED
@@ -4,7 +4,7 @@ Plugin URI: http://multidots.com/
4
  Author: Multidots
5
  Author URI: http://multidots.com/
6
  Contributors: dots, ketuchetan, chiragpatel, jitendrabanjara1991, thedotstore
7
- Stable tag: 4.6
8
  Tags: page counter,page visit, post counter, post visit, wordpress post view, wordpress page view, page visit graph, post visit graph,
9
  Requires at least: 2.1
10
  Tested up to: 4.9.6
@@ -115,6 +115,9 @@ Automatic updates should work great for you. As always, though, we recommend ba
115
 
116
  == Changelog ==
117
 
 
 
 
118
  = 4.6 - 14-06-2018 =
119
  * Fixed language issue.
120
 
4
  Author: Multidots
5
  Author URI: http://multidots.com/
6
  Contributors: dots, ketuchetan, chiragpatel, jitendrabanjara1991, thedotstore
7
+ Stable tag: 4.7
8
  Tags: page counter,page visit, post counter, post visit, wordpress post view, wordpress page view, page visit graph, post visit graph,
9
  Requires at least: 2.1
10
  Tested up to: 4.9.6
115
 
116
  == Changelog ==
117
 
118
+ = 4.7 - 10-08-2018 =
119
+ * minor bug fixed.
120
+
121
  = 4.6 - 14-06-2018 =
122
  * Fixed language issue.
123
 
page_visit_counter.php CHANGED
@@ -7,7 +7,7 @@
7
  * Plugin URI: http://www.multidots.com/
8
  * Description: This plugin will count the total visits of your sites pages.
9
  * Author: Multidots
10
- * Version: 4.6
11
  * Author URI: http://www.multidots.com/
12
  */
13
  // If this file is called directly, abort.
7
  * Plugin URI: http://www.multidots.com/
8
  * Description: This plugin will count the total visits of your sites pages.
9
  * Author: Multidots
10
+ * Version: 4.7
11
  * Author URI: http://www.multidots.com/
12
  */
13
  // If this file is called directly, abort.
public/class-page-visit-counter-public.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  // If this file is called directly, abort.
3
- if ( !defined( 'ABSPATH' ) ) {
4
- exit;
5
  }
6
  /**
7
  * The admin-specific functionality of the plugin.
@@ -25,559 +25,553 @@ if ( !defined( 'ABSPATH' ) ) {
25
  */
26
  class page_visit_counter_Public {
27
 
28
- /**
29
- * The ID of this plugin.
30
- *
31
- * @since 1.0.0
32
- * @access private
33
- * @var string $plugin_name The ID of this plugin.
34
- */
35
- private $plugin_name;
36
-
37
- /**
38
- * The version of this plugin.
39
- *
40
- * @since 1.0.0
41
- * @access private
42
- * @var string $version The current version of this plugin.
43
- */
44
- private $version;
45
-
46
- /**
47
- * Initialize the class and set its properties.
48
- *
49
- * @since 1.0.0
50
- * @param string $plugin_name The name of this plugin.
51
- * @param string $version The version of this plugin.
52
- */
53
- public function __construct( $plugin_name, $version ) {
54
-
55
- $this->plugin_name = $plugin_name;
56
- $this->version = $version;
57
-
58
- }
59
- /**
60
- * Register the stylesheets for the admin area.
61
- *
62
- * @since 1.0.0
63
- */
64
- public function enqueue_styles() {
65
- global $wp;
66
-
67
- wp_enqueue_style('counter-style', plugin_dir_url( __FILE__ ) . 'css/counter-style.css');
68
-
69
- }
70
- /**
71
- * Register the JavaScript for the admin area.
72
- *
73
- * @since 1.0.0
74
- */
75
- public function enqueue_scripts() {
76
- global $wp;
77
- wp_enqueue_script('one', plugin_dir_url( __FILE__ ) . 'js/custom.js', array( 'jquery' ), $this->version, false );
78
- $current_url = home_url( $wp->request );
79
- wp_localize_script( 'one', 'pagevisit', array(
80
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
81
- 'pageurl' => $current_url,
82
- ) );
83
-
84
- }
85
-
86
- /**
87
- * action use in call header
88
- * Insert_page_visit_counter function use insert the page data
89
- * pageid,Currentdate,Ipaddress,pagecount add in database.
90
- */
91
-
92
- public function insert_page_visit_counter() {
93
- global $wpdb, $wp, $post, $wp_query;
94
-
95
- $flag = 0;
96
- // Check the site running on HTTPS. If the site running on HTTPS then we are removing S from HTTPS
97
- if (is_ssl()) {
98
- $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
99
- if (strpos($actual_link,'wp-admin') !== false) {
100
- $page = 0;
101
- $flag = 1;
102
- } else {
103
- $page = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',esc_url($actual_link)));
104
- }
105
- } else {
106
- $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
107
- if (strpos($actual_link,'wp-admin') !== false) {
108
- $page = 0;
109
- $flag = 1;
110
- } else {
111
- $page = url_to_postid( esc_url($actual_link) );
112
- }
113
- }
114
- $pageID = $page;
115
- if( in_array( 'woocommerce/woocommerce.php',apply_filters('active_plugins',get_option('active_plugins'))) ) {
116
- if( is_shop() ){
117
- $page = (int) get_option( 'woocommerce_shop_page_id' );
118
- }
119
- if ( is_cart() ) {
120
- $page = (int) get_option( 'woocommerce_cart_page_id' );
121
- }
122
- if( is_checkout() ){
123
- $page = (int) get_option( 'woocommerce_checkout_page_id' );
124
-
125
- }
126
- }
127
-
128
-
129
- if ($flag == 0) {
130
-
131
- if ($page == 0) {
132
- $page = get_the_ID();
133
- if ($page == 0) {
134
- $current_url = home_url( $wp->request );
135
- if (is_ssl()) {
136
- $page = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$current_url));
137
- } else {
138
- $page = url_to_postid( $current_url );
139
- }
140
- if ($page == 0) {
141
- $queried_object = get_queried_object();
142
-
143
- if ( $queried_object ) {
144
- $post_id = $queried_object->ID;
145
- $page = $post_id;
146
- }
147
- }
148
- }
149
- }
150
- }
151
-
152
- if ($page != 0) {
153
-
154
-
155
- $table_name = $wpdb->prefix."page_visit";
156
- $table_name_history = $wpdb->prefix . "page_visit_history";
157
- $last_date = '';
158
- $page_contet = get_post( $page );
159
-
160
- $currentdate= date("Y-m-d");
161
- $ipaddress = $_SERVER['REMOTE_ADDR'];
162
-
163
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
164
- if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
165
- $post_types = get_post_types();
166
- $postArr = array();
167
- if (isset($post_types) && !empty($post_types)) {
168
- foreach ($post_types as $cpost) {
169
- 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" && $cpost != "shop_subscription"&& $cpost != "wpcf7_contact_form"&& $cpost != "mc4wp-form") {
170
- $postArr[] = $cpost;
171
- }
172
- }
173
- }
174
-
175
- delete_option('wfap_post_type');
176
- if (isset($postArr) && $postArr != null) {
177
- update_option('wfap_post_type',json_encode(array_values($postArr)));
178
- }
179
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
180
- }
181
-
182
- $postTypeSelectedDecodeArr = !empty( $fetchSelecetedPostTypes ) ? $fetchSelecetedPostTypes : json_encode( array() );
183
-
184
-
185
- $fetchSelecetedIpAddress = get_option('ipaddress_visit');
186
- $optionsIpAddressDecodedArr = !empty( $fetchSelecetedIpAddress ) ? $fetchSelecetedIpAddress : json_encode( array() );
187
-
188
-
189
- $fetchSelecetedUserId = get_option('userlist_visit');
190
- $optionsUserIdDecodedArr = !empty( $fetchSelecetedUserId ) ? $fetchSelecetedUserId : json_encode( array() );
191
-
192
- $pageCount_limit = intval(1);
193
- $pageCount_qry = $wpdb->prepare('SELECT * FROM ' . $table_name . ' WHERE page_id=%d AND ipaddress=%s AND date=%s LIMIT %d', $page, $ipaddress, $currentdate, $pageCount_limit);
194
- $pageCount = $wpdb->get_results($pageCount_qry);
195
-
196
- $getPageSetting = get_post_meta($page,'enable_page_count',true);
197
-
198
- $u_agent = $_SERVER['HTTP_USER_AGENT'];
199
-
200
- $bname = 'Unknown';
201
- $platform = 'Unknown';
202
- $version= "";
203
- $ub= "";
204
-
205
- //First get the platform?
206
- if (preg_match('/linux/i', $u_agent)) {
207
- $platform = 'linux';
208
- }
209
- elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
210
- $platform = 'mac';
211
- }
212
- elseif (preg_match('/windows|win32/i', $u_agent)) {
213
- $platform = 'windows';
214
- }
215
-
216
- // Next get the name of the useragent yes seperately and for good reason
217
- if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
218
- {
219
- $bname = 'Internet Explorer';
220
- $ub = "MSIE";
221
- }
222
- elseif(preg_match('/Firefox/i',$u_agent))
223
- {
224
- $bname = 'Mozilla Firefox';
225
- $ub = "Firefox";
226
- }
227
- elseif(preg_match('/Chrome/i',$u_agent))
228
- {
229
- $bname = 'Google Chrome';
230
- $ub = "Chrome";
231
- }
232
- elseif(preg_match('/Safari/i',$u_agent))
233
- {
234
- $bname = 'Apple Safari';
235
- $ub = "Safari";
236
- }
237
- elseif(preg_match('/Opera/i',$u_agent))
238
- {
239
- $bname = 'Opera';
240
- $ub = "Opera";
241
- }
242
- elseif(preg_match('/Netscape/i',$u_agent))
243
- {
244
- $bname = 'Netscape';
245
- $ub = "Netscape";
246
- }
247
-
248
-
249
- // finally get the correct version number
250
- $known = array('Version', $ub, 'other');
251
- $pattern = '#(?<browser>' . join('|', $known) .
252
- ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
253
- if (!preg_match_all($pattern, $u_agent, $matches)) {
254
- // we have no matching number just continue
255
- }
256
-
257
- // see how many we have
258
- $i = count($matches['browser']);
259
- if ($i != 1) {
260
- //we will have two since we are not using 'other' argument yet
261
- //see if version is before or after the name
262
- if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
263
- $version= $matches['version'][0];
264
- }
265
- else {
266
- $version= isset($matches['version'][1]) ? $matches['version'][1] : null;;
267
- }
268
- }
269
- else {
270
- $version= isset($matches['version'][0]) ? $matches['version'][0] : null;;
271
- }
272
-
273
- // check if we have a number
274
- if ($version==null || $version=="") {$version="?";}
275
-
276
- $http_referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] :'';
277
-
278
- // old version plugin
279
- if ($fetchSelecetedPostTypes != '') {
280
-
281
- $postTypeSelectedEncodeArr = json_decode($postTypeSelectedDecodeArr);
282
- $getPageSetting = get_post_meta($page,'enable_page_count',true);
283
-
284
- // Check current page/post type exist in settings page array
285
- if (in_array($page_contet->post_type,$postTypeSelectedEncodeArr)) {
286
-
287
- // Check current page/post metabox settings is blank OR selected value is yes
288
- if ($getPageSetting == '' || $getPageSetting == 'yes') {
289
-
290
- // Check IP Address set in settings page if yes
291
- if (isset($fetchSelecetedIpAddress) && !empty($fetchSelecetedIpAddress)) {
292
-
293
- $optionsIpAddressEncodeArr = json_decode($optionsIpAddressDecodedArr);
294
- // Check IP Address not listed in settings page then go ahed
295
- if (!in_array($ipaddress,$optionsIpAddressEncodeArr)) {
296
-
297
- // Check users set in settings page if yes
298
- if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
299
-
300
- $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
301
- $user_id = get_current_user_id();
302
-
303
- // Check user not listed in settings page then go ahed
304
- if (!in_array($user_id,$optionsUserIdEncodeArr)) {
305
-
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
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
311
- } else {
312
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
313
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
314
- }
315
- }
316
- } else {
317
- if (isset($pageCount) && !empty($pageCount)) {
318
- $existingtotal = (int) $pageCount[0]->page_visit;
319
- $totalFinal = $existingtotal + 1;
320
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
321
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
322
- } else {
323
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
324
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
325
- }
326
- }
327
- }
328
- } else {
329
- // Check users set in settings page if yes
330
- if (isset($fetchSelecetedUserId) && !empty($fetchSelecetedUserId)) {
331
-
332
- $optionsUserIdEncodeArr = json_decode($optionsUserIdDecodedArr);
333
- $user_id = get_current_user_id();
334
-
335
- // Check user not listed in settings page then go ahed
336
- if (!in_array($user_id,$optionsUserIdEncodeArr)) {
337
-
338
- if (isset($pageCount) && !empty($pageCount)) {
339
- $existingtotal = (int) $pageCount[0]->page_visit;
340
- $totalFinal = $existingtotal + 1;
341
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
342
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
343
- } else {
344
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
345
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
346
- }
347
- }
348
- } else {
349
- if (isset($pageCount) && !empty($pageCount)) {
350
- $existingtotal = (int) $pageCount[0]->page_visit;
351
- $totalFinal = $existingtotal + 1;
352
- $update_Query = $wpdb->query("UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='".$page."' AND ipaddress='$ipaddress' AND date = '$currentdate'");
353
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
354
- } else {
355
- $insert_Query = $wpdb->query("INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')");
356
- $insert_Query_history = $wpdb->query("INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')");
357
- }
358
- }
359
- }
360
- }
361
- }
362
- }
363
- }
364
-
365
- }
366
-
367
- public function display_page_visit_counter_ajax() {
368
- global $wpdb, $wp, $post;
369
-
370
- $pageurl = sanitize_text_field(wp_unslash($_POST['pageurl']));
371
-
372
- if (is_ssl()) {
373
- $pageID = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$pageurl));
374
- } else {
375
- $pageID = url_to_postid( $pageurl );
376
- }
377
-
378
- if (strpos($pageurl,'/shop') !== false && $pageID == 0 ) {
379
- $pageID = (int) get_option( 'woocommerce_shop_page_id' );
380
- }
381
-
382
- $post = get_post($pageID);
383
-
384
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
385
-
386
- $table_name = $wpdb->prefix."page_visit";
387
-
388
- $pageCount_qry = $wpdb->prepare('SELECT SUM(page_visit) as total FROM ' . $table_name . ' WHERE page_id=%d', $pageID);
389
- $pageCount = $wpdb->get_results($pageCount_qry);
390
-
391
- $table_name_history = $wpdb->prefix."page_visit_history";
392
-
393
- $pageCountToday_qry = $wpdb->prepare('SELECT COUNT(page_id) as total FROM ' . $table_name_history . ' WHERE page_id=%d AND DATE(`date`) = CURDATE()', $pageID);
394
- $pageCountToday = $wpdb->get_results($pageCountToday_qry);
395
-
396
- $total = (int) $pageCount[0]->total;
397
-
398
- $totalToday = (int) $pageCountToday[0]->total;
399
-
400
- $temp = array();
401
-
402
- $temp['today'] = $totalToday;
403
- $temp['total'] = $total;
404
-
405
- echo json_encode($temp);
406
-
407
- die();
408
-
409
- }
410
-
411
- public function insert_page_visit_counter_total_block_shop_page($content) {
412
- global $wpdb, $wp, $post;
413
-
414
- if (is_ssl()) {
415
- $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
416
- $pageID = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',$actual_link));
417
- } else {
418
- $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
419
- $pageID = url_to_postid( $actual_link );
420
- }
421
-
422
- if (($_SERVER['REQUEST_URI'] == '/shop/' || strpos($_SERVER['REQUEST_URI'], '/shop/') !== false ) && $pageID == 0) {
423
- $pageID = (int) get_option( 'woocommerce_shop_page_id' );
424
- }
425
-
426
- if ($pageID != 0) {
427
- $post = get_post($pageID);
428
-
429
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
 
 
 
 
430
 
431
- $text_color_page_visit = get_option('text_color_page_visit');
432
-
433
- if (isset($text_color_page_visit) && $text_color_page_visit != null) {
434
- $text_color_page_visit = 'style="color: '.$text_color_page_visit.';"';
435
- } else {
436
- $text_color_page_visit = 'style="color: #000000;"';
437
- }
438
-
439
- $enableToday = '';
440
- $enableToday = get_post_meta($pageID,'enable_page_count_day_wise',true);
441
-
442
- $table_name = $wpdb->prefix."page_visit";
443
- $table_name_history = $wpdb->prefix."page_visit_history";
444
 
445
- $pageCount_qry = $wpdb->prepare('SELECT SUM(page_visit) as total FROM ' . $table_name . ' WHERE page_id=%d', $pageID);
446
- $pageCount = $wpdb->get_results($pageCount_qry);
447
 
448
- $pageCountToday_qry = $wpdb->prepare('SELECT COUNT(page_id) as total FROM ' . $table_name_history . ' WHERE page_id=%d AND DATE(`date`) = CURDATE()', $pageID);
449
- $pageCountToday = $wpdb->get_results($pageCountToday_qry);
450
 
451
- $total = (int) $pageCount[0]->total;
452
- $totalToday = (int) $pageCountToday[0]->total;
453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
 
455
- $html = '';
456
- $hide_show_option = get_option('counter_hide_show_front_vew');
457
- if( $hide_show_option == 'on' ){
458
- if(!is_feed() && !is_home()) {
459
- if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
460
- if ('yes' === $enableToday || '' === $enableToday) {
461
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits,','page-visit-counter').'<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">'.esc_attr($totalToday).'</span>'.__('visits today','page-visit-counter').'</p>';
462
- } else {
463
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits.','page-visit-counter').'</p>';
464
- }
465
- } else {
466
- $postTypeSelectedEncodeArr = json_decode($fetchSelecetedPostTypes);
467
- if (in_array($post->post_type,$postTypeSelectedEncodeArr)) {
468
- $innerSettings = get_post_meta($pageID,'enable_page_count',true);
469
- if ($innerSettings == '' || $innerSettings == 'yes') {
470
- if ('yes' === $enableToday || '' === $enableToday) {
471
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits,','page-visit-counter').'<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">'.esc_attr($totalToday).'</span>'.__('visits today','page-visit-counter').'</p>';
472
- } else {
473
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits.','page-visit-counter').'</p>';
474
- }
475
- }
476
- }
477
- }
478
- }
479
- }
480
 
481
- echo $content.' '.$html; // WPCS: XSS OK.
482
- } else {
483
- echo $content; // WPCS: XSS OK.
484
- }
485
 
486
- }
 
487
 
488
- public function insert_page_visit_counter_total_block($content) {
489
- global $wpdb, $wp, $post;
 
490
 
491
- if (is_ssl()) {
492
- $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
493
- $pageID = url_to_postid(preg_replace('/^https(?=:\/\/)/i','http',esc_url($actual_link)));
494
- } else {
495
- $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
496
- $pageID = url_to_postid( esc_url($actual_link) );
497
- }
498
 
499
- if (($_SERVER['REQUEST_URI'] == '/shop/' || strpos($_SERVER['REQUEST_URI'], '/shop/') !== false ) && $pageID == 0) {
500
- $pageID = (int) get_option( 'woocommerce_shop_page_id' );
501
- }
502
-
503
- if ($pageID != 0) {
504
- $post = get_post($pageID);
505
-
506
- $fetchSelecetedPostTypes = get_option('wfap_post_type');
507
-
508
- $text_color_page_visit = get_option('text_color_page_visit');
509
-
510
- if (isset($text_color_page_visit) && $text_color_page_visit != null) {
511
- $text_color_page_visit1 = 'style="color: '.esc_attr($text_color_page_visit).';"';
 
512
 
513
  // echo esc_attr($text_color_page_visit1);
514
  // sanitize_text_field(wp_unslash($text_color_page_visit));
515
- } else {
516
- $text_color_page_visit1 = 'style="color: #000000;"';
517
  // sanitize_text_field(wp_unslash($text_color_page_visit));
518
- }
519
-
520
- $enableToday = '';
521
- $enableToday = get_post_meta($pageID,'enable_page_count_day_wise',true);
522
-
523
- $table_name = $wpdb->prefix."page_visit";
524
- $table_name_history = $wpdb->prefix."page_visit_history";
525
-
526
- $pageCount_qry = $wpdb->prepare('SELECT SUM(page_visit) as total FROM ' . $table_name . ' WHERE page_id=%d', $pageID);
527
- $pageCount = $wpdb->get_results($pageCount_qry);
528
-
529
- $pageCountToday_qry = $wpdb->prepare('SELECT COUNT(page_id) as total FROM ' . $table_name_history . ' WHERE page_id=%d AND DATE(`date`) = CURDATE()', $pageID);
530
- $pageCountToday = $wpdb->get_results($pageCountToday_qry);
531
-
532
- $total = (int) $pageCount[0]->total;
533
- $totalToday = (int) $pageCountToday[0]->total;
534
-
535
- $html = '';
536
- $hide_show_option = get_option('counter_hide_show_front_vew');
537
- if( $hide_show_option == 'on' ){
538
- if(!is_feed() && !is_home()) {
539
- if ($fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null) {
540
- if ('yes' === $enableToday || '' === $enableToday) {
541
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit1.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits,','page-visit-counter').'<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">'.esc_attr($totalToday).'</span>'.__('visits today','page-visit-counter').'</p>';
542
- } else {
543
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit1.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits.','page-visit-counter').'</p>';
544
- }
545
- } else {
546
- $postTypeSelectedEncodeArr = json_decode($fetchSelecetedPostTypes);
547
- if (in_array($post->post_type,$postTypeSelectedEncodeArr)) {
548
- $innerSettings = get_post_meta($pageID,'enable_page_count',true);
549
- if ($innerSettings == '' || $innerSettings == 'yes') {
550
- if ('yes' === $enableToday || '' === $enableToday) {
551
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit1.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits,','page-visit-counter').'<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">'.esc_attr($totalToday).'</span>'.__('visits today','page-visit-counter').'</p>';
552
- } else {
553
- $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" '.$text_color_page_visit1.'><img src="'.esc_url(plugins_url('images/1456175371_vector_65_14.png', dirname(__FILE__) )).'" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">'.esc_attr($total).'</span>'.__('total visits.','page-visit-counter').'</p>';
554
- }
555
- }
556
- }
557
- }
558
- }
559
- }
560
- $get_no_of_days = get_option('no_of_days_to_display');
561
- if ($get_no_of_days == '') {
562
- $get_no_of_days = 6;
563
- } else {
564
- $get_no_of_days = (int) $get_no_of_days + 1;
565
- }
566
- $query = "SELECT `page_id`, COUNT(`page_id`) as count,`date` FROM wp_page_visit_history Where DATE(`lastdate`) > DATE_SUB(CURDATE(), INTERVAL $get_no_of_days DAY) AND DATE(`lastdate`) < CURDATE() AND `page_id` = $pageID GROUP BY `lastdate`";
567
- return $content.' '.$html;
568
- } else {
569
- return $content;
570
- }
571
-
572
- }
573
-
574
-
575
- /**
576
- * BN code added
577
- */
578
-
579
- function paypal_bn_code_filter($paypal_args) {
580
- $paypal_args['bn'] = 'Multidots_SP';
581
- return $paypal_args;
582
- }
 
 
583
  }
1
  <?php
2
  // If this file is called directly, abort.
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
  }
6
  /**
7
  * The admin-specific functionality of the plugin.
25
  */
26
  class page_visit_counter_Public {
27
 
28
+ /**
29
+ * The ID of this plugin.
30
+ *
31
+ * @since 1.0.0
32
+ * @access private
33
+ * @var string $plugin_name The ID of this plugin.
34
+ */
35
+ private $plugin_name;
36
+
37
+ /**
38
+ * The version of this plugin.
39
+ *
40
+ * @since 1.0.0
41
+ * @access private
42
+ * @var string $version The current version of this plugin.
43
+ */
44
+ private $version;
45
+
46
+ /**
47
+ * Initialize the class and set its properties.
48
+ *
49
+ * @since 1.0.0
50
+ *
51
+ * @param string $plugin_name The name of this plugin.
52
+ * @param string $version The version of this plugin.
53
+ */
54
+ public function __construct( $plugin_name, $version ) {
55
+
56
+ $this->plugin_name = $plugin_name;
57
+ $this->version = $version;
58
+
59
+ }
60
+
61
+ /**
62
+ * Register the stylesheets for the admin area.
63
+ *
64
+ * @since 1.0.0
65
+ */
66
+ public function enqueue_styles() {
67
+ global $wp;
68
+
69
+ wp_enqueue_style( 'counter-style', plugin_dir_url( __FILE__ ) . 'css/counter-style.css' );
70
+
71
+ }
72
+
73
+ /**
74
+ * Register the JavaScript for the admin area.
75
+ *
76
+ * @since 1.0.0
77
+ */
78
+ public function enqueue_scripts() {
79
+ global $wp;
80
+ wp_enqueue_script( 'one', plugin_dir_url( __FILE__ ) . 'js/custom.js', array( 'jquery' ), $this->version, false );
81
+ $current_url = home_url( $wp->request );
82
+ wp_localize_script( 'one', 'pagevisit', array(
83
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
84
+ 'pageurl' => $current_url,
85
+ ) );
86
+
87
+ }
88
+
89
+ /**
90
+ * action use in call header
91
+ * Insert_page_visit_counter function use insert the page data
92
+ * pageid,Currentdate,Ipaddress,pagecount add in database.
93
+ */
94
+
95
+ public function insert_page_visit_counter() {
96
+ global $wpdb, $wp, $post, $wp_query;
97
+
98
+ $flag = 0;
99
+ // Check the site running on HTTPS. If the site running on HTTPS then we are removing S from HTTPS
100
+ if ( is_ssl() ) {
101
+ $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
102
+ if ( strpos( $actual_link, 'wp-admin' ) !== false ) {
103
+ $page = 0;
104
+ $flag = 1;
105
+ } else {
106
+ $page = url_to_postid( preg_replace( '/^https(?=:\/\/)/i', 'http', esc_url( $actual_link ) ) );
107
+ }
108
+ } else {
109
+ $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
110
+ if ( strpos( $actual_link, 'wp-admin' ) !== false ) {
111
+ $page = 0;
112
+ $flag = 1;
113
+ } else {
114
+ $page = url_to_postid( esc_url( $actual_link ) );
115
+ }
116
+ }
117
+ $pageID = $page;
118
+ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
119
+ if ( is_shop() ) {
120
+ $page = (int) get_option( 'woocommerce_shop_page_id' );
121
+ }
122
+ if ( is_cart() ) {
123
+ $page = (int) get_option( 'woocommerce_cart_page_id' );
124
+ }
125
+ if ( is_checkout() ) {
126
+ $page = (int) get_option( 'woocommerce_checkout_page_id' );
127
+
128
+ }
129
+ }
130
+
131
+
132
+ if ( $flag == 0 ) {
133
+
134
+ if ( $page == 0 ) {
135
+ $page = get_the_ID();
136
+ if ( $page == 0 ) {
137
+ $current_url = home_url( $wp->request );
138
+ if ( is_ssl() ) {
139
+ $page = url_to_postid( preg_replace( '/^https(?=:\/\/)/i', 'http', $current_url ) );
140
+ } else {
141
+ $page = url_to_postid( $current_url );
142
+ }
143
+ if ( $page == 0 ) {
144
+ $queried_object = get_queried_object();
145
+
146
+ if ( $queried_object ) {
147
+ $post_id = $queried_object->ID;
148
+ $page = $post_id;
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ if ( $page != 0 ) {
156
+
157
+
158
+ $table_name = $wpdb->prefix . "page_visit";
159
+ $table_name_history = $wpdb->prefix . "page_visit_history";
160
+ $last_date = '';
161
+ $page_contet = get_post( $page );
162
+
163
+ $currentdate = date( "Y-m-d" );
164
+ $ipaddress = $_SERVER['REMOTE_ADDR'];
165
+
166
+ $fetchSelecetedPostTypes = get_option( 'wfap_post_type' );
167
+ if ( $fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null ) {
168
+ $post_types = get_post_types();
169
+ $postArr = array();
170
+ if ( isset( $post_types ) && ! empty( $post_types ) ) {
171
+ foreach ( $post_types as $cpost ) {
172
+ 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" && $cpost != "shop_subscription" && $cpost != "wpcf7_contact_form" && $cpost != "mc4wp-form" ) {
173
+ $postArr[] = $cpost;
174
+ }
175
+ }
176
+ }
177
+
178
+ delete_option( 'wfap_post_type' );
179
+ if ( isset( $postArr ) && $postArr != null ) {
180
+ update_option( 'wfap_post_type', json_encode( array_values( $postArr ) ) );
181
+ }
182
+ $fetchSelecetedPostTypes = get_option( 'wfap_post_type' );
183
+ }
184
+
185
+ $postTypeSelectedDecodeArr = ! empty( $fetchSelecetedPostTypes ) ? $fetchSelecetedPostTypes : json_encode( array() );
186
+
187
+
188
+ $fetchSelecetedIpAddress = get_option( 'ipaddress_visit' );
189
+ $optionsIpAddressDecodedArr = ! empty( $fetchSelecetedIpAddress ) ? $fetchSelecetedIpAddress : json_encode( array() );
190
+
191
+
192
+ $fetchSelecetedUserId = get_option( 'userlist_visit' );
193
+ $optionsUserIdDecodedArr = ! empty( $fetchSelecetedUserId ) ? $fetchSelecetedUserId : json_encode( array() );
194
+
195
+ $pageCount_limit = intval( 1 );
196
+ $pageCount_qry = $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE page_id=%d AND ipaddress=%s AND date=%s LIMIT %d', $page, $ipaddress, $currentdate, $pageCount_limit );
197
+ $pageCount = $wpdb->get_results( $pageCount_qry );
198
+
199
+ $getPageSetting = get_post_meta( $page, 'enable_page_count', true );
200
+
201
+ $u_agent = $_SERVER['HTTP_USER_AGENT'];
202
+
203
+ $bname = 'Unknown';
204
+ $platform = 'Unknown';
205
+ $version = "";
206
+ $ub = "";
207
+
208
+ //First get the platform?
209
+ if ( preg_match( '/linux/i', $u_agent ) ) {
210
+ $platform = 'linux';
211
+ } elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
212
+ $platform = 'mac';
213
+ } elseif ( preg_match( '/windows|win32/i', $u_agent ) ) {
214
+ $platform = 'windows';
215
+ }
216
+
217
+ // Next get the name of the useragent yes seperately and for good reason
218
+ if ( preg_match( '/MSIE/i', $u_agent ) && ! preg_match( '/Opera/i', $u_agent ) ) {
219
+ $bname = 'Internet Explorer';
220
+ $ub = "MSIE";
221
+ } elseif ( preg_match( '/Firefox/i', $u_agent ) ) {
222
+ $bname = 'Mozilla Firefox';
223
+ $ub = "Firefox";
224
+ } elseif ( preg_match( '/Chrome/i', $u_agent ) ) {
225
+ $bname = 'Google Chrome';
226
+ $ub = "Chrome";
227
+ } elseif ( preg_match( '/Safari/i', $u_agent ) ) {
228
+ $bname = 'Apple Safari';
229
+ $ub = "Safari";
230
+ } elseif ( preg_match( '/Opera/i', $u_agent ) ) {
231
+ $bname = 'Opera';
232
+ $ub = "Opera";
233
+ } elseif ( preg_match( '/Netscape/i', $u_agent ) ) {
234
+ $bname = 'Netscape';
235
+ $ub = "Netscape";
236
+ }
237
+
238
+
239
+ // finally get the correct version number
240
+ $known = array( 'Version', $ub, 'other' );
241
+ $pattern = '#(?<browser>' . join( '|', $known ) .
242
+ ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
243
+ if ( ! preg_match_all( $pattern, $u_agent, $matches ) ) {
244
+ // we have no matching number just continue
245
+ }
246
+
247
+ // see how many we have
248
+ $i = count( $matches['browser'] );
249
+ if ( $i != 1 ) {
250
+ //we will have two since we are not using 'other' argument yet
251
+ //see if version is before or after the name
252
+ if ( strripos( $u_agent, "Version" ) < strripos( $u_agent, $ub ) ) {
253
+ $version = $matches['version'][0];
254
+ } else {
255
+ $version = isset( $matches['version'][1] ) ? $matches['version'][1] : null;;
256
+ }
257
+ } else {
258
+ $version = isset( $matches['version'][0] ) ? $matches['version'][0] : null;;
259
+ }
260
+
261
+ // check if we have a number
262
+ if ( $version == null || $version == "" ) {
263
+ $version = "?";
264
+ }
265
+
266
+ $http_referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '';
267
+
268
+ // old version plugin
269
+ if ( $fetchSelecetedPostTypes != '' ) {
270
+
271
+ $postTypeSelectedEncodeArr = json_decode( $postTypeSelectedDecodeArr );
272
+ $getPageSetting = get_post_meta( $page, 'enable_page_count', true );
273
+
274
+ // Check current page/post type exist in settings page array
275
+ if ( in_array( $page_contet->post_type, $postTypeSelectedEncodeArr ) ) {
276
+
277
+ // Check current page/post metabox settings is blank OR selected value is yes
278
+ if ( $getPageSetting == '' || $getPageSetting == 'yes' ) {
279
+
280
+ // Check IP Address set in settings page if yes
281
+ if ( isset( $fetchSelecetedIpAddress ) && ! empty( $fetchSelecetedIpAddress ) ) {
282
+
283
+ $optionsIpAddressEncodeArr = json_decode( $optionsIpAddressDecodedArr );
284
+ // Check IP Address not listed in settings page then go ahed
285
+ if ( ! in_array( $ipaddress, $optionsIpAddressEncodeArr ) ) {
286
+
287
+ // Check users set in settings page if yes
288
+ if ( isset( $fetchSelecetedUserId ) && ! empty( $fetchSelecetedUserId ) ) {
289
+
290
+ $optionsUserIdEncodeArr = json_decode( $optionsUserIdDecodedArr );
291
+ $user_id = get_current_user_id();
292
+
293
+ // Check user not listed in settings page then go ahed
294
+ if ( ! in_array( $user_id, $optionsUserIdEncodeArr ) ) {
295
+
296
+ if ( isset( $pageCount ) && ! empty( $pageCount ) ) {
297
+ $existingtotal = (int) $pageCount[0]->page_visit;
298
+ $totalFinal = $existingtotal + 1;
299
+ $update_Query = $wpdb->query( "UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='" . $page . "' AND ipaddress='$ipaddress' AND date = '$currentdate'" );
300
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
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
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
304
+ }
305
+ }
306
+ } else {
307
+ if ( isset( $pageCount ) && ! empty( $pageCount ) ) {
308
+ $existingtotal = (int) $pageCount[0]->page_visit;
309
+ $totalFinal = $existingtotal + 1;
310
+ $update_Query = $wpdb->query( "UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='" . $page . "' AND ipaddress='$ipaddress' AND date = '$currentdate'" );
311
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
312
+ } else {
313
+ $insert_Query = $wpdb->query( "INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')" );
314
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
315
+ }
316
+ }
317
+ }
318
+ } else {
319
+ // Check users set in settings page if yes
320
+ if ( isset( $fetchSelecetedUserId ) && ! empty( $fetchSelecetedUserId ) ) {
321
+
322
+ $optionsUserIdEncodeArr = json_decode( $optionsUserIdDecodedArr );
323
+ $user_id = get_current_user_id();
324
+
325
+ // Check user not listed in settings page then go ahed
326
+ if ( ! in_array( $user_id, $optionsUserIdEncodeArr ) ) {
327
+
328
+ if ( isset( $pageCount ) && ! empty( $pageCount ) ) {
329
+ $existingtotal = (int) $pageCount[0]->page_visit;
330
+ $totalFinal = $existingtotal + 1;
331
+ $update_Query = $wpdb->query( "UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='" . $page . "' AND ipaddress='$ipaddress' AND date = '$currentdate'" );
332
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
333
+ } else {
334
+ $insert_Query = $wpdb->query( "INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')" );
335
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
336
+ }
337
+ }
338
+ } else {
339
+ if ( isset( $pageCount ) && ! empty( $pageCount ) ) {
340
+ $existingtotal = (int) $pageCount[0]->page_visit;
341
+ $totalFinal = $existingtotal + 1;
342
+ $update_Query = $wpdb->query( "UPDATE $table_name SET page_visit = $totalFinal WHERE page_id='" . $page . "' AND ipaddress='$ipaddress' AND date = '$currentdate'" );
343
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
344
+ } else {
345
+ $insert_Query = $wpdb->query( "INSERT into $table_name (`page_id`,`page_visit`,`date`,`lastdate`,`ipaddress`) VALUES($page,1,NOW(),NOW(),'$ipaddress')" );
346
+ $insert_Query_history = $wpdb->query( "INSERT into $table_name_history (`page_id`, `date`, `lastdate`, `ipaddress`, `browser_full_name`, `browser_short_name`, `browser_version`, `os`, `http_referer`) VALUES($page,NOW(),NOW(),'$ipaddress','$bname','$ub','$version','$platform','$http_referer')" );
347
+ }
348
+ }
349
+ }
350
+ }
351
+ }
352
+ }
353
+ }
354
+
355
+ }
356
+
357
+ public function display_page_visit_counter_ajax() {
358
+ global $wpdb, $wp, $post;
359
+
360
+ $pageurl = sanitize_text_field( wp_unslash( $_POST['pageurl'] ) );
361
+
362
+ if ( is_ssl() ) {
363
+ $pageID = url_to_postid( preg_replace( '/^https(?=:\/\/)/i', 'http', $pageurl ) );
364
+ } else {
365
+ $pageID = url_to_postid( $pageurl );
366
+ }
367
+
368
+ if ( strpos( $pageurl, '/shop' ) !== false && $pageID == 0 ) {
369
+ $pageID = (int) get_option( 'woocommerce_shop_page_id' );
370
+ }
371
+
372
+ $post = get_post( $pageID );
373
+
374
+ $fetchSelecetedPostTypes = get_option( 'wfap_post_type' );
375
+
376
+ $table_name = $wpdb->prefix . "page_visit";
377
+
378
+ $pageCount_qry = $wpdb->prepare( 'SELECT SUM(page_visit) as total FROM ' . $table_name . ' WHERE page_id=%d', $pageID );
379
+ $pageCount = $wpdb->get_results( $pageCount_qry );
380
+
381
+ $table_name_history = $wpdb->prefix . "page_visit_history";
382
+
383
+ $pageCountToday_qry = $wpdb->prepare( 'SELECT COUNT(page_id) as total FROM ' . $table_name_history . ' WHERE page_id=%d AND DATE(`date`) = CURDATE()', $pageID );
384
+ $pageCountToday = $wpdb->get_results( $pageCountToday_qry );
385
+
386
+ $total = (int) $pageCount[0]->total;
387
+
388
+ $totalToday = (int) $pageCountToday[0]->total;
389
+
390
+ $temp = array();
391
+
392
+ $temp['today'] = $totalToday;
393
+ $temp['total'] = $total;
394
+
395
+ echo json_encode( $temp );
396
+
397
+ die();
398
+
399
+ }
400
+
401
+ public function insert_page_visit_counter_total_block_shop_page( $content ) {
402
+ global $wpdb, $wp, $post;
403
+
404
+ if ( is_ssl() ) {
405
+ $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
406
+ $pageID = url_to_postid( preg_replace( '/^https(?=:\/\/)/i', 'http', $actual_link ) );
407
+ } else {
408
+ $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
409
+ $pageID = url_to_postid( $actual_link );
410
+ }
411
+
412
+ if ( ( $_SERVER['REQUEST_URI'] == '/shop/' || strpos( $_SERVER['REQUEST_URI'], '/shop/' ) !== false ) && $pageID == 0 ) {
413
+ $pageID = (int) get_option( 'woocommerce_shop_page_id' );
414
+ }
415
+
416
+ if ( $pageID != 0 ) {
417
+ $post = get_post( $pageID );
418
+
419
+ $fetchSelecetedPostTypes = get_option( 'wfap_post_type' );
420
+
421
+ $text_color_page_visit = get_option( 'text_color_page_visit' );
422
+
423
+ if ( isset( $text_color_page_visit ) && $text_color_page_visit != null ) {
424
+ $text_color_page_visit = 'style="color: ' . $text_color_page_visit . ';"';
425
+ } else {
426
+ $text_color_page_visit = 'style="color: #000000;"';
427
+ }
428
+
429
+ $enableToday = '';
430
+ $enableToday = get_post_meta( $pageID, 'enable_page_count_day_wise', true );
431
+
432
+ $table_name = $wpdb->prefix . "page_visit";
433
+ $table_name_history = $wpdb->prefix . "page_visit_history";
434
 
435
+ $pageCount_qry = $wpdb->prepare( 'SELECT SUM(page_visit) as total FROM ' . $table_name . ' WHERE page_id=%d', $pageID );
436
+ $pageCount = $wpdb->get_results( $pageCount_qry );
 
 
 
 
 
 
 
 
 
 
 
437
 
438
+ $pageCountToday_qry = $wpdb->prepare( 'SELECT COUNT(page_id) as total FROM ' . $table_name_history . ' WHERE page_id=%d AND DATE(`date`) = CURDATE()', $pageID );
439
+ $pageCountToday = $wpdb->get_results( $pageCountToday_qry );
440
 
441
+ $total = (int) $pageCount[0]->total;
442
+ $totalToday = (int) $pageCountToday[0]->total;
443
 
 
 
444
 
445
+ $html = '';
446
+ $hide_show_option = get_option( 'counter_hide_show_front_vew' );
447
+ if ( $hide_show_option == 'on' ) {
448
+ if ( ! is_feed() && ! is_home() ) {
449
+ if ( $fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null ) {
450
+ if ( 'yes' === $enableToday || '' === $enableToday ) {
451
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits,', 'page-visit-counter' ) . '<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">' . esc_attr( $totalToday ) . '</span>' . __( 'visits today', 'page-visit-counter' ) . '</p>';
452
+ } else {
453
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits.', 'page-visit-counter' ) . '</p>';
454
+ }
455
+ } else {
456
+ $postTypeSelectedEncodeArr = json_decode( $fetchSelecetedPostTypes );
457
+ if ( in_array( $post->post_type, $postTypeSelectedEncodeArr ) ) {
458
+ $innerSettings = get_post_meta( $pageID, 'enable_page_count', true );
459
+ if ( $innerSettings == '' || $innerSettings == 'yes' ) {
460
+ if ( 'yes' === $enableToday || '' === $enableToday ) {
461
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits,', 'page-visit-counter' ) . '<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">' . esc_attr( $totalToday ) . '</span>' . __( 'visits today', 'page-visit-counter' ) . '</p>';
462
+ } else {
463
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits.', 'page-visit-counter' ) . '</p>';
464
+ }
465
+ }
466
+ }
467
+ }
468
+ }
469
+ }
470
 
471
+ echo $content . ' ' . $html; // WPCS: XSS OK.
472
+ } else {
473
+ echo $content; // WPCS: XSS OK.
474
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
 
476
+ }
 
 
 
477
 
478
+ public function insert_page_visit_counter_total_block( $content ) {
479
+ global $wpdb, $wp, $post;
480
 
481
+ if ( is_ssl() ) {
482
+ $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
483
+ $pageID = url_to_postid( preg_replace( '/^https(?=:\/\/)/i', 'http', esc_url( $actual_link ) ) );
484
 
485
+ } else {
486
+ $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
487
+ $pageID = url_to_postid( esc_url( $actual_link ) );
488
+ }
 
 
 
489
 
490
+ if ( ( $_SERVER['REQUEST_URI'] == '/shop/' || strpos( $_SERVER['REQUEST_URI'], '/shop/' ) !== false ) && $pageID == 0 ) {
491
+ $pageID = (int) get_option( 'woocommerce_shop_page_id' );
492
+ }
493
+
494
+ if ( $pageID != 0 ) {
495
+ // $post = get_post( $pageID );
496
+ global $post;
497
+ //
498
+ $fetchSelecetedPostTypes = get_option( 'wfap_post_type' );
499
+
500
+ $text_color_page_visit = get_option( 'text_color_page_visit' );
501
+
502
+ if ( isset( $text_color_page_visit ) && $text_color_page_visit != null ) {
503
+ $text_color_page_visit1 = 'style="color: ' . esc_attr( $text_color_page_visit ) . ';"';
504
 
505
  // echo esc_attr($text_color_page_visit1);
506
  // sanitize_text_field(wp_unslash($text_color_page_visit));
507
+ } else {
508
+ $text_color_page_visit1 = 'style="color: #000000;"';
509
  // sanitize_text_field(wp_unslash($text_color_page_visit));
510
+ }
511
+
512
+ $enableToday = '';
513
+ $enableToday = get_post_meta( $pageID, 'enable_page_count_day_wise', true );
514
+
515
+ $table_name = $wpdb->prefix . "page_visit";
516
+ $table_name_history = $wpdb->prefix . "page_visit_history";
517
+
518
+ $pageCount_qry = $wpdb->prepare( 'SELECT SUM(page_visit) as total FROM ' . $table_name . ' WHERE page_id=%d', $pageID );
519
+ $pageCount = $wpdb->get_results( $pageCount_qry );
520
+
521
+ $pageCountToday_qry = $wpdb->prepare( 'SELECT COUNT(page_id) as total FROM ' . $table_name_history . ' WHERE page_id=%d AND DATE(`date`) = CURDATE()', $pageID );
522
+ $pageCountToday = $wpdb->get_results( $pageCountToday_qry );
523
+
524
+ $total = (int) $pageCount[0]->total;
525
+ $totalToday = (int) $pageCountToday[0]->total;
526
+
527
+ $html = '';
528
+ $hide_show_option = get_option( 'counter_hide_show_front_vew' );
529
+ if ( $hide_show_option == 'on' ) {
530
+ if ( ! is_feed() && ! is_home() ) {
531
+ if ( $fetchSelecetedPostTypes == '' || $fetchSelecetedPostTypes == null ) {
532
+ if ( 'yes' === $enableToday || '' === $enableToday ) {
533
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit1 . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits,', 'page-visit-counter' ) . '<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">' . esc_attr( $totalToday ) . '</span>' . __( 'visits today', 'page-visit-counter' ) . '</p>';
534
+ } else {
535
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit1 . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits.', 'page-visit-counter' ) . '</p>';
536
+ }
537
+ } else {
538
+ $postTypeSelectedEncodeArr = json_decode( $fetchSelecetedPostTypes );
539
+ if ( in_array( $post->post_type, $postTypeSelectedEncodeArr ) ) {
540
+ $innerSettings = get_post_meta( $pageID, 'enable_page_count', true );
541
+ if ( $innerSettings == '' || $innerSettings == 'yes' ) {
542
+ if ( 'yes' === $enableToday || '' === $enableToday ) {
543
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit1 . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits,', 'page-visit-counter' ) . '<span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor_today">' . esc_attr( $totalToday ) . '</span>' . __( 'visits today', 'page-visit-counter' ) . '</p>';
544
+ } else {
545
+ $html .= '<p id="default-loop-page-visit-counter" class="page-visit-counter-block" ' . $text_color_page_visit1 . '><img src="' . esc_url( plugins_url( 'images/1456175371_vector_65_14.png', dirname( __FILE__ ) ) ) . '" /><span style="margin-left: 5px;margin-right: 5px;" class="page_amount_visitor">' . esc_attr( $total ) . '</span>' . __( 'total visits.', 'page-visit-counter' ) . '</p>';
546
+ }
547
+ }
548
+ }
549
+ }
550
+ }
551
+ }
552
+ $get_no_of_days = get_option( 'no_of_days_to_display' );
553
+ if ( $get_no_of_days == '' ) {
554
+ $get_no_of_days = 6;
555
+ } else {
556
+ $get_no_of_days = (int) $get_no_of_days + 1;
557
+ }
558
+ $query = "SELECT `page_id`, COUNT(`page_id`) as count,`date` FROM wp_page_visit_history Where DATE(`lastdate`) > DATE_SUB(CURDATE(), INTERVAL $get_no_of_days DAY) AND DATE(`lastdate`) < CURDATE() AND `page_id` = $pageID GROUP BY `lastdate`";
559
+
560
+ return $content . ' ' . $html;
561
+ } else {
562
+ return $content;
563
+ }
564
+
565
+ }
566
+
567
+
568
+ /**
569
+ * BN code added
570
+ */
571
+
572
+ function paypal_bn_code_filter( $paypal_args ) {
573
+ $paypal_args['bn'] = 'Multidots_SP';
574
+
575
+ return $paypal_args;
576
+ }
577
  }