WP-PostViews - Version 1.74

Version Description

N/A

Download this release

Release Info

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

Code changes from version 1.73 to 1.74

Files changed (4) hide show
  1. postviews-options.php +2 -1
  2. readme.txt +8 -4
  3. wp-postviews.php +81 -76
  4. wp-postviews.pot +2 -2
postviews-options.php CHANGED
@@ -127,7 +127,8 @@ if( !isset ( $views_options['use_ajax'] ) ) {
127
  - %POST_EXCERPT%<br />
128
  - %POST_CONTENT%<br />
129
  - %POST_URL%<br />
130
- - %POST_THUMBNAIL%<br /><br />
 
131
  <input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'most_viewed' );" class="button" />
132
  </td>
133
  <td valign="top">
127
  - %POST_EXCERPT%<br />
128
  - %POST_CONTENT%<br />
129
  - %POST_URL%<br />
130
+ - %POST_THUMBNAIL%<br />
131
+ - %POST_CATEGORY_ID%<br /><br />
132
  <input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'most_viewed' );" class="button" />
133
  </td>
134
  <td valign="top">
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WP-PostViews ===
2
  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.5
7
- Stable tag: 1.73
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 appreciate it. If not feel free to use it without any obligations.
27
 
28
  == Changelog ==
 
 
 
 
29
  = Version 1.73 =
30
  * FIXED: In preview mode, don't count views
31
 
1
  === WP-PostViews ===
2
  Contributors: GamerZ
3
+ Donate link: https://lesterchan.net/site/donation/
4
  Tags: views, hits, counter, postviews
5
+ Requires at least: 4.0
6
+ Tested up to: 4.7
7
+ Stable tag: 1.74
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 appreciate it. If not feel free to use it without any obligations.
27
 
28
  == Changelog ==
29
+ = Version 1.74 =
30
+ * NEW: Bump WordPress 4.7
31
+ * NEW: Template variable %POST_CATEGORY_ID%. It returns Post's Category ID. If you are using Yoast SEO Plugin, it will return the priority Category ID. Props @FunFrog-BY
32
+
33
  = Version 1.73 =
34
  * FIXED: In preview mode, don't count views
35
 
wp-postviews.php CHANGED
@@ -1,17 +1,17 @@
1
  <?php
2
  /*
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.73
7
  Author: Lester 'GaMerZ' Chan
8
- Author URI: http://lesterchan.net
9
  Text Domain: wp-postviews
10
  */
11
 
12
 
