WP-PostViews - Version 1.69

Version Description

N/A

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-PostViews
Version 1.69
Comparing to
See all releases

Code changes from version 1.68 to 1.69

Files changed (3) hide show
  1. postviews-options.php +5 -3
  2. readme.txt +7 -2
  3. wp-postviews.php +37 -10
postviews-options.php CHANGED
@@ -30,12 +30,12 @@ if(!empty($_POST['Submit'] )) {
30
 
31
  foreach( $update_views_queries as $update_views_query ) {
32
  if( $update_views_query ) {
33
- $text .= '<font style="color: green;">' . $update_views_text[$i] . ' ' . __( 'Updated', 'wp-postviews' ) . '</font><br />';
34
  }
35
  $i++;
36
  }
37
  if( empty( $text ) ) {
38
- $text = '<font style="color: red;">' . __( 'No Post Views Option Updated', 'wp-postviews' ) . '</font>';
39
  }
40
  }
41
 
@@ -107,7 +107,8 @@ if( !isset ( $views_options['use_ajax'] ) ) {
107
  <td valign="top">
108
  <strong><?php _e( 'Views Template:', 'wp-postviews' ); ?></strong><br /><br />
109
  <?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
110
- - %VIEW_COUNT%<br /><br />
 
111
  <input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'template' );" class="button" />
112
  </td>
113
  <td valign="top">
@@ -119,6 +120,7 @@ if( !isset ( $views_options['use_ajax'] ) ) {
119
  <strong><?php _e( 'Most Viewed Template:', 'wp-postviews' ); ?></strong><br /><br />
120
  <?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
121
  - %VIEW_COUNT%<br />
 
122
  - %POST_TITLE%<br />
123
  - %POST_DATE%<br />
124
  - %POST_TIME%<br />
30
 
31
  foreach( $update_views_queries as $update_views_query ) {
32
  if( $update_views_query ) {
33
+ $text .= '<p style="color: green;">' . $update_views_text[$i] . ' ' . __( 'Updated', 'wp-postviews' ) . '</p>';
34
  }
35
  $i++;
36
  }
37
  if( empty( $text ) ) {
38
+ $text = '<p style="color: red;">' . __( 'No Post Views Option Updated', 'wp-postviews' ) . '</p>';
39
  }
40
  }
41
 
107
  <td valign="top">
108
  <strong><?php _e( 'Views Template:', 'wp-postviews' ); ?></strong><br /><br />
109
  <?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
110
+ - %VIEW_COUNT%<br />
111
+ - %VIEW_COUNT_ROUNDED%<br /><br />
112
  <input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'template' );" class="button" />
113
  </td>
114
  <td valign="top">
120
  <strong><?php _e( 'Most Viewed Template:', 'wp-postviews' ); ?></strong><br /><br />
121
  <?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
122
  - %VIEW_COUNT%<br />
123
+ - %VIEW_COUNT_ROUNDED%<br />
124
  - %POST_TITLE%<br />
125
  - %POST_DATE%<br />
126
  - %POST_TIME%<br />
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: GamerZ
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: views, hits, counter, postviews
5
  Requires at least: 3.0
6
- Tested up to: 4.0
7
- Stable tag: 1.68
8
 
9
  Enables you to display how many times a post/page had been viewed.
10
 
@@ -26,6 +26,10 @@ Enables you to display how many times a post/page had been viewed.
26
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
27
 
28
  == Changelog ==
 
 
 
 
29
  = Version 1.68 =
30
  * NEW: Added action hook 'postviews_increment_views' and 'postviews_increment_views_ajax'
31
  * NEW: Allow custom post type to be chosen under the widget
@@ -138,6 +142,7 @@ I spent most of my free time creating, updating, maintaining and supporting thes
138
  2. You may place it in archive.php, single.php, post.php or page.php also.
139
  3. Find: `<?php while (have_posts()) : the_post(); ?>`
