From 256a354b246dee227a754f224d6b14eb96fea842 Mon Sep 17 00:00:00 2001 From: Nguyen Tuan Date: Thu, 14 Dec 2017 12:22:53 +0700 Subject: [PATCH] Release version 2.0.2 * Maintenance Update. This update includes 3 bug fixes, including AMP pages conpatibility * Fix - Headers already sent warning. Delete trailing spaces at bottom of php file * Fix - Change attribute name element-id to data-element-id for compatibility with AMP. Thanks to @veenareddys for reporting the issue * Fix - Update SQL query for fix bug get incorrect total views when edit a Post or Page. Thanks to @groenhart for reporting this issue --- admin/admin-init.php | 2 +- admin/admin-interface.php | 2 +- admin/admin-ui.php | 2 +- admin/includes/uploader/class-uploader.php | 2 +- admin/less/compile_less_sass_class.php | 3 +- admin/less/index.html | 2 +- admin/less/sass.php | 3 +- admin/plugin-init.php | 4 +- api/pvc-api.php | 1 + assets/js/pvc.backbone.js | 2 +- assets/js/pvc.backbone.min.js | 2 +- classes/class-pvc-metabox.php | 3 +- page-views-count.php | 7 ++- pvc_class.php | 66 ++++++++++++++-------- readme.txt | 11 +++- 15 files changed, 74 insertions(+), 38 deletions(-) diff --git a/admin/admin-init.php b/admin/admin-init.php index e91ba99..a3d85f9 100755 --- a/admin/admin-init.php +++ b/admin/admin-init.php @@ -319,4 +319,4 @@ public function admin_settings_tab( $current_page = '', $tab_data = array() ) { global $wp_pvc_admin_init; $wp_pvc_admin_init = new WP_PVC_Admin_Init(); -?> +?> \ No newline at end of file diff --git a/admin/admin-interface.php b/admin/admin-interface.php index 494e79d..e940b68 100755 --- a/admin/admin-interface.php +++ b/admin/admin-interface.php @@ -3701,4 +3701,4 @@ public function generate_background_color_css( $option, $transparency = 100 ) { global $wp_pvc_admin_interface; $wp_pvc_admin_interface = new WP_PVC_Admin_Interface(); -?> +?> \ No newline at end of file diff --git a/admin/admin-ui.php b/admin/admin-ui.php index b5a5713..a595bf8 100755 --- a/admin/admin-ui.php +++ b/admin/admin-ui.php @@ -342,4 +342,4 @@ public function get_version_message() { } -?> +?> \ No newline at end of file diff --git a/admin/includes/uploader/class-uploader.php b/admin/includes/uploader/class-uploader.php index f37fd05..3e646e7 100755 --- a/admin/includes/uploader/class-uploader.php +++ b/admin/includes/uploader/class-uploader.php @@ -134,4 +134,4 @@ public function upload_input ( $name_attribute, $id_attribute = '', $value = '', global $wp_pvc_uploader; $wp_pvc_uploader = new WP_PVC_Uploader(); -?> +?> \ No newline at end of file diff --git a/admin/less/compile_less_sass_class.php b/admin/less/compile_less_sass_class.php index 517381c..445cc60 100644 --- a/admin/less/compile_less_sass_class.php +++ b/admin/less/compile_less_sass_class.php @@ -53,4 +53,5 @@ public function compileLessFile( $less_file = '', $css_file = '', $css_min_file } } -?> + +?> \ No newline at end of file diff --git a/admin/less/index.html b/admin/less/index.html index 2ff65d9..8a9c24a 100644 --- a/admin/less/index.html +++ b/admin/less/index.html @@ -26,6 +26,6 @@ -

3,894 total views, 1 views today

+

3,894 total views, 1 views today

\ No newline at end of file diff --git a/admin/less/sass.php b/admin/less/sass.php index 0385484..9dca894 100644 --- a/admin/less/sass.php +++ b/admin/less/sass.php @@ -179,4 +179,5 @@ public function get_css_file_version( $css_file_name = '' ) { } global $a3_pvc_less; $a3_pvc_less = new A3_PVC_Less(); -?> + +?> \ No newline at end of file diff --git a/admin/plugin-init.php b/admin/plugin-init.php index 5325765..c544846 100755 --- a/admin/plugin-init.php +++ b/admin/plugin-init.php @@ -3,7 +3,7 @@ * Process when plugin is activated */ function pvc_install(){ - update_option( 'a3_pvc_version', '2.0.1' ); + update_option( 'a3_pvc_version', '2.0.2' ); // empty pvc_daily table for daily wp_schedule_event( time(), 'daily', 'pvc_empty_daily_table_daily_event_hook' ); @@ -131,7 +131,7 @@ function pvc_lite_upgrade_plugin () { $a3_pvc_less->plugin_build_sass(); } - update_option('a3_pvc_version', '2.0.1'); + update_option('a3_pvc_version', '2.0.2'); } diff --git a/api/pvc-api.php b/api/pvc-api.php index 78244de..06eb5e5 100755 --- a/api/pvc-api.php +++ b/api/pvc-api.php @@ -135,4 +135,5 @@ public function view_stats( WP_REST_Request $request ) { global $pvc_api; $pvc_api = new PVC_API(); + ?> \ No newline at end of file diff --git a/assets/js/pvc.backbone.js b/assets/js/pvc.backbone.js index bcbd228..1a65452 100755 --- a/assets/js/pvc.backbone.js +++ b/assets/js/pvc.backbone.js @@ -110,7 +110,7 @@ jQuery( document ).ready( function( $ ) { if ( pvc_stats.length ) { var pvc_ids = {}; $(".pvc_stats").each( function() { - post_id = $(this).attr('element-id'); + post_id = $(this).data('element-id'); update_status = $(this).hasClass('pvc_load_by_ajax_update'); pvc_ids[post_id] = { post_id: post_id, ask_update : update_status }; }); diff --git a/assets/js/pvc.backbone.min.js b/assets/js/pvc.backbone.min.js index 432639b..cdd5dff 100755 --- a/assets/js/pvc.backbone.min.js +++ b/assets/js/pvc.backbone.min.js @@ -1 +1 @@ -jQuery(function(a){var b=vars.rest_api_url;pvc={apps:{},models:{},collections:{},views:{}};_.templateSettings={evaluate:/[<{][%{](.+?)[%}][}>]/g,interpolate:/[<{][%{]=(.+?)[%}][}>]/g,escape:/[<{][%{]-(.+?)[%}][}>]/g};pvc.models.State=Backbone.Model.extend({defaults:{post_id:0,total_view:1,today_view:1}});pvc.collections.Stats=Backbone.Collection.extend({model:pvc.models.State,url:b});pvc.views.State=Backbone.View.extend({model:pvc.models.State,tagName:"span",template:_.template(a("#pvc-stats-view-template").html()),initialize:function(){},render:function(){this.$el.html(this.template(this.model.toJSON()));return this}});pvc.views.AppView=Backbone.View.extend({initialize:function(){this.listenTo(this.collection,"add",this.addOne)},addOne:function(a){a=new pvc.views.State({model:a});this.$el.html(a.render().el)}});pvc.apps.app={initialize:function(b,e){this.rest_api_url=e;view_pvc_ids=[];increase_pvc_ids=[];a.each(b,function(a,c){c.ask_update?increase_pvc_ids.push(c.post_id):view_pvc_ids.push(c.post_id)});increase_pvc_ids.length&&a.get(this.rest_api_url+"/increase/"+increase_pvc_ids.join(","),function(b){b.success&&a.each(b.items,function(b,d){collection=new pvc.collections.Stats;new pvc.views.AppView({collection:collection,el:a("#pvc_stats_"+b)});collection.add(d)})});view_pvc_ids.length&&a.get(this.rest_api_url+"/view/"+view_pvc_ids.join(","),function(b){b.success&&a.each(b.items,function(b,d){collection=new pvc.collections.Stats;new pvc.views.AppView({collection:collection,el:a("#pvc_stats_"+b)});collection.add(d)})})}}});jQuery(document).ready(function(a){if(a(".pvc_stats").length){var b={};a(".pvc_stats").each(function(){post_id=a(this).attr("element-id");update_status=a(this).hasClass("pvc_load_by_ajax_update");b[post_id]={post_id:post_id,ask_update:update_status}});pvc.apps.app.initialize(b,vars.rest_api_url)}}); \ No newline at end of file +jQuery(function(a){var b=vars.rest_api_url;pvc={apps:{},models:{},collections:{},views:{}};_.templateSettings={evaluate:/[<{][%{](.+?)[%}][}>]/g,interpolate:/[<{][%{]=(.+?)[%}][}>]/g,escape:/[<{][%{]-(.+?)[%}][}>]/g};pvc.models.State=Backbone.Model.extend({defaults:{post_id:0,total_view:1,today_view:1}});pvc.collections.Stats=Backbone.Collection.extend({model:pvc.models.State,url:b});pvc.views.State=Backbone.View.extend({model:pvc.models.State,tagName:"span",template:_.template(a("#pvc-stats-view-template").html()),initialize:function(){},render:function(){this.$el.html(this.template(this.model.toJSON()));return this}});pvc.views.AppView=Backbone.View.extend({initialize:function(){this.listenTo(this.collection,"add",this.addOne)},addOne:function(a){a=new pvc.views.State({model:a});this.$el.html(a.render().el)}});pvc.apps.app={initialize:function(b,e){this.rest_api_url=e;view_pvc_ids=[];increase_pvc_ids=[];a.each(b,function(a,c){c.ask_update?increase_pvc_ids.push(c.post_id):view_pvc_ids.push(c.post_id)});increase_pvc_ids.length&&a.get(this.rest_api_url+"/increase/"+increase_pvc_ids.join(","),function(b){b.success&&a.each(b.items,function(b,d){collection=new pvc.collections.Stats;new pvc.views.AppView({collection:collection,el:a("#pvc_stats_"+b)});collection.add(d)})});view_pvc_ids.length&&a.get(this.rest_api_url+"/view/"+view_pvc_ids.join(","),function(b){b.success&&a.each(b.items,function(b,d){collection=new pvc.collections.Stats;new pvc.views.AppView({collection:collection,el:a("#pvc_stats_"+b)});collection.add(d)})})}}});jQuery(document).ready(function(a){if(a(".pvc_stats").length){var b={};a(".pvc_stats").each(function(){post_id=a(this).data("element-id");update_status=a(this).hasClass("pvc_load_by_ajax_update");b[post_id]={post_id:post_id,ask_update:update_status}});pvc.apps.app.initialize(b,vars.rest_api_url)}}); \ No newline at end of file diff --git a/classes/class-pvc-metabox.php b/classes/class-pvc-metabox.php index 4b5c85e..d82d211 100644 --- a/classes/class-pvc-metabox.php +++ b/classes/class-pvc-metabox.php @@ -153,4 +153,5 @@ public function save( $post_id ) { } new PVC_MetaBox(); -?> + +?> \ No newline at end of file diff --git a/page-views-count.php b/page-views-count.php index 07bffc9..78eddb8 100755 --- a/page-views-count.php +++ b/page-views-count.php @@ -2,7 +2,7 @@ /* Plugin Name: Page Views Count Description: Show front end users all time views and views today on posts, pages, index pages and custom post types with the Page Views Count Plugin. Use the Page Views Count function to add page views to any content type or object created by your theme or plugins. -Version: 2.0.1 +Version: 2.0.2 Requires at least: 4.6 Tested up to: 4.9.1 Author: a3rev Software @@ -21,7 +21,7 @@ define('A3_PVC_JS_URL', A3_PVC_URL . '/assets/js'); define('A3_PVC_IMAGES_URL', A3_PVC_URL . '/assets/images'); -define('A3_PVC_VERSION', '2.0.1'); +define('A3_PVC_VERSION', '2.0.2'); /** * Load Localisation files. @@ -86,4 +86,5 @@ function pvc_check_exclude( $postid = 0 ) { return true; } } -?> + +?> \ No newline at end of file diff --git a/pvc_class.php b/pvc_class.php index 4c0ed91..fbf7a9b 100755 --- a/pvc_class.php +++ b/pvc_class.php @@ -49,20 +49,38 @@ public static function pvc_fetch_posts_stats( $post_ids ) { } public static function pvc_fetch_post_counts( $post_id ) { - global $wpdb; - $nowisnow = date('Y-m-d'); + $total = A3_PVC::pvc_fetch_post_total( $post_id ); + $today = A3_PVC::pvc_fetch_post_today( $post_id ); - $sql = $wpdb->prepare( "SELECT t.postcount AS total, d.postcount AS today FROM ". $wpdb->prefix . "pvc_total AS t - LEFT JOIN ". $wpdb->prefix . "pvc_daily AS d ON t.postnum = d.postnum - WHERE t.postnum = %s AND d.time = %s", $post_id, $nowisnow ); - return $wpdb->get_row($sql); + $post_counts = new stdClass(); + $post_counts->total = 0; + $post_counts->today = 0; + + if ( ! empty( $total ) ) { + $post_counts->total = $total; + } + + if ( ! empty( $today ) ) { + $post_counts->today = $today; + } + + return $post_counts; } public static function pvc_fetch_post_total( $post_id ) { global $wpdb; - $sql = $wpdb->prepare( "SELECT t.postcount AS total FROM ". $wpdb->prefix . "pvc_total AS t - WHERE t.postnum = %s", $post_id ); + $sql = $wpdb->prepare( "SELECT postcount AS total FROM ". $wpdb->prefix . "pvc_total + WHERE postnum = %s", $post_id ); + return $wpdb->get_var($sql); + } + + public static function pvc_fetch_post_today( $post_id ) { + global $wpdb; + $nowisnow = date('Y-m-d'); + + $sql = $wpdb->prepare( "SELECT postcount AS today FROM ". $wpdb->prefix . "pvc_daily + WHERE postnum = %s AND time = %s", $post_id, $nowisnow ); return $wpdb->get_var($sql); } @@ -88,8 +106,6 @@ public static function pvc_stats_update($post_id) { $wpdb->query( $wpdb->prepare( "INSERT INTO ". $wpdb->prefix . "pvc_daily (time, postnum, postcount) VALUES ('%s', '%s', 1)", $nowisnow, $post_id ) ); } - // get all the post view info so we can update meta fields - //$row = A3_PVC::pvc_fetch_post_counts( $post_id ); } public static function pvc_stats_manual_update( $post_id, $new_total_views, $new_today_views ) { @@ -117,23 +133,29 @@ public static function pvc_stats_manual_update( $post_id, $new_total_views, $new } } - public static function pvc_get_stats($post_id) { + public static function pvc_get_stats( $post_id ) { global $wpdb; $output_html = ''; // get all the post view info to display - $results = A3_PVC::pvc_fetch_post_counts( $post_id ); - // get the stats and - if ( $results ){ - $output_html .= number_format( $results->total ) . ' ' .__('total views', 'page-views-count') . ', ' . number_format( $results->today ) . ' ' .__('views today', 'page-views-count'); - } else { - $total = A3_PVC::pvc_fetch_post_total( $post_id ); - if ( $total > 0 ) { - $output_html .= number_format( $total ) . ' ' .__('total views', 'page-views-count') . ', ' .__('no views today', 'page-views-count'); + $total = A3_PVC::pvc_fetch_post_total( $post_id ); + $today = A3_PVC::pvc_fetch_post_today( $post_id ); + + if ( ! empty( $total ) ) { + + $output_html .= number_format( $total ) . ' ' .__('total views', 'page-views-count'); + $output_html .= ', '; + + if ( ! empty( $today ) ) { + $output_html .= number_format( $results->today ) . ' ' .__('views today', 'page-views-count'); } else { - $output_html .= __('No views yet', 'page-views-count'); + $output_html .= __('no views today', 'page-views-count'); } + + } else { + $output_html .= __('No views yet', 'page-views-count'); } + $output_html = apply_filters( 'pvc_filter_get_stats', $output_html, $post_id ); return $output_html; @@ -151,9 +173,9 @@ public static function pvc_stats_counter( $post_id, $increase_views = false ) { $html = '
'; if ( $pvc_settings['enable_ajax_load'] == 'yes' ) { - $stats_html = '

'; + $stats_html = '

'; } else { - $stats_html = '

' . A3_PVC::pvc_get_stats( $post_id ) . '

'; + $stats_html = '

' . A3_PVC::pvc_get_stats( $post_id ) . '

'; } $html .= apply_filters( 'pvc_filter_stats', $stats_html, $post_id ); diff --git a/readme.txt b/readme.txt index 2ce33e9..2861636 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: a3rev, a3rev Software, nguyencongtuan Tags: wordpress page view, page view count , post views, postview count, Requires at least: 4.6 Tested up to: 4.9.1 -Stable tag: 2.0.1 +Stable tag: 2.0.2 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -89,6 +89,12 @@ The manual installation method involves down loading our plugin and uploading it == Changelog == += 2.0.2 - 2017/12/14 = +* Maintenance Update. This update includes 3 bug fixes, including AMP pages conpatibility +* Fix - Headers already sent warning. Delete trailing spaces at bottom of php file +* Fix - Change attribute name element-id to data-element-id for compatibility with AMP. Thanks to @veenareddys for reporting the issue +* Fix - Update SQL query for fix bug get incorrect total views when edit a Post or Page. Thanks to @groenhart for reporting this issue + = 2.0.1 - 2017/12/13 = * Maintenance Update. 3 code tweaks for compatibility with WordPress 4.9.1 and 2 bug fixes * Tweak - Removed auto redirect to plugins admin panel on activation @@ -264,6 +270,9 @@ The manual installation method involves down loading our plugin and uploading it == Upgrade Notice == += 2.0.2 = +Maintenance Update. This update includes 3 bug fixes, including AMP pages compatibility + = 2.0.1 = Maintenance Update. 3 code tweaks for compatibility with WordPress 4.9.1 and 2 bug fixes