13
  /*
14
- Copyright 2015 Lester Chan (email : lesterchan@gmail.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
@@ -78,8 +78,7 @@ function process_postviews() {
78
  if( intval( $views_options['exclude_bots'] ) === 1 ) {
79
  $bots = array
80
  (
81
- 'Google Bot' => 'googlebot'
82
- , 'Google Bot' => 'google'
83
  , 'MSN' => 'msnbot'
84
  , 'Alex' => 'ia_archiver'
85
  , 'Lycos' => 'lycos'
@@ -108,9 +107,9 @@ function process_postviews() {
108
  , 'soso.com' => 'sosospider'
109
  , 'Yandex' => 'yandex'
110
  );
111
- $useragent = $_SERVER['HTTP_USER_AGENT'];
112
  foreach ( $bots as $name => $lookfor ) {
113
- if ( stristr( $useragent, $lookfor ) !== false ) {
114
  $should_count = false;
115
  break;
116
  }
@@ -249,8 +248,8 @@ if(!function_exists('get_least_viewed')) {
249
  } else {
250
  $where = '1=1';
251
  }
252
- $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views ASC LIMIT $limit");
253
- if($most_viewed) {
254
  foreach ($most_viewed as $post) {
255
  $post_views = intval($post->views);
256
  $post_title = get_the_title($post);
@@ -260,15 +259,16 @@ if(!function_exists('get_least_viewed')) {
260
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
261
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
262
  $temp = stripslashes($views_options['most_viewed_template']);
263
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
264
- $temp = str_replace("%VIEW_COUNT_ROUNDED%", postviews_round_number( $post_views ), $temp);
265
- $temp = str_replace("%POST_TITLE%", $post_title, $temp);
266
- $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
267
- $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
268
- $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
269
- $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
270
- $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
271
- $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
 
272
  $output .= $temp;
273
  }
274
  } else {
@@ -301,7 +301,7 @@ if(!function_exists('get_most_viewed')) {
301
  } else {
302
  $where = '1=1';
303
  }
304
- $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
305
  if($most_viewed) {
306
  foreach ($most_viewed as $post) {
307
  $post_views = intval($post->views);
@@ -309,18 +309,19 @@ if(!function_exists('get_most_viewed')) {
309
  if($chars > 0) {
310
  $post_title = snippet_text($post_title, $chars);
311
  }
312
- $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
313
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
 
314
  $temp = stripslashes($views_options['most_viewed_template']);
315
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n( $post_views ), $temp);
316
- $temp = str_replace("%VIEW_COUNT_ROUNDED%", postviews_round_number( $post_views ), $temp);
317
- $temp = str_replace("%POST_TITLE%", $post_title, $temp);
318
- $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
319
- $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
320
- $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
321
- $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
322
- $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
323
- $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
 
324
  $output .= $temp;
325
  }
326
  } else {
@@ -335,7 +336,7 @@ if(!function_exists('get_most_viewed')) {
335
  }
336
 
337
 
338
- ### Function: Display Leased Viewed Page/Post By Category ID
339
  if(!function_exists('get_least_viewed_category')) {
340
  function get_least_viewed_category($category_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true) {
341
  global $wpdb;
@@ -344,9 +345,9 @@ if(!function_exists('get_least_viewed_category')) {
344
  $temp = '';
345
  $output = '';
346
  if(is_array($category_id)) {
347
- $category_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $category_id).')';
348
  } else {
349
- $category_sql = "$wpdb->term_taxonomy.term_id = $category_id";
350
  }
351
  if(!empty($mode) && $mode != 'both') {
352
  if(is_array($mode)) {
@@ -358,7 +359,7 @@ if(!function_exists('get_least_viewed_category')) {
358
  } else {
359
  $where = '1=1';
360
  }
361
- $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'category' AND $category_sql AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views ASC LIMIT $limit");
362
  if($most_viewed) {
363
  foreach ($most_viewed as $post) {
364
  $post_views = intval($post->views);
@@ -369,14 +370,15 @@ if(!function_exists('get_least_viewed_category')) {
369
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
370
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
371
  $temp = stripslashes($views_options['most_viewed_template']);
372
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
373
- $temp = str_replace("%POST_TITLE%", $post_title, $temp);
374
- $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
375
- $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
376
- $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
377
- $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
378
- $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
379
- $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
 
380
  $output .= $temp;
381
  }
382
  } else {
@@ -400,9 +402,9 @@ if(!function_exists('get_most_viewed_category')) {
400
  $temp = '';
401
  $output = '';
402
  if(is_array($category_id)) {
403
- $category_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $category_id).')';
404
  } else {
405
- $category_sql = "$wpdb->term_taxonomy.term_id = $category_id";
406
  }
407
  if(!empty($mode) && $mode != 'both') {
408
  if(is_array($mode)) {
@@ -414,7 +416,7 @@ if(!function_exists('get_most_viewed_category')) {
414
  } else {
415
  $where = '1=1';
416
  }
417
- $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'category' AND $category_sql AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
418
  if($most_viewed) {
419
  foreach ($most_viewed as $post) {
420
  $post_views = intval($post->views);
@@ -425,14 +427,15 @@ if(!function_exists('get_most_viewed_category')) {
425
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
426
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
427
  $temp = stripslashes($views_options['most_viewed_template']);
428
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
429
- $temp = str_replace("%POST_TITLE%", $post_title, $temp);
430
- $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
431
- $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
432
- $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
433
- $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
434
- $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
435
- $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
 
436
  $output .= $temp;
437
  }
438
  } else {
@@ -456,9 +459,9 @@ if(!function_exists('get_most_viewed_tag')) {
456
  $temp = '';
457
  $output = '';
458
  if(is_array($tag_id)) {
459
- $tag_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $tag_id).')';
460
  } else {
461
- $tag_sql = "$wpdb->term_taxonomy.term_id = $tag_id";
462
  }
463
  if(!empty($mode) && $mode != 'both') {
464
  if(is_array($mode)) {
@@ -470,7 +473,7 @@ if(!function_exists('get_most_viewed_tag')) {
470
  } else {
471
  $where = '1=1';
472
  }
473
- $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'post_tag' AND $tag_sql AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
474
  if($most_viewed) {
475
  foreach ($most_viewed as $post) {
476
  $post_views = intval($post->views);
@@ -481,14 +484,15 @@ if(!function_exists('get_most_viewed_tag')) {
481
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
482
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
483
  $temp = stripslashes($views_options['most_viewed_template']);
484
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
485
- $temp = str_replace("%POST_TITLE%", $post_title, $temp);
486
- $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
487
- $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
488
- $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
489
- $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
490
- $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
491
- $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
 
492
  $output .= $temp;
493
  }
494
  } else {
@@ -512,9 +516,9 @@ if(!function_exists('get_least_viewed_tag')) {
512
  $temp = '';
513
  $output = '';
514
  if(is_array($tag_id)) {
515
- $tag_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $tag_id).')';
516
  } else {
517
- $tag_sql = "$wpdb->term_taxonomy.term_id = $tag_id";
518
  }
519
  if(!empty($mode) && $mode != 'both') {
520
  if(is_array($mode)) {
@@ -526,7 +530,7 @@ if(!function_exists('get_least_viewed_tag')) {
526
  } else {
527
  $where = '1=1';
528
  }
529
- $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date < '".current_time('mysql')."' AND $wpdb->term_taxonomy.taxonomy = 'post_tag' AND $tag_sql AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views ASC LIMIT $limit");
530
  if($most_viewed) {
531
  foreach ($most_viewed as $post) {
532
  $post_views = intval($post->views);
@@ -537,14 +541,15 @@ if(!function_exists('get_least_viewed_tag')) {
537
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
538
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
539
  $temp = stripslashes($views_options['most_viewed_template']);
540
- $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
541
- $temp = str_replace("%POST_TITLE%", $post_title, $temp);
542
- $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
543
- $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
544
- $temp = str_replace("%POST_URL%", get_permalink($post), $temp);
545
- $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp);
546
- $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp);
547
- $temp = str_replace("%POST_THUMBNAIL%", $thumbnail, $temp);
 
548
  $output .= $temp;
549
  }
550
  } else {
@@ -922,7 +927,7 @@ function postviews_round_number( $number, $min_value = 1000, $decimal = 1 ) {
922
  </p>
923
  <p>
924
  <label for="<?php echo $this->get_field_id('cat_ids'); ?>"><?php _e('Category IDs:', 'wp-postviews'); ?> <span style="color: red;">*</span> <input class="widefat" id="<?php echo $this->get_field_id('cat_ids'); ?>" name="<?php echo $this->get_field_name('cat_ids'); ?>" type="text" value="<?php echo $cat_ids; ?>" /></label><br />
925
- <small><?php _e('Seperate mutiple categories with commas.', 'wp-postviews'); ?></small>
926
  </p>
927
  <p style="color: red;">
928
  <small><?php _e('* If you are not using any category statistics, you can ignore it.', 'wp-postviews'); ?></small>
1
  <?php
2
  /*
3
  Plugin Name: WP-PostViews
4
+ Plugin URI: https://lesterchan.net/portfolio/programming/php/
5
  Description: Enables you to display how many times a post/page had been viewed.
6
+ Version: 1.74
7
  Author: Lester 'GaMerZ' Chan
8
+ Author URI: https://lesterchan.net
9
  Text Domain: wp-postviews
10
  */
