File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/wp-postviews.tar
postviews-cache.js 0000644 00000000767 15153230044 0010215 0 ustar 00 fetch( viewsCacheL10n.admin_ajax_url, {
method: "POST",
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache',
},
body: new URLSearchParams(
{
action: 'postviews',
nonce: viewsCacheL10n.nonce,
postviews_id: viewsCacheL10n.post_id,
cache: !1,
}
),
})
.then(function(response) {
return response.json();
})
.then(function(data) {
})
.catch(function(error) {
console.log('WP-PostViews');
console.log(error);
});
postviews-options.php 0000644 00000025377 15153230044 0011024 0 ustar 00 <?php
### Variables Variables Variables
$base_name = plugin_basename( 'wp-postviews/postviews-options.php' );
$base_page = 'admin.php?page='.$base_name;
$id = ( isset($_GET['id'] ) ? (int) sanitize_key( $_GET['id'] ) : 0 );
$mode = ( isset($_GET['mode'] ) ? sanitize_key( trim( $_GET['mode'] ) ) : '' );
$text = '';
### Form Processing
if(!empty($_POST['Submit'] )) {
check_admin_referer( 'wp-postviews_options' );
$views_options = array(
'count' => (int) sanitize_key( views_options_parse('views_count') )
, 'exclude_bots' => (int) sanitize_key( views_options_parse('views_exclude_bots') )
, 'display_home' => (int) sanitize_key( views_options_parse('views_display_home') )
, 'display_single' => (int) sanitize_key( views_options_parse('views_display_single') )
, 'display_page' => (int) sanitize_key( views_options_parse('views_display_page') )
, 'display_archive' => (int) sanitize_key( views_options_parse('views_display_archive') )
, 'display_search' => (int) sanitize_key( views_options_parse('views_display_search') )
, 'display_other' => (int) sanitize_key( views_options_parse('views_display_other') )
, 'use_ajax' => (int) sanitize_key( views_options_parse('views_use_ajax') )
, 'template' => wp_kses_post( trim( views_options_parse('views_template_template') ) )
, 'most_viewed_template' => wp_kses_post( trim( views_options_parse('views_template_most_viewed') ) )
);
$update_views_queries = array();
$update_views_text = array();
$update_views_queries[] = update_option( 'views_options', $views_options );
$update_views_text[] = __( 'Post Views Options', 'wp-postviews' );
$i = 0;
foreach( $update_views_queries as $update_views_query ) {
if( $update_views_query ) {
$text .= '<p style="color: green;">' . $update_views_text[$i] . ' ' . __( 'Updated', 'wp-postviews' ) . '</p>';
}
$i++;
}
if( empty( $text ) ) {
$text = '<p style="color: red;">' . __( 'No Post Views Option Updated', 'wp-postviews' ) . '</p>';
}
}
$views_options = get_option( 'views_options' );
// Default
if( !isset ( $views_options['use_ajax'] ) ) {
$views_options['use_ajax'] = 1;
}
?>
<script type="text/javascript">
/* <![CDATA[*/
function views_default_templates(template) {
var default_template;
switch(template) {
case 'template':
default_template = "<?php _e( '%VIEW_COUNT% views', 'wp-postviews' ); ?>";
break;
case 'most_viewed':
default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %VIEW_COUNT% <?php _e( 'views', 'wp-postviews' ); ?></li>";
break;
}
jQuery("#views_template_" + template).val(default_template);
}
/* ]]> */
</script>
<?php if( !empty( $text ) ) { echo '<div id="message" class="updated fade"><p>' . $text . '</p></div>'; } ?>
<form method="post" action="<?php echo admin_url( 'admin.php?page=' . plugin_basename( __FILE__ ) ); ?>">
<?php wp_nonce_field( 'wp-postviews_options' ); ?>
<div class="wrap">
<h2><?php _e( 'Post Views Options', 'wp-postviews' ); ?></h2>
<table class="form-table">
<tr>
<td valign="top" width="30%"><strong><?php _e( 'Count Views From:', 'wp-postviews' ); ?></strong></td>
<td valign="top">
<select name="views_count" size="1">
<option value="0"<?php selected( '0', $views_options['count'] ); ?>><?php _e( 'Everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['count'] ); ?>><?php _e( 'Guests Only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['count'] ); ?>><?php _e( 'Registered Users Only', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top" width="30%"><strong><?php _e( 'Exclude Bot Views:', 'wp-postviews' ); ?></strong></td>
<td valign="top">
<select name="views_exclude_bots" size="1">
<option value="0"<?php selected( '0', $views_options['exclude_bots'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['exclude_bots'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<?php if( defined( 'WP_CACHE' ) && WP_CACHE ): ?>
<tr>
<td valign="top" width="30%"><strong><?php _e( 'Use AJAX To Update Views:', 'wp-postviews' ); ?></strong></td>
<td valign="top">
<select name="views_use_ajax" size="1">
<option value="0"<?php selected( '0', $views_options['use_ajax'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['use_ajax'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option>
</select>
<p>
<?php _e( 'You have caching enabled for your WordPress installation, by default WP-PostViews will use AJAX to update the view count. However in some cases, you might not want it.', 'wp-postviews' ); ?>
</p>
</td>
</tr>
<?php else: ?>
<input type="hidden" name="views_use_ajax" value="0" />
<?php endif; ?>
<tr>
<td valign="top">
<strong><?php _e( 'Views Template:', 'wp-postviews' ); ?></strong><br /><br />
<?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
- %VIEW_COUNT%<br />
- %VIEW_COUNT_ROUNDED%<br /><br />
<input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'template' );" class="button" />
</td>
<td valign="top">
<input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php echo htmlspecialchars(stripslashes($views_options['template'] )); ?>" />
</td>
</tr>
<tr>
<td valign="top">
<strong><?php _e( 'Most Viewed Template:', 'wp-postviews' ); ?></strong><br /><br />
<?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
- %VIEW_COUNT%<br />
- %VIEW_COUNT_ROUNDED%<br />
- %POST_TITLE%<br />
- %POST_DATE%<br />
- %POST_TIME%<br />
- %POST_EXCERPT%<br />
- %POST_CONTENT%<br />
- %POST_URL%<br />
- %POST_THUMBNAIL%<br />
- %POST_CATEGORY_ID%<br />
- %POST_AUTHOR%<br /><br />
<input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'most_viewed' );" class="button" />
</td>
<td valign="top">
<textarea cols="80" rows="15" id="views_template_most_viewed" name="views_template_most_viewed"><?php echo htmlspecialchars(stripslashes($views_options['most_viewed_template'] )); ?></textarea>
</td>
</tr>
</table>
<h3><?php _e( 'Display Options', 'wp-postviews' ); ?></h3>
<p><?php _e( 'These options specify where the view counts should be displayed and to whom. By default view counts will be displayed to all visitors. Note that the theme files must contain a call to <code>the_views()</code> in order for any view count to be displayed.', 'wp-postviews' ); ?></p>
<table class="form-table">
<tr>
<td valign="top"><strong><?php _e( 'Home Page:', 'wp-postviews' ); ?></strong></td>
<td>
<select name="views_display_home" size="1">
<option value="0"<?php selected( '0', $views_options['display_home'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['display_home'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['display_home'] ); ?>><?php _e( 'Don\'t display on home page', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e( 'Single Posts:', 'wp-postviews' ); ?></strong></td>
<td>
<select name="views_display_single" size="1">
<option value="0"<?php selected( '0', $views_options['display_single'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['display_single'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['display_single'] ); ?>><?php _e( 'Don\'t display on single posts', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e( 'Pages:', 'wp-postviews' ); ?></strong></td>
<td>
<select name="views_display_page" size="1">
<option value="0"<?php selected( '0', $views_options['display_page'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['display_page'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['display_page'] ); ?>><?php _e( 'Don\'t display on pages', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e( 'Archive Pages:', 'wp-postviews' ); ?></strong></td>
<td>
<select name="views_display_archive" size="1">
<option value="0"<?php selected( '0', $views_options['display_archive'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['display_archive'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['display_archive'] ); ?>><?php _e( 'Don\'t display on archive pages', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e( 'Search Pages:', 'wp-postviews' ); ?></strong></td>
<td>
<select name="views_display_search" size="1">
<option value="0"<?php selected( '0', $views_options['display_search'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['display_search'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['display_search'] ); ?>><?php _e( 'Don\'t display on search pages', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top"><strong><?php _e( 'Other Pages:', 'wp-postviews' ); ?></strong></td>
<td>
<select name="views_display_other" size="1">
<option value="0"<?php selected( '0', $views_options['display_other'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
<option value="1"<?php selected( '1', $views_options['display_other'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
<option value="2"<?php selected( '2', $views_options['display_other'] ); ?>><?php _e( 'Don\'t display on other pages', 'wp-postviews' ); ?></option>
</select>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-postviews' ); ?>" />
</p>
</div>
</form>
readme.txt 0000644 00000017310 15153230044 0006541 0 ustar 00 # WP-PostViews
Contributors: GamerZ
Donate link: https://lesterchan.net/site/donation/
Tags: views, hits, counter, postviews
Requires at least: 4.0
Tested up to: 6.3
Stable tag: 1.77
Enables you to display how many times a post/page had been viewed.
## Description
### Usage
1. Open `wp-content/themes/<YOUR THEME NAME>/index.php`
2. You may place it in archive.php, single.php, post.php or page.php also.
3. Find: `<?php while (have_posts()) : the_post(); ?>`
4. Add Anywhere Below It (The Place You Want The Views To Show): `<?php if(function_exists('the_views')) { the_views(); } ?>`
5. Or you can use the shortcode `[views]` or `[views id="1"]` (where 1 is the post ID) in a post
6. Go to `WP-Admin -> Settings -> PostViews` to configure the plugin.
### Development
[https://github.com/lesterchan/wp-postviews/](https://github.com/lesterchan/wp-postviews/ "https://github.com/lesterchan/wp-postviews/")
### Translations
[http://dev.wp-plugins.org/browser/wp-postviews/i18n/](http://dev.wp-plugins.org/browser/wp-postviews/i18n/ "http://dev.wp-plugins.org/browser/wp-postviews/i18n/")
### Credits
* Plugin icon by [Iconmoon](http://www.icomoon.io) from [Flaticon](http://www.flaticon.com)
### Donations
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.
## Changelog
### Version 1.77
* NEW: Use Vanilla JS. Props @JiveDig
* NEW: Bump to WordPress 6.2
* NEW: Support views under fields for Rest API. Props @vitro-mod
## Version 1.76.1
* NEW: Add Post Author in views template
* NEW: Bump for WordPress 5.3
### Version 1.76
* NEW: Added postviews_should_count filter
* FIXED: Change to (int) from intval() and use sanitize_key() with it.
### Version 1.75
* NEW: Use WP_Query() for most/least viewed posts
### Version 1.74
* NEW: Bump WordPress 4.7
* 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
### Version 1.73
* FIXED: In preview mode, don't count views
### Version 1.72
* NEW: Add %POST_THUMBNAIL% to template variables
### Version 1.71
* FIXED: Notices in Widget Constructor for WordPress 4.3
### Version 1.70
* FIXED: Integration with WP-Stats
### Version 1.69
* NEW: Shortcode `[views]` or [views id="POST_ID"]` to embed view count into post
* NEW: Added template variable `%VIEW_COUNT_ROUNDED%` to support rounded view count like 10.1k or 11.2M
### Version 1.68
* NEW: Added action hook 'postviews_increment_views' and 'postviews_increment_views_ajax'
* NEW: Allow custom post type to be chosen under the widget
### Version 1.67
* NEW: Allow user to not use AJAX to update the views even though WP_CACHE is true
### Version 1.66
* NEW: Supports MultiSite Network Activation
* NEW: Add %POST_DATE% and %POST_TIME% to template variables
* NEW: Add China isearch engines bots
* NEW: Ability to pass in an array of post types for get_most/least_*() functions. Props Leo Plaw.
* FIXED: Moved uninstall to uninstall.php and hence fix missing nonce. Props Julio Potier.
* FIXED: Notices and better way to get views from meta. Props daankortenbach.
* FIXED: No longer needing add_post_meta() if update_post_meta() fails.
### Version 1.65 (02-06-2013)
* FIXED: Views not showing in WP-Admin if "Display Options" is not set to "Display to everyone"
## Upgrade Notice
N/A
## Screenshots
1. PostViews
2. Admin - PostViews Options
## Frequently Asked Questions
### How To View Stats With Widgets?
* Go to `WP-Admin -> Appearance -> Widgets`
* The widget name is Views.
### To Display Least Viewed Posts
~~~
<?php if (function_exists('get_least_viewed')): ?>
<ul>
<?php get_least_viewed(); ?>
</ul>
<?php endif; ?>
~~~
* The first value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example `array('post', 'page')`.
* The second value you pass in is the maximum number of post you want to get.
* Default: get_least_viewed('both', 10);
### To Display Most Viewed Posts
~~~
<?php if (function_exists('get_most_viewed')): ?>
<ul>
<?php get_most_viewed(); ?>
</ul>
<?php endif; ?>
~~~
* The first value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example `array('post', 'page')`.
* The second value you pass in is the maximum number of post you want to get.
* Default: get_most_viewed('both', 10);
### To Display Least Viewed Posts By Tag
~~~
<?php if (function_exists('get_least_viewed_tag')): ?>
<ul>
<?php get_least_viewed_tag(); ?>
</ul>
<?php endif; ?>
~~~
* The first value you pass in is the tag id.
* The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example `array('post', 'page')`.
* The third value you pass in is the maximum number of post you want to get.
* Default: get_least_viewed_tag(1, 'both', 10);
### To Display Most Viewed Posts By Tag
~~~
<?php if (function_exists('get_most_viewed_tag')): ?>
<ul>
<?php get_most_viewed_tag(); ?>
</ul>
<?php endif; ?>
~~~
* The first value you pass in is the tag id.
* The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example `array('post', 'page')`.
* The third value you pass in is the maximum number of post you want to get.
* Default: get_most_viewed_tag(1, 'both', 10);
### To Display Least Viewed Posts For A Category
~~~
<?php if (function_exists('get_least_viewed_category')): ?>
<ul>
<?php get_least_viewed_category(); ?>
</ul>
<?php endif; ?>
~~~
* The first value you pass in is the category id.
* The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example `array('post', 'page')`.
* The third value you pass in is the maximum number of post you want to get.
* Default: get_least_viewed_category(1, 'both', 10);
### To Display Most Viewed Posts For A Category
~~~
<?php if (function_exists('get_most_viewed_category')): ?>
<ul>
<?php get_most_viewed_category(); ?>
</ul>
<?php endif; ?>
~~~
* The first value you pass in is the category id.
* The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example `array('post', 'page')`.
* The third value you pass in is the maximum number of post you want to get.
* Default: get_most_viewed_category(1, 'both', 10);
### To Sort Most/Least Viewed Posts
* You can use: `<?php query_posts( array( 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>`
* Or pass in the variables to the URL: `http://yoursite.com/?v_sortby=views&v_orderby=desc`
* You can replace DESC with ASC if you want the least viewed posts.
### To Display Updating View Count With LiteSpeed Cache
Use: `<div id="postviews_lscwp"></div>` to replace `<?php if(function_exists('the_views')) { the_views(); } ?>`.
NOTE: The id can be changed, but the div id and the ajax function must match.
Replace the ajax query in `wp-content/plugins/wp-postviews/postviews-cache.js` with
~~~
jQuery.ajax({
type:"GET",
url:viewsCacheL10n.admin_ajax_url,
data:"postviews_id="+viewsCacheL10n.post_id+"&action=postviews",
cache:!1,
success:function(data) {
if(data) {
jQuery('#postviews_lscwp').html(data+' views');
}
}
});
~~~
Purge the cache to use the updated pages.
### To Get Views With REST API
You can obtain the number of post views by adding `views` to your `_fields` parameter:
`/wp/v2/posts?_fields=views,title` uninstall.php 0000644 00000001404 15153230044 0007262 0 ustar 00 <?php
/*
* Uninstall plugin
*/
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit ();
if ( is_multisite() ) {
$ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
if( 0 < count( $ms_sites ) ) {
foreach ( $ms_sites as $ms_site ) {
$blog_id = class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id'];
switch_to_blog( $blog_id );
uninstall();
restore_current_blog();
}
}
} else {
uninstall();
}
function uninstall() {
global $wpdb;
$option_names = array( 'views_options', 'widget_views_most_viewed', 'widget_views' );
if( count( $option_names ) > 0 ) {
foreach( $option_names as $option_name ) {
delete_option( $option_name );
}
}
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'views'" );
}
wp-postviews.php 0000644 00000114011 15153230044 0007737 0 ustar 00 <?php
/*
Plugin Name: WP-PostViews
Plugin URI: https://lesterchan.net/portfolio/programming/php/
Description: Enables you to display how many times a post/page had been viewed.
Version: 1.77
Author: Lester 'GaMerZ' Chan
Author URI: https://lesterchan.net
Text Domain: wp-postviews
*/
/*
Copyright 2023 Lester Chan (email : lesterchan@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
### WP-PostViews Version
define( 'WP_POSTVIEWS_VERSION', '1.77' );
### Create Text Domain For Translations
add_action( 'plugins_loaded', 'postviews_textdomain' );
function postviews_textdomain() {
load_plugin_textdomain( 'wp-postviews', false, dirname( plugin_basename( __FILE__ ) ) );
}
### Function: Post Views Option Menu
add_action('admin_menu', 'postviews_menu');
function postviews_menu() {
if (function_exists('add_options_page')) {
add_options_page(__('PostViews', 'wp-postviews'), __('PostViews', 'wp-postviews'), 'manage_options', 'wp-postviews/postviews-options.php') ;
}
}
### Function: Calculate Post Views
add_action( 'wp_head', 'process_postviews' );
function process_postviews() {
global $user_ID, $post;
if ( is_int( $post ) ) {
$post = get_post( $post );
}
if ( ! wp_is_post_revision( $post ) && ! is_preview() ) {
if ( is_single() || is_page() ) {
$id = (int) $post->ID;
$views_options = get_option( 'views_options' );
if ( !$post_views = get_post_meta( $post->ID, 'views', true ) ) {
$post_views = 0;
}
$should_count = false;
switch( (int) $views_options['count'] ) {
case 0:
$should_count = true;
break;
case 1:
if( empty( $_COOKIE[ USER_COOKIE ] ) && (int) $user_ID === 0 ) {
$should_count = true;
}
break;
case 2:
if( (int) $user_ID > 0 ) {
$should_count = true;
}
break;
}
if ( isset( $views_options['exclude_bots'] ) && (int) $views_options['exclude_bots'] === 1 ) {
$bots = array(
'Google Bot' => 'google'
, 'MSN' => 'msnbot'
, 'Alex' => 'ia_archiver'
, 'Lycos' => 'lycos'
, 'Ask Jeeves' => 'jeeves'
, 'Altavista' => 'scooter'
, 'AllTheWeb' => 'fast-webcrawler'
, 'Inktomi' => 'slurp@inktomi'
, 'Turnitin.com' => 'turnitinbot'
, 'Technorati' => 'technorati'
, 'Yahoo' => 'yahoo'
, 'Findexa' => 'findexa'
, 'NextLinks' => 'findlinks'
, 'Gais' => 'gaisbo'
, 'WiseNut' => 'zyborg'
, 'WhoisSource' => 'surveybot'
, 'Bloglines' => 'bloglines'
, 'BlogSearch' => 'blogsearch'
, 'PubSub' => 'pubsub'
, 'Syndic8' => 'syndic8'
, 'RadioUserland' => 'userland'
, 'Gigabot' => 'gigabot'
, 'Become.com' => 'become.com'
, 'Baidu' => 'baiduspider'
, 'so.com' => '360spider'
, 'Sogou' => 'spider'
, 'soso.com' => 'sosospider'
, 'Yandex' => 'yandex'
, 'Ahrefs' => 'AhrefsBot'
, 'Bing' => 'bingbot'
, 'Apple' => 'applebot'
, 'GitCrawler' => 'GitCrawlerBot'
, 'Bytedance' => 'Bytespider'
, 'webmeup' => 'BLEXBot'
);
$useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
foreach ( $bots as $name => $lookfor ) {
if ( ! empty( $useragent ) && ( false !== stripos( $useragent, $lookfor ) ) ) {
$should_count = false;
break;
}
}
}
$should_count = apply_filters( 'postviews_should_count', $should_count, $id );
if( $should_count && ( ( isset( $views_options['use_ajax'] ) && (int) $views_options['use_ajax'] === 0 ) || ( !defined( 'WP_CACHE' ) || !WP_CACHE ) ) ) {
update_post_meta( $id, 'views', $post_views + 1 );
do_action( 'postviews_increment_views', $post_views + 1 );
}
}
}
}
### Function: Calculate Post Views With WP_CACHE Enabled
add_action('wp_enqueue_scripts', 'wp_postview_cache_count_enqueue');
function wp_postview_cache_count_enqueue() {
global $user_ID, $post;
if ( !defined( 'WP_CACHE' ) || !WP_CACHE ) {
return;
}
$views_options = get_option( 'views_options' );
if ( isset( $views_options['use_ajax'] ) && (int) $views_options['use_ajax'] === 0 ) {
return;
}
if ( !wp_is_post_revision( $post ) && ( is_single() || is_page() ) ) {
$should_count = false;
switch( (int) $views_options['count'] ) {
case 0:
$should_count = true;
break;
case 1:
if ( empty( $_COOKIE[USER_COOKIE] ) && (int) $user_ID === 0) {
$should_count = true;
}
break;
case 2:
if ( (int) $user_ID > 0 ) {
$should_count = true;
}
break;
}
$should_count = apply_filters( 'postviews_should_count', $should_count, (int) $post->ID );
if ( $should_count ) {
wp_enqueue_script( 'wp-postviews-cache', plugins_url( 'postviews-cache.js', __FILE__ ), array(), WP_POSTVIEWS_VERSION, true );
wp_localize_script( 'wp-postviews-cache', 'viewsCacheL10n', array( 'admin_ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wp_postviews_nonce' ), 'post_id' => (int) $post->ID ) );
}
}
}
### Function: Determine If Post Views Should Be Displayed (By: David Potter)
function should_views_be_displayed($views_options = null) {
if ($views_options == null) {
$views_options = get_option('views_options');
}
$display_option = 0;
if (is_home()) {
if (array_key_exists('display_home', $views_options)) {
$display_option = $views_options['display_home'];
}
} elseif (is_single()) {
if (array_key_exists('display_single', $views_options)) {
$display_option = $views_options['display_single'];
}
} elseif (is_page()) {
if (array_key_exists('display_page', $views_options)) {
$display_option = $views_options['display_page'];
}
} elseif (is_archive()) {
if (array_key_exists('display_archive', $views_options)) {
$display_option = $views_options['display_archive'];
}
} elseif (is_search()) {
if (array_key_exists('display_search', $views_options)) {
$display_option = $views_options['display_search'];
}
} else {
if (array_key_exists('display_other', $views_options)) {
$display_option = $views_options['display_other'];
}
}
return (($display_option == 0) || (($display_option == 1) && is_user_logged_in()));
}
### Function: Display The Post Views
function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
$post_views = (int) get_post_meta( get_the_ID(), 'views', true );
$views_options = get_option('views_options');
if ($always || should_views_be_displayed($views_options)) {
$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;
if($display) {
echo apply_filters('the_views', $output);
} else {
return apply_filters('the_views', $output);
}
}
elseif (!$display) {
return '';
}
}
### Function: Short Code For Inserting Views Into Posts
add_shortcode( 'views', 'views_shortcode' );
function views_shortcode( $atts ) {
$attributes = shortcode_atts( array( 'id' => 0 ), $atts );
$id = (int) $attributes['id'];
if( $id === 0) {
$id = get_the_ID();
}
$views_options = get_option( 'views_options' );
$post_views = (int) get_post_meta( $id, 'views', true );
$output = str_replace( array( '%VIEW_COUNT%', '%VIEW_COUNT_ROUNDED%' ), array( number_format_i18n( $post_views ), postviews_round_number( $post_views) ), stripslashes( $views_options['template'] ) );
return apply_filters( 'the_views', $output );
}
### Function: Display Least Viewed Page/Post
if ( ! function_exists( 'get_least_viewed' ) ) {
function get_least_viewed( $mode = '', $limit = 10, $chars = 0, $display = true ) {
$views_options = get_option( 'views_options' );
$output = '';
$least_viewed = new WP_Query( array(
'post_type' => ( empty( $mode ) || $mode === 'both' ) ? 'any' : $mode,
'posts_per_page' => $limit,
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_key' => 'views',
) );
if ( $least_viewed->have_posts() ) {
while ( $least_viewed->have_posts() ) {
$least_viewed->the_post();
// Post Views.
$post_views = get_post_meta( get_the_ID(), 'views', true );
// Post Title.
$post_title = get_the_title();
if ( $chars > 0 ) {
$post_title = snippet_text( $post_title, $chars );
}
// Post First Category.
$categories = get_the_category();
$post_category_id = 0;
if ( ! empty( $categories ) ) {
$post_category_id = $categories[0]->term_id;
}
$temp = stripslashes( $views_options['most_viewed_template'] );
$temp = str_replace( '%VIEW_COUNT%', number_format_i18n( $post_views ), $temp );
$temp = str_replace( '%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp );
$temp = str_replace( '%POST_TITLE%', $post_title, $temp );
$temp = str_replace( '%POST_EXCERPT%', get_the_excerpt(), $temp );
$temp = str_replace( '%POST_CONTENT%', get_the_content(), $temp );
$temp = str_replace( '%POST_URL%', get_permalink(), $temp );
$temp = str_replace( '%POST_DATE%', get_the_time( get_option( 'date_format' ) ), $temp );
$temp = str_replace( '%POST_TIME%', get_the_time( get_option( 'time_format' ) ), $temp );
$temp = str_replace( '%POST_THUMBNAIL%', get_the_post_thumbnail( null,'thumbnail',true ), $temp);
$temp = str_replace( '%POST_CATEGORY_ID%', $post_category_id, $temp );
$temp = str_replace( '%POST_AUTHOR%', get_the_author(), $temp );
$output .= $temp;
}
wp_reset_postdata();
} else {
$output = '<li>' . __( 'N/A', 'wp-postviews' ) . '</li>' . "\n";
}
if( $display ) {
echo $output;
} else {
return $output;
}
}
}
### Function: Display Most Viewed Page/Post
if ( ! function_exists( 'get_most_viewed' ) ) {
function get_most_viewed( $mode = '', $limit = 10, $chars = 0, $display = true ) {
$views_options = get_option( 'views_options' );
$output = '';
$most_viewed = new WP_Query( array(
'post_type' => ( empty( $mode ) || $mode === 'both' ) ? 'any' : $mode,
'posts_per_page' => $limit,
'orderby' => 'meta_value_num',
'order' => 'desc',
'meta_key' => 'views',
) );
if ( $most_viewed->have_posts() ) {
while ( $most_viewed->have_posts() ) {
$most_viewed->the_post();
// Post Views.
$post_views = get_post_meta( get_the_ID(), 'views', true );
// Post Title.
$post_title = get_the_title();
if ( $chars > 0 ) {
$post_title = snippet_text( $post_title, $chars );
}
// Post First Category.
$categories = get_the_category();
$post_category_id = 0;
if ( ! empty( $categories ) ) {
$post_category_id = $categories[0]->term_id;
}
$temp = stripslashes( $views_options['most_viewed_template'] );
$temp = str_replace( '%VIEW_COUNT%', number_format_i18n( $post_views ), $temp );
$temp = str_replace( '%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp );
$temp = str_replace( '%POST_TITLE%', $post_title, $temp );
$temp = str_replace( '%POST_EXCERPT%', get_the_excerpt(), $temp );
$temp = str_replace( '%POST_CONTENT%', get_the_content(), $temp );
$temp = str_replace( '%POST_URL%', get_permalink(), $temp );
$temp = str_replace( '%POST_DATE%', get_the_time( get_option( 'date_format' ) ), $temp );
$temp = str_replace( '%POST_TIME%', get_the_time( get_option( 'time_format' ) ), $temp );
$temp = str_replace( '%POST_THUMBNAIL%', get_the_post_thumbnail( null,'thumbnail',true ), $temp);
$temp = str_replace( '%POST_CATEGORY_ID%', $post_category_id, $temp );
$temp = str_replace( '%POST_AUTHOR%', get_the_author(), $temp );
$output .= $temp;
}
wp_reset_postdata();
} else {
$output = '<li>' . __( 'N/A', 'wp-postviews' ) . '</li>' . "\n";
}
if( $display ) {
echo $output;
} else {
return $output;
}
}
}
### Function: Display Least Viewed Page/Post By Category ID
if ( ! function_exists( 'get_least_viewed_category' ) ) {
function get_least_viewed_category( $category_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true ) {
$views_options = get_option( 'views_options' );
$output = '';
$least_viewed = new WP_Query( array(
'post_type' => ( empty( $mode ) || $mode === 'both' ) ? 'any' : $mode,
'posts_per_page' => $limit,
'category__in' => (array) $category_id,
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_key' => 'views',
) );
if ( $least_viewed->have_posts() ) {
while ( $least_viewed->have_posts() ) {
$least_viewed->the_post();
// Post Views.
$post_views = get_post_meta( get_the_ID(), 'views', true );
// Post Title.
$post_title = get_the_title();
if ( $chars > 0 ) {
$post_title = snippet_text( $post_title, $chars );
}
// Post First Category.
$categories = get_the_category();
$post_category_id = 0;
if ( ! empty( $categories ) ) {
$post_category_id = $categories[0]->term_id;
}
$temp = stripslashes( $views_options['most_viewed_template'] );
$temp = str_replace( '%VIEW_COUNT%', number_format_i18n( $post_views ), $temp );
$temp = str_replace( '%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp );
$temp = str_replace( '%POST_TITLE%', $post_title, $temp );
$temp = str_replace( '%POST_EXCERPT%', get_the_excerpt(), $temp );
$temp = str_replace( '%POST_CONTENT%', get_the_content(), $temp );
$temp = str_replace( '%POST_URL%', get_permalink(), $temp );
$temp = str_replace( '%POST_DATE%', get_the_time( get_option( 'date_format' ) ), $temp );
$temp = str_replace( '%POST_TIME%', get_the_time( get_option( 'time_format' ) ), $temp );
$temp = str_replace( '%POST_THUMBNAIL%', get_the_post_thumbnail( null,'thumbnail',true ), $temp);
$temp = str_replace( '%POST_CATEGORY_ID%', $post_category_id, $temp );
$temp = str_replace( '%POST_AUTHOR%', get_the_author(), $temp );
$output .= $temp;
}
wp_reset_postdata();
} else {
$output = '<li>' . __( 'N/A', 'wp-postviews' ) . '</li>' . "\n";
}
if($display) {
echo $output;
} else {
return $output;
}
}
}
### Function: Display Most Viewed Page/Post By Category ID
if ( ! function_exists( 'get_most_viewed_category' ) ) {
function get_most_viewed_category( $category_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true ) {
$views_options = get_option( 'views_options' );
$output = '';
$most_viewed = new WP_Query( array(
'post_type' => ( empty( $mode ) || $mode === 'both' ) ? 'any' : $mode,
'posts_per_page' => $limit,
'category__in' => (array) $category_id,
'orderby' => 'meta_value_num',
'order' => 'desc',
'meta_key' => 'views',
) );
if ( $most_viewed->have_posts() ) {
while ( $most_viewed->have_posts() ) {
$most_viewed->the_post();
// Post Views.
$post_views = get_post_meta( get_the_ID(), 'views', true );
// Post Title.
$post_title = get_the_title();
if ( $chars > 0 ) {
$post_title = snippet_text( $post_title, $chars );
}
// Post First Category.
$categories = get_the_category();
$post_category_id = 0;
if ( ! empty( $categories ) ) {
$post_category_id = $categories[0]->term_id;
}
$temp = stripslashes( $views_options['most_viewed_template'] );
$temp = str_replace( '%VIEW_COUNT%', number_format_i18n( $post_views ), $temp );
$temp = str_replace( '%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp );
$temp = str_replace( '%POST_TITLE%', $post_title, $temp );
$temp = str_replace( '%POST_EXCERPT%', get_the_excerpt(), $temp );
$temp = str_replace( '%POST_CONTENT%', get_the_content(), $temp );
$temp = str_replace( '%POST_URL%', get_permalink(), $temp );
$temp = str_replace( '%POST_DATE%', get_the_time( get_option( 'date_format' ) ), $temp );
$temp = str_replace( '%POST_TIME%', get_the_time( get_option( 'time_format' ) ), $temp );
$temp = str_replace( '%POST_THUMBNAIL%', get_the_post_thumbnail( null,'thumbnail',true ), $temp);
$temp = str_replace( '%POST_CATEGORY_ID%', $post_category_id, $temp );
$temp = str_replace( '%POST_AUTHOR%', get_the_author(), $temp );
$output .= $temp;
}
wp_reset_postdata();
} else {
$output = '<li>' . __( 'N/A', 'wp-postviews' ) . '</li>' . "\n";
}
if ( $display ) {
echo $output;
} else {
return $output;
}
}
}
### Function: Display Least Viewed Page/Post By Tag ID
if ( ! function_exists( 'get_least_viewed_tag' ) ) {
function get_least_viewed_tag( $tag_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true ) {
$views_options = get_option( 'views_options' );
$output = '';
$least_viewed = new WP_Query( array(
'post_type' => ( empty( $mode ) || $mode === 'both' ) ? 'any' : $mode,
'posts_per_page' => $limit,
'tag__in' => (array) $tag_id,
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_key' => 'views',
) );
if ( $least_viewed->have_posts() ) {
while ( $least_viewed->have_posts() ) {
$least_viewed->the_post();
// Post Views.
$post_views = get_post_meta( get_the_ID(), 'views', true );
// Post Title.
$post_title = get_the_title();
if ( $chars > 0 ) {
$post_title = snippet_text( $post_title, $chars );
}
// Post First Category.
$categories = get_the_category();
$post_category_id = 0;
if ( ! empty( $categories ) ) {
$post_category_id = $categories[0]->term_id;
}
$temp = stripslashes( $views_options['most_viewed_template'] );
$temp = str_replace( '%VIEW_COUNT%', number_format_i18n( $post_views ), $temp );
$temp = str_replace( '%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp );
$temp = str_replace( '%POST_TITLE%', $post_title, $temp );
$temp = str_replace( '%POST_EXCERPT%', get_the_excerpt(), $temp );
$temp = str_replace( '%POST_CONTENT%', get_the_content(), $temp );
$temp = str_replace( '%POST_URL%', get_permalink(), $temp );
$temp = str_replace( '%POST_DATE%', get_the_time( get_option( 'date_format' ) ), $temp );
$temp = str_replace( '%POST_TIME%', get_the_time( get_option( 'time_format' ) ), $temp );
$temp = str_replace( '%POST_THUMBNAIL%', get_the_post_thumbnail( null,'thumbnail',true ), $temp);
$temp = str_replace( '%POST_CATEGORY_ID%', $post_category_id, $temp );
$temp = str_replace( '%POST_AUTHOR%', get_the_author(), $temp );
$output .= $temp;
}
wp_reset_postdata();
} else {
$output = '<li>' . __( 'N/A', 'wp-postviews' ) . '</li>' . "\n";
}
if ( $display ) {
echo $output;
} else {
return $output;
}
}
}
### Function: Display Most Viewed Page/Post By Tag ID
if ( ! function_exists( 'get_most_viewed_tag' ) ) {
function get_most_viewed_tag( $tag_id = 0, $mode = '', $limit = 10, $chars = 0, $display = true ) {
$views_options = get_option( 'views_options' );
$output = '';
$most_viewed = new WP_Query( array(
'post_type' => ( empty( $mode ) || $mode === 'both' ) ? 'any' : $mode,
'posts_per_page' => $limit,
'tag__in' => (array) $tag_id,
'orderby' => 'meta_value_num',
'order' => 'desc',
'meta_key' => 'views',
) );
if ( $most_viewed->have_posts() ) {
while ( $most_viewed->have_posts() ) {
$most_viewed->the_post();
// Post Views.
$post_views = get_post_meta( get_the_ID(), 'views', true );
// Post Title.
$post_title = get_the_title();
if ( $chars > 0 ) {
$post_title = snippet_text( $post_title, $chars );
}
// Post First Category.
$categories = get_the_category();
$post_category_id = 0;
if ( ! empty( $categories ) ) {
$post_category_id = $categories[0]->term_id;
}
$temp = stripslashes( $views_options['most_viewed_template'] );
$temp = str_replace( '%VIEW_COUNT%', number_format_i18n( $post_views ), $temp );
$temp = str_replace( '%VIEW_COUNT_ROUNDED%', postviews_round_number( $post_views ), $temp );
$temp = str_replace( '%POST_TITLE%', $post_title, $temp );
$temp = str_replace( '%POST_EXCERPT%', get_the_excerpt(), $temp );
$temp = str_replace( '%POST_CONTENT%', get_the_content(), $temp );
$temp = str_replace( '%POST_URL%', get_permalink(), $temp );
$temp = str_replace( '%POST_DATE%', get_the_time( get_option( 'date_format' ) ), $temp );
$temp = str_replace( '%POST_TIME%', get_the_time( get_option( 'time_format' ) ), $temp );
$temp = str_replace( '%POST_THUMBNAIL%', get_the_post_thumbnail( null,'thumbnail',true ), $temp);
$temp = str_replace( '%POST_CATEGORY_ID%', $post_category_id, $temp );
$temp = str_replace( '%POST_AUTHOR%', get_the_author(), $temp );
$output .= $temp;
}
wp_reset_postdata();
} else {
$output = '<li>' . __( 'N/A', 'wp-postviews' ) . '</li>' . "\n";
}
if($display) {
echo $output;
} else {
return $output;
}
}
}
### Function: Display Total Views
if(!function_exists('get_totalviews')) {
function get_totalviews($display = true) {
global $wpdb;
$total_views = (int) $wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->postmeta WHERE meta_key = 'views'" );
if($display) {
echo number_format_i18n($total_views);
} else {
return $total_views;
}
}
}
### Function: Snippet Text
if(!function_exists('snippet_text')) {
function snippet_text($text, $length = 0) {
if (defined('MB_OVERLOAD_STRING')) {
$text = @html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
if (mb_strlen($text) > $length) {
return htmlentities(mb_substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
} else {
return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
}
} else {
$text = @html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
if (strlen($text) > $length) {
return htmlentities(substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
} else {
return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
}
}
}
}
### Function: Modify Default WordPress Listing To Make It Sorted By Post Views
function views_fields($content) {
global $wpdb;
$content .= ", ($wpdb->postmeta.meta_value+0) AS views";
return $content;
}
function views_join($content) {
global $wpdb;
$content .= " LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID";
return $content;
}
function views_where($content) {
global $wpdb;
$content .= " AND $wpdb->postmeta.meta_key = 'views'";
return $content;
}
function views_orderby($content) {
$orderby = trim(addslashes(get_query_var('v_orderby')));
if(empty($orderby) || ($orderby != 'asc' && $orderby != 'desc')) {
$orderby = 'desc';
}
$content = " views $orderby";
return $content;
}
### Function: Add Views Custom Fields
add_action('publish_post', 'add_views_fields');
add_action('publish_page', 'add_views_fields');
function add_views_fields($post_ID) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, 'views', 0, true);
}
}
### Function: Views Public Variables
add_filter('query_vars', 'views_variables');
function views_variables($public_query_vars) {
$public_query_vars[] = 'v_sortby';
$public_query_vars[] = 'v_orderby';
return $public_query_vars;
}
### Function: Sort Views Posts
add_action('pre_get_posts', 'views_sorting');
function views_sorting($local_wp_query) {
if($local_wp_query->get('v_sortby') == 'views') {
add_filter('posts_fields', 'views_fields');
add_filter('posts_join', 'views_join');
add_filter('posts_where', 'views_where');
add_filter('posts_orderby', 'views_orderby');
} else {
remove_filter('posts_fields', 'views_fields');
remove_filter('posts_join', 'views_join');
remove_filter('posts_where', 'views_where');
remove_filter('posts_orderby', 'views_orderby');
}
}
### Function: Plug Into WP-Stats
add_action( 'plugins_loaded', 'postviews_wp_stats' );
function postviews_wp_stats() {
add_filter( 'wp_stats_page_admin_plugins', 'postviews_page_admin_general_stats' );
add_filter( 'wp_stats_page_admin_most', 'postviews_page_admin_most_stats' );
add_filter( 'wp_stats_page_plugins', 'postviews_page_general_stats' );
add_filter( 'wp_stats_page_most', 'postviews_page_most_stats' );
}
### Function: Add WP-PostViews General Stats To WP-Stats Page Options
function postviews_page_admin_general_stats($content) {
$stats_display = get_option('stats_display');
if ( (int) $stats_display['views'] === 1 ) {
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_views" value="views" checked="checked" /> <label for="wpstats_views">'.__('WP-PostViews', 'wp-postviews').'</label><br />'."\n";
} else {
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_views" value="views" /> <label for="wpstats_views">'.__('WP-PostViews', 'wp-postviews').'</label><br />'."\n";
}
return $content;
}
### Function: Add WP-PostViews Top Most/Highest Stats To WP-Stats Page Options
function postviews_page_admin_most_stats($content) {
$stats_display = get_option('stats_display');
$stats_mostlimit = (int) get_option('stats_mostlimit');
if ( (int) $stats_display['viewed_most_post'] === 1 ) {
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_viewed_most_post" value="viewed_most_post" checked="checked" /> <label for="wpstats_viewed_most_post">'.sprintf(_n('%s Most Viewed Post', '%s Most Viewed Posts', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
} else {
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_viewed_most_post" value="viewed_most_post" /> <label for="wpstats_viewed_most_post">'.sprintf(_n('%s Most Viewed Post', '%s Most Viewed Posts', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
}
if ( (int) $stats_display['viewed_most_page'] === 1 ) {
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_viewed_most_page" value="viewed_most_page" checked="checked" /> <label for="wpstats_viewed_most_page">'.sprintf(_n('%s Most Viewed Page', '%s Most Viewed Pages', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
} else {
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_viewed_most_page" value="viewed_most_page" /> <label for="wpstats_viewed_most_page">'.sprintf(_n('%s Most Viewed Page', '%s Most Viewed Pages', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'</label><br />'."\n";
}
return $content;
}
### Function: Add WP-PostViews General Stats To WP-Stats Page
function postviews_page_general_stats($content) {
$stats_display = get_option('stats_display');
if ( (int) $stats_display['views'] === 1 ) {
$content .= '<p><strong>'.__('WP-PostViews', 'wp-postviews').'</strong></p>'."\n";
$content .= '<ul>'."\n";
$content .= '<li>'.sprintf(_n('<strong>%s</strong> view was generated.', '<strong>%s</strong> views were generated.', get_totalviews(false), 'wp-postviews'), number_format_i18n(get_totalviews(false))).'</li>'."\n";
$content .= '</ul>'."\n";
}
return $content;
}
### Function: Add WP-PostViews Top Most/Highest Stats To WP-Stats Page
function postviews_page_most_stats($content) {
$stats_display = get_option('stats_display');
$stats_mostlimit = (int) get_option('stats_mostlimit');
if ( (int) $stats_display['viewed_most_post'] === 1 ) {
$content .= '<p><strong>'.sprintf(_n('%s Most Viewed Post', '%s Most Viewed Posts', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n";
$content .= '<ul>'."\n";
$content .= get_most_viewed('post', $stats_mostlimit, 0, false);
$content .= '</ul>'."\n";
}
if($stats_display['viewed_most_page'] == 1) {
$content .= '<p><strong>'.sprintf(_n('%s Most Viewed Page', '%s Most Viewed Pages', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n";
$content .= '<ul>'."\n";
$content .= get_most_viewed('page', $stats_mostlimit, 0, false);
$content .= '</ul>'."\n";
}
return $content;
}
### Function: Increment Post Views
add_action( 'wp_ajax_postviews', 'increment_views' );
add_action( 'wp_ajax_nopriv_postviews', 'increment_views' );
function increment_views() {
$security = check_ajax_referer( 'wp_postviews_nonce', 'nonce' );
if ( false === $security ) {
wp_send_json_error();
wp_die();
}
if ( ! isset( $_POST['postviews_id'] ) || empty( $_POST['postviews_id'] ) ) {
return;
}
if ( !defined( 'WP_CACHE' ) || ! WP_CACHE ) {
return;
}
$views_options = get_option( 'views_options' );
if ( isset( $views_options['use_ajax'] ) && (int) $views_options['use_ajax'] === 0 ) {
return;
}
$post_id = (int) sanitize_key( $_POST['postviews_id'] );
if( $post_id > 0 ) {
$post_views = (int) get_post_meta( $post_id, 'views', true );
$post_views = $post_views + 1;
update_post_meta( $post_id, 'views', $post_views );
do_action( 'postviews_increment_views_ajax', $post_views );
wp_send_json_success( [ 'views' => $post_views ] );
exit();
}
}
### Function Show Post Views Column in WP-Admin
add_action('manage_posts_custom_column', 'add_postviews_column_content');
add_filter('manage_posts_columns', 'add_postviews_column');
add_action('manage_pages_custom_column', 'add_postviews_column_content');
add_filter('manage_pages_columns', 'add_postviews_column');
function add_postviews_column($defaults) {
$defaults['views'] = __( 'Views', 'wp-postviews' );
return $defaults;
}
### Functions Fill In The Views Count
function add_postviews_column_content($column_name) {
if ($column_name === 'views' ) {
if ( function_exists('the_views' ) ) {
the_views( true, '', '', true );
}
}
}
### Function Sort Columns
add_filter( 'manage_edit-post_sortable_columns', 'sort_postviews_column');
add_filter( 'manage_edit-page_sortable_columns', 'sort_postviews_column' );
function sort_postviews_column( $defaults ) {
$defaults['views'] = 'views';
return $defaults;
}
add_action('pre_get_posts', 'sort_postviews');
function sort_postviews($query) {
if ( ! is_admin() ) {
return;
}
$orderby = $query->get('orderby');
if ( 'views' === $orderby ) {
$query->set( 'meta_key', 'views' );
$query->set( 'orderby', 'meta_value_num' );
}
}
### Function: Round Numbers To K (Thousand), M (Million) or B (Billion)
function postviews_round_number( $number, $min_value = 1000, $decimal = 1 ) {
if( $number < $min_value ) {
return number_format_i18n( $number );
}
$alphabets = array( 1000000000 => 'B', 1000000 => 'M', 1000 => 'K' );
foreach( $alphabets as $key => $value )
if( $number >= $key ) {
return round( $number / $key, $decimal ) . '' . $value;
}
}
### Class: WP-PostViews Widget
class WP_Widget_PostViews extends WP_Widget {
// Constructor
public function __construct() {
$widget_ops = array('description' => __('WP-PostViews views statistics', 'wp-postviews'));
parent::__construct('views', __('Views', 'wp-postviews'), $widget_ops);
}
// Display Widget
public function widget($args, $instance) {
$title = apply_filters('widget_title', esc_attr($instance['title']));
$type = esc_attr($instance['type']);
$mode = esc_attr($instance['mode']);
$limit = (int) $instance['limit'];
$chars = (int) $instance['chars'];
$cat_ids = explode(',', esc_attr($instance['cat_ids']));
echo $args['before_widget'] . $args['before_title'] . $title . $args['after_title'];
echo '<ul>'."\n";
switch($type) {
case 'least_viewed':
get_least_viewed($mode, $limit, $chars);
break;
case 'most_viewed':
get_most_viewed($mode, $limit, $chars);
break;
case 'most_viewed_category':
get_most_viewed_category($cat_ids, $mode, $limit, $chars);
break;
case 'least_viewed_category':
get_least_viewed_category($cat_ids, $mode, $limit, $chars);
break;
}
echo '</ul>'."\n";
echo $args['after_widget'];
}
// When Widget Control Form Is Posted
public function update($new_instance, $old_instance) {
if (!isset($new_instance['submit'])) {
return false;
}
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['type'] = strip_tags($new_instance['type']);
$instance['mode'] = strip_tags($new_instance['mode']);
$instance['limit'] = (int) $new_instance['limit'];
$instance['chars'] = (int) $new_instance['chars'];
$instance['cat_ids'] = strip_tags($new_instance['cat_ids']);
return $instance;
}
// DIsplay Widget Control Form
public function form($instance) {
$instance = wp_parse_args((array) $instance, array('title' => __('Views', 'wp-postviews'), 'type' => 'most_viewed', 'mode' => '', 'limit' => 10, 'chars' => 200, 'cat_ids' => '0'));
$title = esc_attr($instance['title']);
$type = esc_attr($instance['type']);
$mode = trim(esc_attr($instance['mode']));
$limit = (int) $instance['limit'];
$chars = (int) $instance['chars'];
$cat_ids = esc_attr($instance['cat_ids']);
$post_types = get_post_types(array(
'public' => true
));
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-postviews'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Statistics Type:', 'wp-postviews'); ?>
<select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>" class="widefat">
<option value="least_viewed"<?php selected('least_viewed', $type); ?>><?php _e('Least Viewed', 'wp-postviews'); ?></option>
<option value="least_viewed_category"<?php selected('least_viewed_category', $type); ?>><?php _e('Least Viewed By Category', 'wp-postviews'); ?></option>
<optgroup> </optgroup>
<option value="most_viewed"<?php selected('most_viewed', $type); ?>><?php _e('Most Viewed', 'wp-postviews'); ?></option>
<option value="most_viewed_category"<?php selected('most_viewed_category', $type); ?>><?php _e('Most Viewed By Category', 'wp-postviews'); ?></option>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('mode'); ?>"><?php _e('Include Views From:', 'wp-postviews'); ?>
<select name="<?php echo $this->get_field_name('mode'); ?>" id="<?php echo $this->get_field_id('mode'); ?>" class="widefat">
<option value=""<?php selected('', $mode); ?>><?php _e('All', 'wp-postviews'); ?></option>
<?php if($post_types > 0): ?>
<?php foreach($post_types as $post_type): ?>
<option value="<?php echo $post_type; ?>"<?php selected($post_type, $mode); ?>><?php printf(__('%s Only', 'wp-postviews'), ucfirst($post_type)); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('No. Of Records To Show:', 'wp-postviews'); ?> <input class="widefat" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit; ?>" /></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('chars'); ?>"><?php _e('Maximum Post Title Length (Characters):', 'wp-postviews'); ?> <input class="widefat" id="<?php echo $this->get_field_id('chars'); ?>" name="<?php echo $this->get_field_name('chars'); ?>" type="text" value="<?php echo $chars; ?>" /></label><br />
<small><?php _e('<strong>0</strong> to disable.', 'wp-postviews'); ?></small>
</p>
<p>
<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 />
<small><?php _e('Separate mutiple categories with commas.', 'wp-postviews'); ?></small>
</p>
<p style="color: red;">
<small><?php _e('* If you are not using any category statistics, you can ignore it.', 'wp-postviews'); ?></small>
<p>
<input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
<?php
}
}
### Function: Init WP-PostViews Widget
add_action( 'widgets_init', 'widget_views_init' );
function widget_views_init() {
register_widget( 'WP_Widget_PostViews' );
}
### Function: Post Views Options
register_activation_hook( __FILE__, 'views_activation' );
function views_activation( $network_wide ) {
// Add Options
$option_name = 'views_options';
$option = array(
'count' => 1,
'exclude_bots' => 0,
'display_home' => 0,
'display_single' => 0,
'display_page' => 0,
'display_archive' => 0,
'display_search' => 0,
'display_other' => 0,
'use_ajax' => 1,
'template' => __( '%VIEW_COUNT% views', 'wp-postviews' ),
'most_viewed_template' => '<li><a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a> - %VIEW_COUNT% '.__('views', 'wp-postviews').'</li>'
);
if ( is_multisite() && $network_wide ) {
$ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
if( 0 < count( $ms_sites ) ) {
foreach ( $ms_sites as $ms_site ) {
$blog_id = class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id'];
switch_to_blog( $blog_id );
add_option( $option_name, $option );
restore_current_blog();
}
}
} else {
add_option( $option_name, $option );
}
}
### Function: Parse View Options
function views_options_parse( $key ) {
return ! empty( $_POST[ $key ] ) ? $_POST[ $key ] : null;
}
### Function: Register views meta field to use it in REST API
add_action('rest_api_init', 'register_rest_views_field');
function register_rest_views_field(){
register_rest_field('post', 'views', array(
'get_callback' => function ($post) {
if (!$post_views = get_post_meta($post['id'], 'views', true)) {
$post_views = 0;
}
return (int) $post_views;
}
));
}
wp-postviews.pot 0000644 00000016761 15153230044 0007767 0 ustar 00 # Copyright (C) 2012 WP-PostViews
# This file is distributed under the same license as the WP-PostViews package.
msgid ""
msgstr ""
"Project-Id-Version: WP-PostViews 1.61\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-postviews\n"
"POT-Creation-Date: 2012-05-22 00:48:11+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
#: postviews-options.php:46 postviews-options.php:139
msgid "Post Views Options"
msgstr ""
#: postviews-options.php:51
msgid "Updated"
msgstr ""
#: postviews-options.php:56
msgid "No Post Views Option Updated"
msgstr ""
#: postviews-options.php:63 postviews-options.php:303
msgid "UNINSTALL WP-PostViews"
msgstr ""
#: postviews-options.php:71
msgid "Setting Key '%s' has been deleted."
msgstr ""
#: postviews-options.php:75
msgid "Error deleting Setting Key '%s'."
msgstr ""
#: postviews-options.php:85
msgid "Post Meta Key '%s' has been deleted."
msgstr ""
#: postviews-options.php:89
msgid "Error deleting Post Meta Key '%s'."
msgstr ""
#: postviews-options.php:111 postviews-options.php:261
msgid "Uninstall WP-PostViews"
msgstr ""
#: postviews-options.php:112
msgid ""
"<a href=\"%s\">Click Here</a> To Finish The Uninstallation And WP-PostViews "
"Will Be Deactivated Automatically."
msgstr ""
#: postviews-options.php:125 wp-postviews.php:797
msgid "%VIEW_COUNT% views"
msgstr ""
#: postviews-options.php:128 wp-postviews.php:798
msgid "views"
msgstr ""
#: postviews-options.php:142
msgid "Count Views From:"
msgstr ""
#: postviews-options.php:145
msgid "Everyone"
msgstr ""
#: postviews-options.php:146
msgid "Guests Only"
msgstr ""
#: postviews-options.php:147
msgid "Registered Users Only"
msgstr ""
#: postviews-options.php:152
msgid "Exclude Bot Views:"
msgstr ""
#: postviews-options.php:155
msgid "No"
msgstr ""
#: postviews-options.php:156 postviews-options.php:302
msgid "Yes"
msgstr ""
#: postviews-options.php:162
msgid "Views Template:"
msgstr ""
#: postviews-options.php:163 postviews-options.php:174
msgid "Allowed Variables:"
msgstr ""
#: postviews-options.php:165 postviews-options.php:180
msgid "Restore Default Template"
msgstr ""
#: postviews-options.php:173
msgid "Most Viewed Template:"
msgstr ""
#: postviews-options.php:187
msgid "Display Options"
msgstr ""
#: postviews-options.php:188
msgid ""
"These options specify where the view counts should be displayed and to whom. "
"\tBy default view counts will be displayed to all visitors. Note that the "
"theme files must contain a call to <code>the_views()</code> in order for any "
"view count to be displayed."
msgstr ""
#: postviews-options.php:191
msgid "Home Page:"
msgstr ""
#: postviews-options.php:194 postviews-options.php:204
#: postviews-options.php:214 postviews-options.php:224
#: postviews-options.php:234 postviews-options.php:244
msgid "Display to everyone"
msgstr ""
#: postviews-options.php:195 postviews-options.php:205
#: postviews-options.php:215 postviews-options.php:225
#: postviews-options.php:235 postviews-options.php:245
msgid "Display to registered users only"
msgstr ""
#: postviews-options.php:196
msgid "Don't display on home page"
msgstr ""
#: postviews-options.php:201
msgid "Single Posts:"
msgstr ""
#: postviews-options.php:206
msgid "Don't display on single posts"
msgstr ""
#: postviews-options.php:211
msgid "Pages:"
msgstr ""
#: postviews-options.php:216
msgid "Don't display on pages"
msgstr ""
#: postviews-options.php:221
msgid "Archive Pages:"
msgstr ""
#: postviews-options.php:226
msgid "Don't display on archive pages"
msgstr ""
#: postviews-options.php:231
msgid "Search Pages:"
msgstr ""
#: postviews-options.php:236
msgid "Don't display on search pages"
msgstr ""
#: postviews-options.php:241
msgid "Other Pages:"
msgstr ""
#: postviews-options.php:246
msgid "Don't display on other pages"
msgstr ""
#: postviews-options.php:252
msgid "Save Changes"
msgstr ""
#: postviews-options.php:263
msgid ""
"Deactivating WP-PostViews plugin does not remove any data that may have been "
"created, such as the views data. To completely remove this plugin, you can "
"uninstall it here."
msgstr ""
#: postviews-options.php:266
msgid "WARNING:"
msgstr ""
#: postviews-options.php:267
msgid ""
"Once uninstalled, this cannot be undone. You should use a Database Backup "
"plugin of WordPress to back up all the data first."
msgstr ""
#: postviews-options.php:270
msgid "The following WordPress Options/PostMetas will be DELETED:"
msgstr ""
#: postviews-options.php:275
msgid "WordPress Options"
msgstr ""
#: postviews-options.php:276
msgid "WordPress PostMetas"
msgstr ""
#: postviews-options.php:303
msgid ""
"You Are About To Uninstall WP-PostViews From WordPress.\\nThis Action Is Not "
"Reversible.\\n\\n Choose [Cancel] To Stop, [OK] To Uninstall."
msgstr ""
#: wp-postviews.php:42
msgid "PostViews"
msgstr ""
#: wp-postviews.php:191 wp-postviews.php:233 wp-postviews.php:280
#: wp-postviews.php:327 wp-postviews.php:374 wp-postviews.php:421
msgid "N/A"
msgstr ""
#: wp-postviews.php:472
msgid "There is no excerpt because this is a protected post."
msgstr ""
#. #-#-#-#-# plugin.pot (WP-PostViews 1.61) #-#-#-#-#
#. Plugin Name of the plugin/theme
#: wp-postviews.php:574 wp-postviews.php:576 wp-postviews.php:604
msgid "WP-PostViews"
msgstr ""
#: wp-postviews.php:587 wp-postviews.php:589 wp-postviews.php:618
msgid "%s Most Viewed Post"
msgid_plural "%s Most Viewed Posts"
msgstr[0] ""
msgstr[1] ""
#: wp-postviews.php:592 wp-postviews.php:594 wp-postviews.php:624
msgid "%s Most Viewed Page"
msgid_plural "%s Most Viewed Pages"
msgstr[0] ""
msgstr[1] ""
#: wp-postviews.php:606
msgid "<strong>%s</strong> view was generated."
msgid_plural "<strong>%s</strong> views were generated."
msgstr[0] ""
msgstr[1] ""
#: wp-postviews.php:674
msgid "WP-PostViews views statistics"
msgstr ""
#: wp-postviews.php:675 wp-postviews.php:725
msgid "Views"
msgstr ""
#: wp-postviews.php:734
msgid "Title:"
msgstr ""
#: wp-postviews.php:737
msgid "Statistics Type:"
msgstr ""
#: wp-postviews.php:739
msgid "Least Viewed"
msgstr ""
#: wp-postviews.php:740
msgid "Least Viewed By Category"
msgstr ""
#: wp-postviews.php:742
msgid "Most Viewed"
msgstr ""
#: wp-postviews.php:743
msgid "Most Viewed By Category"
msgstr ""
#: wp-postviews.php:748
msgid "Include Views From:"
msgstr ""
#: wp-postviews.php:750
msgid "Posts & Pages"
msgstr ""
#: wp-postviews.php:751
msgid "Posts Only"
msgstr ""
#: wp-postviews.php:752
msgid "Pages Only"
msgstr ""
#: wp-postviews.php:757
msgid "No. Of Records To Show:"
msgstr ""
#: wp-postviews.php:760
msgid "Maximum Post Title Length (Characters):"
msgstr ""
#: wp-postviews.php:761
msgid "<strong>0</strong> to disable."
msgstr ""
#: wp-postviews.php:764
msgid "Category IDs:"
msgstr ""
#: wp-postviews.php:765
msgid "Separate mutiple categories with commas."
msgstr ""
#: wp-postviews.php:768
msgid "* If you are not using any category statistics, you can ignore it."
msgstr ""
#. Plugin URI of the plugin/theme
msgid "http://lesterchan.net/portfolio/programming/php/"
msgstr ""
#. Description of the plugin/theme
msgid ""
"Enables you to display how many times a post/page had been viewed. Modified "
"by <a href=\"http://DPotter.net/Technical/\" title=\"David's Technical "
"Musings\">David Potter</a> to include options for when and where to display "
"view counts."
msgstr ""
#. Author of the plugin/theme
msgid "Lester 'GaMerZ' Chan"
msgstr ""
#. Author URI of the plugin/theme
msgid "http://lesterchan.net"
msgstr ""