140
  4. Add Anywhere Below It (The Place You Want The Views To Show): `<?php if(function_exists('the_views')) { the_views(); } ?>`
 
141
 
142
  == Upgrading ==
143
 
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: views, hits, counter, postviews
5
  Requires at least: 3.0
6
+ Tested up to: 4.1
7
+ Stable tag: 1.69
8
 
9
  Enables you to display how many times a post/page had been viewed.
10
 
26
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
27
 
28
  == Changelog ==
29
+ = Version 1.69 =
30
+ * NEW: Shortcode `[views]` or [views id="POST_ID"]` to embed view count into post
31
+ * NEW: Added template variable `%VIEW_COUNT_ROUNDED%` to support rounded view count like 10.1k or 11.2M
32
+
33
  = Version 1.68 =
34
  * NEW: Added action hook 'postviews_increment_views' and 'postviews_increment_views_ajax'
35
  * NEW: Allow custom post type to be chosen under the widget
142
  2. You may place it in archive.php, single.php, post.php or page.php also.
143
  3. Find: `<?php while (have_posts()) : the_post(); ?>`
144
  4. Add Anywhere Below It (The Place You Want The Views To Show): `<?php if(function_exists('the_views')) { the_views(); } ?>`
145
+ 5. Or you can use the shortcode `[views]` or `[views id="1"]` (where 1 is the post ID) in a post
146
 
147
  == Upgrading ==
148
 
wp-postviews.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-PostViews
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Enables you to display how many times a post/page had been viewed.
6
- Version: 1.68
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-postviews
@@ -200,10 +200,10 @@ function should_views_be_displayed($views_options = null) {
200
 
201
  ### Function: Display The Post Views
202
  function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
203
- $post_views = intval(post_custom('views'));
204
  $views_options = get_option('views_options');
205
  if ($always || should_views_be_displayed($views_options)) {
206
- $output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
207
  if($display) {
208
  echo apply_filters('the_views', $output);
209
  } else {
@@ -215,6 +215,21 @@ function the_views($display = true, $prefix = '', $postfix = '', $always = false
215
  }
216
  }
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  ### Function: Display Least Viewed Page/Post
220
  if(!function_exists('get_least_viewed')) {
@@ -245,6 +260,7 @@ if(!function_exists('get_least_viewed')) {
245
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
246
  $temp = stripslashes($views_options['most_viewed_template']);
247
  $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
 
248
  $temp = str_replace("%POST_TITLE%", $post_title, $temp);
249
  $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
250
  $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
@@ -293,7 +309,8 @@ if(!function_exists('get_most_viewed')) {
293
  }
294
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
295
  $temp = stripslashes($views_options['most_viewed_template']);
296
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
 
297
  $temp = str_replace("%POST_TITLE%", $post_title, $temp);
298
  $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
299
  $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
@@ -658,12 +675,10 @@ function views_sorting($local_wp_query) {
658
  add_action('wp','postviews_wp_stats');
659
  function postviews_wp_stats() {
660
  if(function_exists('stats_page')) {
661
- if(strpos(get_option('stats_url'), $_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], 'stats-options.php') || strpos($_SERVER['REQUEST_URI'], 'wp-stats/wp-stats.php')) {
662
- add_filter('wp_stats_page_admin_plugins', 'postviews_page_admin_general_stats');
663
- add_filter('wp_stats_page_admin_most', 'postviews_page_admin_most_stats');
664
- add_filter('wp_stats_page_plugins', 'postviews_page_general_stats');
665
- add_filter('wp_stats_page_most', 'postviews_page_most_stats');
666
- }
667
  }
668
  }
669
 
@@ -795,6 +810,18 @@ function sort_postviews($query) {
795
  }
796
  }
797
 
 
 
 
 
 
 
 
 
 
 
 
 
798
 
799
  ### Class: WP-PostViews Widget
800
  class WP_Widget_PostViews extends WP_Widget {
3
  Plugin Name: WP-PostViews
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Enables you to display how many times a post/page had been viewed.
6
+ Version: 1.69
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-postviews
200
 
201
  ### Function: Display The Post Views
202
  function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
203
+ $post_views = intval( get_post_meta( get_the_ID(), 'views', true ) );
204
  $views_options = get_option('views_options');
205
  if ($always || should_views_be_displayed($views_options)) {
206
+ $output = $prefix.str_replace( array( '%VIEW_COUNT%', '%VIEW_COUNT_ROUNDED%' ), array( number_format_i18n( $post_views ), postviews_round_number( $post_views) ), stripslashes( $views_options['template'] ) ).$postfix;
207
  if($display) {
208
  echo apply_filters('the_views', $output);
209
  } else {
215
  }
216
  }
217
 
218
+ ### Function: Short Code For Inserting Views Into Posts
219
+ add_shortcode( 'views', 'views_shortcode' );
220
+ function views_shortcode( $atts ) {
221
+ $attributes = shortcode_atts( array( 'id' => 0 ), $atts );
222
+ $id = intval( $attributes['id'] );
223
+ if( $id === 0) {
224
+ $id = get_the_ID();
225
+ }
226
+ $views_options = get_option( 'views_options' );
227
+ $post_views = intval( get_post_meta( $id, 'views', true ) );
228
+ $output = str_replace( array( '%VIEW_COUNT%', '%VIEW_COUNT_ROUNDED%' ), array( number_format_i18n( $post_views ), postviews_round_number( $post_views) ), stripslashes( $views_options['template'] ) );
229
+
230
+ return apply_filters( 'the_views', $output );
231
+ }
232
+
233
 
234
  ### Function: Display Least Viewed Page/Post
235
  if(!function_exists('get_least_viewed')) {
260
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
261
  $temp = stripslashes($views_options['most_viewed_template']);
262
  $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
263
+ $temp = str_replace("%VIEW_COUNT_ROUNDED%", postviews_round_number( $post_views ), $temp);
264
  $temp = str_replace("%POST_TITLE%", $post_title, $temp);
265
  $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
266
  $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
309
  }
310
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
311
  $temp = stripslashes($views_options['most_viewed_template']);
312
+ $temp = str_replace("%VIEW_COUNT%", number_format_i18n( $post_views ), $temp);
313
+ $temp = str_replace("%VIEW_COUNT_ROUNDED%", postviews_round_number( $post_views ), $temp);
314
  $temp = str_replace("%POST_TITLE%", $post_title, $temp);
315
  $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
316
  $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
675
  add_action('wp','postviews_wp_stats');
676
  function postviews_wp_stats() {
677
  if(function_exists('stats_page')) {
678
+ add_filter('wp_stats_page_admin_plugins', 'postviews_page_admin_general_stats');
679
+ add_filter('wp_stats_page_admin_most', 'postviews_page_admin_most_stats');
680
+ add_filter('wp_stats_page_plugins', 'postviews_page_general_stats');
681
+ add_filter('wp_stats_page_most', 'postviews_page_most_stats');
 
 
682
  }
683
  }
684
 
810
  }
811
  }
812
 
813
+ ### Function: Round Numbers To K (Thousand), M (Million) or B (Billion)
814
+ function postviews_round_number( $number, $min_value = 1000, $decimal = 1 ) {
815
+ if( $number < $min_value ) {
816
+ return number_format_i18n( $number );
817
+ }
818
+ $alphabets = array( 1000000000 => 'B', 1000000 => 'M', 1000 => 'K' );
819
+ foreach( $alphabets as $key => $value )
820
+ if( $number >= $key ) {
821
+ return round( $number / $key, $decimal ) . '' . $value;
822
+ }
823
+ }
824
+
825
 
826
  ### Class: WP-PostViews Widget
827
  class WP_Widget_PostViews extends WP_Widget {