11
 
12
 
13
  /*
14
+ Copyright 2016 Lester Chan (email : lesterchan@gmail.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
78
  if( intval( $views_options['exclude_bots'] ) === 1 ) {
79
  $bots = array
80
  (
81
+ 'Google Bot' => 'google'
 
82
  , 'MSN' => 'msnbot'
83
  , 'Alex' => 'ia_archiver'
84
  , 'Lycos' => 'lycos'
107
  , 'soso.com' => 'sosospider'
108
  , 'Yandex' => 'yandex'
109
  );
110
+ $useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
111
  foreach ( $bots as $name => $lookfor ) {
112
+ if ( ! empty( $useragent ) && ( stristr( $useragent, $lookfor ) !== false ) ) {
113
  $should_count = false;
114
  break;
115
  }
248
  } else {
249
  $where = '1=1';
250
  }
251
+ $most_viewed = $wpdb->get_results("SELECT DISTINCT p.*, (pm1.meta_value+0) AS views, IF((pm2.meta_value IS NULL) OR (pm2.meta_value = ''), tt.term_id, pm2.meta_value) AS cat_id FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm1 ON pm1.post_id = p.ID LEFT JOIN $wpdb->postmeta pm2 ON (pm2.post_id = p.ID AND pm2.meta_key='_yoast_wpseo_primary_category') INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category') WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND pm1.meta_key = 'views' AND post_password = '' GROUP BY p.ID ORDER BY views ASC LIMIT $limit");
252
+ if($most_viewed) {
253
  foreach ($most_viewed as $post) {
254
  $post_views = intval($post->views);
255
  $post_title = get_the_title($post);
259
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
260
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
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);
267
+ $temp = str_replace('%POST_URL%', get_permalink($post), $temp);
268
+ $temp = str_replace('%POST_DATE%', get_the_time(get_option('date_format'), $post), $temp);
269
+ $temp = str_replace('%POST_TIME%', get_the_time(get_option('time_format'), $post), $temp);
270
+ $temp = str_replace('%POST_THUMBNAIL%', $thumbnail, $temp);
271
+ $temp = str_replace('%POST_CATEGORY_ID%', $post->cat_id, $temp);
272
  $output .= $temp;
273
  }
274
  } else {
301
  } else {
302
  $where = '1=1';
303
  }
304
+ $most_viewed = $wpdb->get_results("SELECT DISTINCT p.*, (pm1.meta_value+0) AS views, IF((pm2.meta_value IS NULL) OR (pm2.meta_value = ''), tt.term_id, pm2.meta_value) AS cat_id FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm1 ON pm1.post_id = p.ID LEFT JOIN $wpdb->postmeta pm2 ON (pm2.post_id = p.ID AND pm2.meta_key='_yoast_wpseo_primary_category') INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category') WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND pm1.meta_key = 'views' AND post_password = '' GROUP BY p.ID ORDER BY views DESC LIMIT $limit");
305
  if($most_viewed) {
306
  foreach ($most_viewed as $post) {
307
  $post_views = intval($post->views);
309
  if($chars > 0) {
310
  $post_title = snippet_text($post_title, $chars);
311
  }
 
312
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
313
+ $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
314
  $temp = stripslashes($views_options['most_viewed_template']);
315
+ $temp = str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $temp);
316
+ $temp = str_replace('%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp);
317
+ $temp = str_replace('%POST_TITLE%', $post_title, $temp);
318
+ $temp = str_replace('%POST_EXCERPT%', $post_excerpt, $temp);
319
+ $temp = str_replace('%POST_CONTENT%', $post->post_content, $temp);
320
+ $temp = str_replace('%POST_URL%', get_permalink($post), $temp);
321
+ $temp = str_replace('%POST_DATE%', get_the_time(get_option('date_format'), $post), $temp);
322
+ $temp = str_replace('%POST_TIME%', get_the_time(get_option('time_format'), $post), $temp);
323
+ $temp = str_replace('%POST_THUMBNAIL%', $thumbnail, $temp);
324
+ $temp = str_replace('%POST_CATEGORY_ID%', $post->cat_id, $temp);
325
  $output .= $temp;
326
  }
327
  } else {
336
  }
337
 
338
 
339
+ ### Function: Display Least Viewed Page/Post By Category ID
340
  if(!function_exists('get_least_viewed_category')) {
341
  function get_least_viewed_category($category_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true) {
342
  global $wpdb;
345
  $temp = '';
346
  $output = '';
347
  if(is_array($category_id)) {
348
+ $category_sql = 'tt.term_id IN ('.join(',', $category_id).')';
349
  } else {
350
+ $category_sql = "tt.term_id = $category_id";
351
  }
352
  if(!empty($mode) && $mode != 'both') {
353
  if(is_array($mode)) {
359
  } else {
360
  $where = '1=1';
361
  }
362
+ $most_viewed = $wpdb->get_results("SELECT DISTINCT p.*, (pm1.meta_value+0) AS views, IF((pm2.meta_value IS NULL) OR (pm2.meta_value = ''), tt.term_id, pm2.meta_value) AS cat_id FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm1 ON pm1.post_id = p.ID LEFT JOIN $wpdb->postmeta pm2 ON (pm2.post_id = p.ID AND pm2.meta_key='_yoast_wpseo_primary_category') INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND $category_sql) WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND pm1.meta_key = 'views' AND post_password = '' GROUP BY p.ID ORDER BY views ASC LIMIT $limit");
363
  if($most_viewed) {
364
  foreach ($most_viewed as $post) {
365
  $post_views = intval($post->views);
370
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
371
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
372
  $temp = stripslashes($views_options['most_viewed_template']);
373
+ $temp = str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $temp);
374
+ $temp = str_replace('%POST_TITLE%', $post_title, $temp);
375
+ $temp = str_replace('%POST_EXCERPT%', $post_excerpt, $temp);
376
+ $temp = str_replace('%POST_CONTENT%', $post->post_content, $temp);
377
+ $temp = str_replace('%POST_URL%', get_permalink($post), $temp);
378
+ $temp = str_replace('%POST_DATE%', get_the_time(get_option('date_format'), $post), $temp);
379
+ $temp = str_replace('%POST_TIME%', get_the_time(get_option('time_format'), $post), $temp);
380
+ $temp = str_replace('%POST_THUMBNAIL%', $thumbnail, $temp);
381
+ $temp = str_replace('%POST_CATEGORY_ID%', $post->cat_id, $temp);
382
  $output .= $temp;
383
  }
384
  } else {
402
  $temp = '';
403
  $output = '';
404
  if(is_array($category_id)) {
405
+ $category_sql = 'tt.term_id IN ('.join(',', $category_id).')';
406
  } else {
407
+ $category_sql = "tt.term_id = $category_id";
408
  }
409
  if(!empty($mode) && $mode != 'both') {
410
  if(is_array($mode)) {
416
  } else {
417
  $where = '1=1';
418
  }
419
+ $most_viewed = $wpdb->get_results("SELECT DISTINCT p.*, (pm1.meta_value+0) AS views, IF((pm2.meta_value IS NULL) OR (pm2.meta_value = ''), tt.term_id, pm2.meta_value) AS cat_id FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm1 ON pm1.post_id = p.ID LEFT JOIN $wpdb->postmeta pm2 ON (pm2.post_id = p.ID AND pm2.meta_key='_yoast_wpseo_primary_category') INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND $category_sql) WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND pm1.meta_key = 'views' AND post_password = '' GROUP BY p.ID ORDER BY views DESC LIMIT $limit");
420
  if($most_viewed) {
421
  foreach ($most_viewed as $post) {
422
  $post_views = intval($post->views);
427
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
428
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
429
  $temp = stripslashes($views_options['most_viewed_template']);
430
+ $temp = str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $temp);
431
+ $temp = str_replace('%POST_TITLE%', $post_title, $temp);
432
+ $temp = str_replace('%POST_EXCERPT%', $post_excerpt, $temp);
433
+ $temp = str_replace('%POST_CONTENT%', $post->post_content, $temp);
434
+ $temp = str_replace('%POST_URL%', get_permalink($post), $temp);
435
+ $temp = str_replace('%POST_DATE%', get_the_time(get_option('date_format'), $post), $temp);
436
+ $temp = str_replace('%POST_TIME%', get_the_time(get_option('time_format'), $post), $temp);
437
+ $temp = str_replace('%POST_THUMBNAIL%', $thumbnail, $temp);
438
+ $temp = str_replace('%POST_CATEGORY_ID%', $post->cat_id, $temp);
439
  $output .= $temp;
440
  }
441
  } else {
459
  $temp = '';
460
  $output = '';
461
  if(is_array($tag_id)) {
462
+ $tag_sql = 'tt.term_id IN ('.join(',', $tag_id).')';
463
  } else {
464
+ $tag_sql = "tt.term_id = $tag_id";
465
  }
466
  if(!empty($mode) && $mode != 'both') {
467
  if(is_array($mode)) {
473
  } else {
474
  $where = '1=1';
475
  }
476
+ $most_viewed = $wpdb->get_results("SELECT DISTINCT p.*, (pm1.meta_value+0) AS views, IF((pm2.meta_value IS NULL) OR (pm2.meta_value = ''), tt2.term_id, pm2.meta_value) AS cat_id FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm1 ON pm1.post_id = p.ID LEFT JOIN $wpdb->postmeta pm2 ON (pm2.post_id = p.ID AND pm2.meta_key='_yoast_wpseo_primary_category') INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'post_tag' AND $tag_sql) INNER JOIN $wpdb->term_relationships tr2 ON (p.ID = tr2.object_id) LEFT JOIN $wpdb->term_taxonomy tt2 ON (tr2.term_taxonomy_id = tt2.term_taxonomy_id AND tt2.taxonomy = 'category') WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND pm1.meta_key = 'views' AND post_password = '' GROUP BY p.ID ORDER BY views DESC LIMIT $limit");
477
  if($most_viewed) {
478
  foreach ($most_viewed as $post) {
479
  $post_views = intval($post->views);
484
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
485
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
486
  $temp = stripslashes($views_options['most_viewed_template']);
487
+ $temp = str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $temp);
488
+ $temp = str_replace('%POST_TITLE%', $post_title, $temp);
489
+ $temp = str_replace('%POST_EXCERPT%', $post_excerpt, $temp);
490
+ $temp = str_replace('%POST_CONTENT%', $post->post_content, $temp);
491
+ $temp = str_replace('%POST_URL%', get_permalink($post), $temp);
492
+ $temp = str_replace('%POST_DATE%', get_the_time(get_option('date_format'), $post), $temp);
493
+ $temp = str_replace('%POST_TIME%', get_the_time(get_option('time_format'), $post), $temp);
494
+ $temp = str_replace('%POST_THUMBNAIL%', $thumbnail, $temp);
495
+ $temp = str_replace('%POST_CATEGORY_ID%', $post->cat_id, $temp);
496
  $output .= $temp;
497
  }
498
  } else {
516
  $temp = '';
517
  $output = '';
518
  if(is_array($tag_id)) {
519
+ $tag_sql = 'tt.term_id IN ('.join(',', $tag_id).')';
520
  } else {
521
+ $tag_sql = "tt.term_id = $tag_id";
522
  }
523
  if(!empty($mode) && $mode != 'both') {
524
  if(is_array($mode)) {
530
  } else {
531
  $where = '1=1';
532
  }
533
+ $most_viewed = $wpdb->get_results("SELECT DISTINCT p.*, (pm1.meta_value+0) AS views, IF((pm2.meta_value IS NULL) OR (pm2.meta_value = ''), tt2.term_id, pm2.meta_value) AS cat_id FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm1 ON pm1.post_id = p.ID LEFT JOIN $wpdb->postmeta pm2 ON (pm2.post_id = p.ID AND pm2.meta_key='_yoast_wpseo_primary_category') INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'post_tag' AND $tag_sql) INNER JOIN $wpdb->term_relationships tr2 ON (p.ID = tr2.object_id) LEFT JOIN $wpdb->term_taxonomy tt2 ON (tr2.term_taxonomy_id = tt2.term_taxonomy_id AND tt2.taxonomy = 'category') WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND pm1.meta_key = 'views' AND post_password = '' GROUP BY p.ID ORDER BY views ASC LIMIT $limit");
534
  if($most_viewed) {
535
  foreach ($most_viewed as $post) {
536
  $post_views = intval($post->views);
541
  $thumbnail = get_the_post_thumbnail($post->ID,'thumbnail',true);
542
  $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
543
  $temp = stripslashes($views_options['most_viewed_template']);
544
+ $temp = str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $temp);
545
+ $temp = str_replace('%POST_TITLE%', $post_title, $temp);
546
+ $temp = str_replace('%POST_EXCERPT%', $post_excerpt, $temp);
547
+ $temp = str_replace('%POST_CONTENT%', $post->post_content, $temp);
548
+ $temp = str_replace('%POST_URL%', get_permalink($post), $temp);
549
+ $temp = str_replace('%POST_DATE%', get_the_time(get_option('date_format'), $post), $temp);
550
+ $temp = str_replace('%POST_TIME%', get_the_time(get_option('time_format'), $post), $temp);
551
+ $temp = str_replace('%POST_THUMBNAIL%', $thumbnail, $temp);
552
+ $temp = str_replace('%POST_CATEGORY_ID%', $post->cat_id, $temp);
553
  $output .= $temp;
554
  }
555
  } else {
927
  </p>
928
  <p>
929
  <label for="<?php echo $this->get_field_id('cat_ids'); ?>"><?php _e('Category IDs:', 'wp-postviews'); ?> <span style="color: red;">*</span> <input class="widefat" id="<?php echo $this->get_field_id('cat_ids'); ?>" name="<?php echo $this->get_field_name('cat_ids'); ?>" type="text" value="<?php echo $cat_ids; ?>" /></label><br />
930
+ <small><?php _e('Separate mutiple categories with commas.', 'wp-postviews'); ?></small>
931
  </p>
932
  <p style="color: red;">
933
  <small><?php _e('* If you are not using any category statistics, you can ignore it.', 'wp-postviews'); ?></small>
wp-postviews.pot CHANGED
@@ -139,7 +139,7 @@ msgid "Don't display on home page"
139
  msgstr ""
140
 
141
  #: postviews-options.php:201
142
- msgid "Singe Posts:"
143
  msgstr ""
144
 
145
  #: postviews-options.php:206
@@ -319,7 +319,7 @@ msgid "Category IDs:"
319
  msgstr ""
320
 
321
  #: wp-postviews.php:765
322
- msgid "Seperate mutiple categories with commas."
323
  msgstr ""
324
 
325
  #: wp-postviews.php:768
139
  msgstr ""
140
 
141
  #: postviews-options.php:201
142
+ msgid "Single Posts:"
143
  msgstr ""
144
 
145
  #: postviews-options.php:206
319
  msgstr ""
320
 
321
  #: wp-postviews.php:765
322
+ msgid "Separate mutiple categories with commas."
323
  msgstr ""
324
 
325
  #: wp-postviews.php:768