From 37fefa3e3c010fc54eb66201b8476aafa6d8a795 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Fri, 3 Feb 2012 10:42:56 -0700 Subject: [PATCH] adding version 1.60 from http://svn.wp-plugins.org/wp-postviews/trunk/ --- postviews-options.php | 309 ++++++++++++++++ readme.txt | 226 ++++++++++++ screenshot-1.png | Bin 0 -> 9856 bytes wp-postviews.php | 808 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1343 insertions(+) create mode 100644 postviews-options.php create mode 100644 readme.txt create mode 100644 screenshot-1.png create mode 100644 wp-postviews.php diff --git a/postviews-options.php b/postviews-options.php new file mode 100644 index 0000000..9302f00 --- /dev/null +++ b/postviews-options.php @@ -0,0 +1,309 @@ +'.$update_views_text[$i].' '.__('Updated', 'wp-postviews').'
'; + } + $i++; + } + if(empty($text)) { + $text = ''.__('No Post Views Option Updated', 'wp-postviews').''; + } +} +// Decide What To Do +if(!empty($_POST['do'])) { + // Uninstall WP-PostViews + switch($_POST['do']) { + case __('UNINSTALL WP-PostViews', 'wp-postviews') : + if(trim($_POST['uninstall_views_yes']) == 'yes') { + echo '
'; + echo '

'; + foreach($views_settings as $setting) { + $delete_setting = delete_option($setting); + if($delete_setting) { + echo ''; + printf(__('Setting Key \'%s\' has been deleted.', 'wp-postviews'), "{$setting}"); + echo '
'; + } else { + echo ''; + printf(__('Error deleting Setting Key \'%s\'.', 'wp-postviews'), "{$setting}"); + echo '
'; + } + } + echo '

'; + echo '

'; + foreach($views_postmetas as $postmeta) { + $remove_postmeta = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '$postmeta'"); + if($remove_postmeta) { + echo ''; + printf(__('Post Meta Key \'%s\' has been deleted.', 'wp-postviews'), "{$postmeta}"); + echo '
'; + } else { + echo ''; + printf(__('Error deleting Post Meta Key \'%s\'.', 'wp-postviews'), "{$postmeta}"); + echo '
'; + } + } + echo '

'; + echo '
'; + $mode = 'end-UNINSTALL'; + } + break; + } +} + + +### Determines Which Mode It Is +switch($mode) { + // Deactivating WP-PostViews + case 'end-UNINSTALL': + $deactivate_url = 'plugins.php?action=deactivate&plugin=wp-postviews/wp-postviews.php'; + if(function_exists('wp_nonce_url')) { + $deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-postviews/wp-postviews.php'); + } + echo '
'; + echo '

'.__('Uninstall WP-PostViews', 'wp-postviews').'

'; + echo '

'.sprintf(__('Click Here To Finish The Uninstallation And WP-PostViews Will Be Deactivated Automatically.', 'wp-postviews'), $deactivate_url).'

'; + echo '
'; + break; + // Main Page + default: + $views_options = get_option('views_options'); +?> + +

'.$text.'

'; } ?> +
+
+ +

+ + + + + + + + + + + + + + + + + +
+ +
+ +
+

+
+ - %VIEW_COUNT%

+ +
+ +
+

+
+ - %VIEW_COUNT%
+ - %POST_TITLE%
+ - %POST_EXCERPT%
+ - %POST_CONTENT%
+ - %POST_URL%

+ +
+ +
+

+

the_views() in order for any view count to be displayed.', 'wp-postviews'); ?>

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+

+ +

+
+
+

 

+ + +
+
+

+

+ +

+

+
+ +

+

+
+

+ + + + + + + + + + + +
+
    + '.$settings.''."\n"; + } + ?> +
+
+
    + '.$postmeta.''."\n"; + } + ?> +
+
+

 

+

+  

+ +

+
+
+ \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..28b3cee --- /dev/null +++ b/readme.txt @@ -0,0 +1,226 @@ +=== WP-PostViews === +Contributors: GamerZ +Donate link: http://lesterchan.net/site/donation/ +Tags: views, hits, counter, postviews +Requires at least: 2.8 +Tested up to: 3.0.4 +Stable tag: trunk + +Enables you to display how many times a post/page had been viewed. + +== Description == + += Previous Versions = +* [WP-PostViews 1.40 For WordPress 2.7.x](http://downloads.wordpress.org/plugin/wp-postviews.1.40.zip "WP-PostViews 1.40 For WordPress 2.7.x") +* [WP-PostViews 1.31 For WordPress 2.3.x, 2.5.x And 2.6.x](http://downloads.wordpress.org/plugin/wp-postviews.1.31.zip "WP-PostViews 1.31 For WordPress 2.3.x, 2.5.x And 2.6.x") +* [WP-PostViews 1.11 For WordPress 2.1.x And 2.2.x](http://downloads.wordpress.org/plugin/wp-postviews.1.11.zip "WP-PostViews 1.11 For WordPress 2.1.x And 2.2.x") +* [WP-PostViews 1.02 For WordPress 2.0.x](http://downloads.wordpress.org/plugin/wp-postviews.1.02.zip "WP-PostViews 1.02 For WordPress 2.0.x") + += Development = +* [http://dev.wp-plugins.org/browser/wp-postviews/](http://dev.wp-plugins.org/browser/wp-postviews/ "http://dev.wp-plugins.org/browser/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/") + += Support Forums = +* [http://forums.lesterchan.net/index.php?board=16.0](http://forums.lesterchan.net/index.php?board=16.0 "http://forums.lesterchan.net/index.php?board=16.0") + += Credits = +* WP-Cache/WP-SuperCache Compatibility By [Thaya Kareeson](http://omninoggin.com/ "Thaya Kareeson") +* __ngetext() by [Anna Ozeritskaya](http://hweia.ru/ "Anna Ozeritskaya") +* Right To Left Language Support by [Kambiz R. Khojasteh](http://persian-programming.com/ "Kambiz R. Khojasteh") +* Options To Display Views On Certain Places by [David Potter](http://dpotter.net/Technical/ "David Potter") + += 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 appericiate it. If not feel free to use it without any obligations. + +== Changelog == += Version 1.60 (18-02-2011) = +* NEW: Added Views Count To Edit Posts Screen +* FIXED: Removed Global $post + += Version 1.50 (15-06-2009) = +* NEW: Works For WordPress 2.8 Only +* NEW: Uses jQuery Framework +* NEW: Added In Most Viewed Pages To WP-Stats +* NEW: Use _n() Instead Of __ngettext() And _n_noop() Instead Of __ngettext_noop() +* FIXED: Uses $_SERVER['PHP_SELF'] With plugin_basename(__FILE__) Instead Of Just $_SERVER['REQUEST_URI'] +* NEW: Uses New Widget Class From WordPress +* NEW: Merge Widget Code To wp-postviews.php And Remove wp-postviews-widget.php +* NEW: Added get_most_viewed_tag() And get_least_viewed_tag() +* FIXED: Ensure That Post Is Not A Revision +* FIXED: Multiple Loops Filtered Not Cleared + += Version 1.40 (12-12-2008) = +* NEW: Works For WordPress 2.7 Only +* NEW: Options To Display Views On Certain Places by David Potter +* NEW: Right To Left Language Support by Kambiz R. Khojasteh +* NEW: Output Of the_views() Applied To "the_views" Filter by Kambiz R. Khojasteh +* NEW: Called postviews_textdomain() In views_init() by Kambiz R. Khojasteh +* NEW: Uses plugins_url() And site_url() +* NEW: Added get_least_viewed() And get_least_viewed_category() By JBrinx +* FIXED: "views" Custom Field Gets Created Now When Post Is Published + += Version 1.31 (16-07-2008) = +* NEW: Works For WordPress 2.6 +* NEW: Renamed GET Variables sortby To v_sortby And orderby To v_orderby +* NEW: Better Translation Using __ngetext() by Anna Ozeritskaya +* FIXED: Able To Use v_sortby And v_orderby in query_posts() + += Version 1.30 (01-06-2008) = +* NEW: Uses /wp-postviews/ Folder Instead Of /postviews/ +* NEW: Uses wp-postviews.php Instead Of postviews.php +* NEW: Uses wp-postviews-widget.php Instead Of postviews-widget.php +* NEW: Uses number_format_i18n() Instead Of number_format() +* NEW: Option To Exclude Bots Views In 'WP-Admin -> Settings -> Post Views' +* NEW: Added Most Viewed Template +* NEW: Change The Way WP-PostViews Count Views +* NEW: Should Work With WP-Cache Or WP-SuperCache + += Version 1.20 (01-10-2007) = +* NEW: Works For WordPress 2.3 Only +* NEW: Most Viewed Widget Added +* NEW: Ability To Uninstall WP-PostViews +* NEW: Uses WP-Stats Filter To Add Stats Into WP-Stats Page + += Version 1.11 (01-06-2007) = +* FIXED: Wrong URL For Page Under Most Viewed Posts Listing + += Version 1.10 (01-02-2007) = +* NEW: Works For WordPress 2.1 Only +* NEW: Localization WP-PostViews +* NEW: Added Function To Get Most Viewed Post By Category ID +* FIXED: Views Not Counting In Some Cases + += Version 1.02 (01-10-2006) = +* NEW: Change In get_most_viewed() To Accommodate Latest Version Of WP-Stats + += Version 1.01 (01-07-2006) = +* NEW: Added Get Total Views Function +* FIXED: Modified Get Most Viewed Post Function + += Version 1.00 (01-03-2006) = +* NEW: Initial Release + +== Installation == + +1. Open `wp-content/plugins` Folder +2. Put: `Folder: wp-postviews` +3. Activate `WP-PostViews` Plugin +4. Go to `WP-Admin -> Settings -> PostViews` to configure the plugin. + += Usage = +1. Open `wp-content/themes//index.php` +2. You may place it in archive.php, single.php, post.php or page.php also. +3. Find: `` +4. Add Anywhere Below It (The Place You Want The Views To Show): `` + +== Upgrading == + +1. Deactivate `wp-postviews` Plugin +2. Open `wp-content/plugins` Folder +3. Put/Overwrite: `Folder: wp-postviews` +4. Activate `WP-PostViews` Plugin + +== Upgrade Notice == + +N/A + +== Screenshots == + +1. PostViews + +== Frequently Asked Questions == + += How To View Stats With Widgets? = +* Go to `WP-Admin -> Appearance -> Widgets` +* The widget name is Views. + += How To View Stats (Outside WP Loop) = + += To Display Least Viewed Posts = +* Use: + + +
    + +
+ +
+* The first value you pass in is what you want to get, 'post', 'page' or 'both'. +* 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 = +* Use: + + +
    + +
+ +
+* The first value you pass in is what you want to get, 'post', 'page' or 'both'. +* 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 = +* Use: + + +
    + +
+ +
+* The first value you pass in is the tag id. +* The second value you pass in is what you want to get, 'post', 'page' or 'both'. +* 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 = +* Use: + + +
    + +
+ +
+* The first value you pass in is the tag id. +* The second value you pass in is what you want to get, 'post', 'page' or 'both'. +* 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 = +* Use: + + +
    + +
+ +
+* The first value you pass in is the category id. +* The second value you pass in is what you want to get, 'post', 'page' or 'both'. +* 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 = +* Use: + + +
    + +
+ +
+* The first value you pass in is the category id. +* The second value you pass in is what you want to get, 'post', 'page' or 'both'. +* 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: `` +* 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. \ No newline at end of file diff --git a/screenshot-1.png b/screenshot-1.png new file mode 100644 index 0000000000000000000000000000000000000000..b267144a1e42e2cd72793c27d8c36b9935b45a67 GIT binary patch literal 9856 zcmbVy1yEe=mTg0X1PCs{0>PT#5?q55+(K}7*T&_?f`tG!qJnJxq}OEJ^oJmmoES zRVU&We}FcXMfwva#zQR<&2O*N)>ar@o~%5~hGMHJ(|rxDH3>Lqn7M6%*n-SNhKGec zM>F|6Z4Xg_^#&v0fX(b>zo0G9Xtrqal9PZq08qj%-Rszp6+(9xXX*Y+t{DKRr~M!b z0KoA80Np$n5Nx{Aa0=t{U>m zjD%X;UuQwP^ZXl^CJ8{IVZYp(U0 z8$_@4a3j-K9vD-okQmE*Uams-u^R(=(v2@!!7UZYruLYh^J5QFum}9B9d43^QUZ6w zFZ#@HmJdi?a}cj4DZJ2!xEM2rHW{5Cqhsf$KCNm!OjhlSp5Slc7V|ruwM<+LzCAd3 z^;u`gGgg5AN0o7_#QpV{LdP>(0TY@ezEY(t{0N5S*!iiCG@|ji8U#6!bsse}?Nmkq z6TFZ74)Mj$KW)1fDBsf3h9FO%YR{k4|B^jP-EKb$xxe*>3%38tTxuH{`riU>_5mg95s25#Abh%N>u9iKh2AGYm^r!QW()30~Ax?{@`j#s{+&z+GB) znBBFS#)4zvo%d7ZomX<17|W(9-)zvKK-3g)tA%6dZMOr^U(lCkkX**3Go%?d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mi zB-p{>ElVrG`S`eI{*|$@@r+48r3{cI?qHUfNQO9}z@KGP-)<=F|qG0<#vx#f(+2i!7T>mv!*PCOYjg1X94#WEGkFW<_O0=}J zxdu|chj*O&%ITcqfmg>IkcH%3`fFM~)@s^HdZM0wIw!4lq4EBezy*&?^(vstDJJ@?jou5LRWBsUGLLDQp$ht}0jmoqszr$PPp_IM#= z(Z?_tEOw-p%0hi|$9`)!ci;`x0b3y1XuAJ8)!8cNK2U4FEt)HuHX3nIZLbChk%4|9 zT*M5m`Yd&UwQ8zuIqV6YCj=PdA35qoN|d91Z!mo6tUgo&g3gb_4|k z7q0dHlF*HrRMY%B4X|699m$YECdWM#}kfiH9I~3vgB4-4bi9CzkHlk zchOw+v-hezTHIAxxhq>dzz0@q?djssza_f(s5GJKNFdiuk*WazU-t5wUEk_{EjaFYmR@ZuCZ5q(D0L5*qB?Y z^Eq<8zn(*&nmY%Nk=LEDx-G1;Bc!ut#^K@NjA=;FT5rM^L02+bQ~w>N{L_?_6g5Us zWIx+QO-{qd)~pnssgwOEYaT-sQut!?Yq0!*eYLK)hxWiu&QCGijNk9L@I>8Ke%xH_ zVPRo~^F`y)WMyT|eK!vWYiF`-izt_^S>$ukp15SU%*ocU^muK=_%k(qG~YFgX_Pyp zE)pnaPNJ-{ZO}4#M;_xhuFp}J+eaqh8AX)bG}>Ocj9m(2JIzsh<+&s}{i2MhjPvk9 zjWa2Y>weo!*vy%B5KmDavid Potter to include options for when and where to display view counts. +Version: 1.60 +Author: Lester 'GaMerZ' Chan +Author URI: http://lesterchan.net +*/ + + +/* + Copyright 2009 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 +*/ + + +### Load WP-Config File If This File Is Called Directly +if (!function_exists('add_action')) { + $wp_root = '../../..'; + if (file_exists($wp_root.'/wp-load.php')) { + require_once($wp_root.'/wp-load.php'); + } else { + require_once($wp_root.'/wp-config.php'); + } +} + + +### Create Text Domain For Translations +add_action('init', 'postviews_textdomain'); +function postviews_textdomain() { + load_plugin_textdomain('wp-postviews', false, 'wp-postviews'); +} + + +### 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)) { + if(is_single() || is_page()) { + $id = intval($post->ID); + $views_options = get_option('views_options'); + $post_views = get_post_custom($id); + $post_views = intval($post_views['views'][0]); + $should_count = false; + switch(intval($views_options['count'])) { + case 0: + $should_count = true; + break; + case 1: + if(empty($_COOKIE[USER_COOKIE]) && intval($user_ID) == 0) { + $should_count = true; + } + break; + case 2: + if(intval($user_ID) > 0) { + $should_count = true; + } + break; + } + if(intval($views_options['exclude_bots']) == 1) { + $bots = array('Google Bot' => 'googlebot', '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'); + $useragent = $_SERVER['HTTP_USER_AGENT']; + foreach ($bots as $name => $lookfor) { + if (stristr($useragent, $lookfor) !== false) { + $should_count = false; + break; + } + } + } + if($should_count) { + if(defined('WP_CACHE') && WP_CACHE) { + echo "\n".''."\n"; + wp_print_scripts('jquery'); + echo ''."\n"; + echo ''."\n"; + } else { + if(!update_post_meta($id, 'views', ($post_views+1))) { + add_post_meta($id, 'views', 1, true); + } + } + } + } + } +} + + +### 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 = intval(post_custom('views')); + $views_options = get_option('views_options'); + if ($always || should_views_be_displayed($views_options)) { + $output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix; + if($display) { + echo apply_filters('the_views', $output); + } else { + return apply_filters('the_views', $output); + } + } + elseif (!$display) { + return ''; + } +} + + +### Function: Display Least Viewed Page/Post +if(!function_exists('get_least_viewed')) { + function get_least_viewed($mode = '', $limit = 10, $chars = 0, $display = true) { + global $wpdb; + $views_options = get_option('views_options'); + $where = ''; + $temp = ''; + $output = ''; + if(!empty($mode) && $mode != 'both') { + $where = "post_type = '$mode'"; + } else { + $where = '1=1'; + } + $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"); + if($most_viewed) { + foreach ($most_viewed as $post) { + $post_views = intval($post->views); + $post_title = get_the_title($post); + if($chars > 0) { + $post_title = snippet_text($post_title, $chars); + } + $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); + $temp = stripslashes($views_options['most_viewed_template']); + $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); + $temp = str_replace("%POST_TITLE%", $post_title, $temp); + $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); + $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); + $temp = str_replace("%POST_URL%", get_permalink($post), $temp); + $output .= $temp; + } + } else { + $output = '
  • '.__('N/A', 'wp-postviews').'
  • '."\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) { + global $wpdb; + $views_options = get_option('views_options'); + $where = ''; + $temp = ''; + $output = ''; + if(!empty($mode) && $mode != 'both') { + $where = "post_type = '$mode'"; + } else { + $where = '1=1'; + } + $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"); + if($most_viewed) { + foreach ($most_viewed as $post) { + $post_views = intval($post->views); + $post_title = get_the_title($post); + if($chars > 0) { + $post_title = snippet_text($post_title, $chars); + } + $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); + $temp = stripslashes($views_options['most_viewed_template']); + $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); + $temp = str_replace("%POST_TITLE%", $post_title, $temp); + $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); + $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); + $temp = str_replace("%POST_URL%", get_permalink($post), $temp); + $output .= $temp; + } + } else { + $output = '
  • '.__('N/A', 'wp-postviews').'
  • '."\n"; + } + if($display) { + echo $output; + } else { + return $output; + } + } +} + + +### Function: Display Leased 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) { + global $wpdb; + $views_options = get_option('views_options'); + $where = ''; + $temp = ''; + $output = ''; + if(is_array($category_id)) { + $category_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $category_id).')'; + } else { + $category_sql = "$wpdb->term_taxonomy.term_id = $category_id"; + } + if(!empty($mode) && $mode != 'both') { + $where = "post_type = '$mode'"; + } else { + $where = '1=1'; + } + $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"); + if($most_viewed) { + foreach ($most_viewed as $post) { + $post_views = intval($post->views); + $post_title = get_the_title($post); + if($chars > 0) { + $post_title = snippet_text($post_title, $chars); + } + $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); + $temp = stripslashes($views_options['most_viewed_template']); + $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); + $temp = str_replace("%POST_TITLE%", $post_title, $temp); + $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); + $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); + $temp = str_replace("%POST_URL%", get_permalink($post), $temp); + $output .= $temp; + } + } else { + $output = '
  • '.__('N/A', 'wp-postviews').'
  • '."\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) { + global $wpdb; + $views_options = get_option('views_options'); + $where = ''; + $temp = ''; + $output = ''; + if(is_array($category_id)) { + $category_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $category_id).')'; + } else { + $category_sql = "$wpdb->term_taxonomy.term_id = $category_id"; + } + if(!empty($mode) && $mode != 'both') { + $where = "post_type = '$mode'"; + } else { + $where = '1=1'; + } + $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"); + if($most_viewed) { + foreach ($most_viewed as $post) { + $post_views = intval($post->views); + $post_title = get_the_title($post); + if($chars > 0) { + $post_title = snippet_text($post_title, $chars); + } + $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); + $temp = stripslashes($views_options['most_viewed_template']); + $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); + $temp = str_replace("%POST_TITLE%", $post_title, $temp); + $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); + $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); + $temp = str_replace("%POST_URL%", get_permalink($post), $temp); + $output .= $temp; + } + } else { + $output = '
  • '.__('N/A', 'wp-postviews').'
  • '."\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) { + global $wpdb; + $views_options = get_option('views_options'); + $where = ''; + $temp = ''; + $output = ''; + if(is_array($tag_id)) { + $tag_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $tag_id).')'; + } else { + $tag_sql = "$wpdb->term_taxonomy.term_id = $tag_id"; + } + if(!empty($mode) && $mode != 'both') { + $where = "post_type = '$mode'"; + } else { + $where = '1=1'; + } + $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"); + if($most_viewed) { + foreach ($most_viewed as $post) { + $post_views = intval($post->views); + $post_title = get_the_title($post); + if($chars > 0) { + $post_title = snippet_text($post_title, $chars); + } + $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); + $temp = stripslashes($views_options['most_viewed_template']); + $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); + $temp = str_replace("%POST_TITLE%", $post_title, $temp); + $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); + $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); + $temp = str_replace("%POST_URL%", get_permalink($post), $temp); + $output .= $temp; + } + } else { + $output = '
  • '.__('N/A', 'wp-postviews').'
  • '."\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) { + global $wpdb; + $views_options = get_option('views_options'); + $where = ''; + $temp = ''; + $output = ''; + if(is_array($tag_id)) { + $tag_sql = "$wpdb->term_taxonomy.term_id IN (".join(',', $tag_id).')'; + } else { + $tag_sql = "$wpdb->term_taxonomy.term_id = $tag_id"; + } + if(!empty($mode) && $mode != 'both') { + $where = "post_type = '$mode'"; + } else { + $where = '1=1'; + } + $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"); + if($most_viewed) { + foreach ($most_viewed as $post) { + $post_views = intval($post->views); + $post_title = get_the_title($post); + if($chars > 0) { + $post_title = snippet_text($post_title, $chars); + } + $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); + $temp = stripslashes($views_options['most_viewed_template']); + $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); + $temp = str_replace("%POST_TITLE%", $post_title, $temp); + $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); + $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); + $temp = str_replace("%POST_URL%", get_permalink($post), $temp); + $output .= $temp; + } + } else { + $output = '
  • '.__('N/A', 'wp-postviews').'
  • '."\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 = intval($wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->postmeta WHERE meta_key = 'views'")); + if($display) { + echo $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: Process Post Excerpt, For Some Reasons, The Default get_post_excerpt() Does Not Work As Expected +function views_post_excerpt($post_excerpt, $post_content, $post_password, $chars = 200) { + if(!empty($post_password)) { + if(!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post_password) { + return __('There is no excerpt because this is a protected post.', 'wp-postviews'); + } + } + if(empty($post_excerpt)) { + return snippet_text(strip_tags($post_content), $chars); + } else { + return $post_excerpt; + } +} + + +### 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: Delete Views Custom Fields +add_action('delete_post', 'delete_views_fields'); +function delete_views_fields($post_ID) { + global $wpdb; + if(!wp_is_post_revision($post_ID)) { + delete_post_meta($post_ID, 'views'); + } +} + + +### 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('wp','postviews_wp_stats'); +function postviews_wp_stats() { + if(function_exists('stats_page')) { + if(strpos(get_option('stats_url'), $_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], 'stats-options.php') || strpos($_SERVER['REQUEST_URI'], 'wp-stats/wp-stats.php')) { + 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($stats_display['views'] == 1) { + $content .= '  
    '."\n"; + } else { + $content .= '  
    '."\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 = intval(get_option('stats_mostlimit')); + if($stats_display['viewed_most_post'] == 1) { + $content .= '  
    '."\n"; + } else { + $content .= '  
    '."\n"; + } + if($stats_display['viewed_most_page'] == 1) { + $content .= '  
    '."\n"; + } else { + $content .= '  
    '."\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($stats_display['views'] == 1) { + $content .= '

    '.__('WP-PostViews', 'wp-postviews').'

    '."\n"; + $content .= '
      '."\n"; + $content .= '
    • '.sprintf(_n('%s view was generated.', '%s views were generated.', get_totalviews(false), 'wp-postviews'), number_format_i18n(get_totalviews(false))).'
    • '."\n"; + $content .= '
    '."\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 = intval(get_option('stats_mostlimit')); + if($stats_display['viewed_most_post'] == 1) { + $content .= '

    '.sprintf(_n('%s Most Viewed Post', '%s Most Viewed Posts', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'

    '."\n"; + $content .= '
      '."\n"; + $content .= get_most_viewed('post', $stats_mostlimit, 0, false); + $content .= '
    '."\n"; + } + if($stats_display['viewed_most_page'] == 1) { + $content .= '

    '.sprintf(_n('%s Most Viewed Page', '%s Most Viewed Pages', $stats_mostlimit, 'wp-postviews'), number_format_i18n($stats_mostlimit)).'

    '."\n"; + $content .= '
      '."\n"; + $content .= get_most_viewed('page', $stats_mostlimit, 0, false); + $content .= '
    '."\n"; + } + return $content; +} + + +### Function: Increment Post Views +increment_views(); +function increment_views() { + global $wpdb; + $post_id = intval($_GET['postviews_id']); + if($post_id > 0 && defined('WP_CACHE') && WP_CACHE) { + $post_views = get_post_custom($post_id); + $post_views = intval($post_views['views'][0]); + if(!update_post_meta($post_id, 'views', ($post_views+1))) { + add_post_meta($post_id, 'views', 1, true); + } + } +} + +### Function Show Post Views Column in WP-Admin +add_action('manage_posts_custom_column', 'add_postviews_column_content', 5, 2); +add_filter('manage_posts_columns', 'add_postviews_column', 5, 2); +function add_postviews_column( $defaults ) { + $defaults['viewscolumn'] = 'Views'; + return $defaults; +} + + +### Functions Fill In The Views Count +function add_postviews_column_content($column_name) { + if( $column_name == 'viewscolumn' ) { + if(function_exists('the_views')) { the_views(); } + } +} + + +### Class: WP-PostViews Widget + class WP_Widget_PostViews extends WP_Widget { + // Constructor + function WP_Widget_PostViews() { + $widget_ops = array('description' => __('WP-PostViews views statistics', 'wp-postviews')); + $this->WP_Widget('views', __('Views', 'wp-postviews'), $widget_ops); + } + + // Display Widget + function widget($args, $instance) { + extract($args); + $title = apply_filters('widget_title', esc_attr($instance['title'])); + $type = esc_attr($instance['type']); + $mode = esc_attr($instance['mode']); + $limit = intval($instance['limit']); + $chars = intval($instance['chars']); + $cat_ids = explode(',', esc_attr($instance['cat_ids'])); + echo $before_widget.$before_title.$title.$after_title; + echo '
      '."\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 '
    '."\n"; + echo $after_widget; + } + + // When Widget Control Form Is Posted + 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'] = intval($new_instance['limit']); + $instance['chars'] = intval($new_instance['chars']); + $instance['cat_ids'] = strip_tags($new_instance['cat_ids']); + return $instance; + } + + // DIsplay Widget Control Form + function form($instance) { + global $wpdb; + $instance = wp_parse_args((array) $instance, array('title' => __('Views', 'wp-postviews'), 'type' => 'most_viewed', 'mode' => 'both', 'limit' => 10, 'chars' => 200, 'cat_ids' => '0')); + $title = esc_attr($instance['title']); + $type = esc_attr($instance['type']); + $mode = esc_attr($instance['mode']); + $limit = intval($instance['limit']); + $chars = intval($instance['chars']); + $cat_ids = esc_attr($instance['cat_ids']); +?> +

    + +

    +

    + +

    +

    + +

    +

    + +

    +

    +
    + 0 to disable.', 'wp-postviews'); ?> +

    +

    +
    + +

    +

    + +

    + +%POST_TITLE% - %VIEW_COUNT% '.__('views', 'wp-postviews').''; + add_option('views_options', $views_options, 'Post Views Options'); + // Veersion 1.50 Upgrade + delete_option('widget_views_most_viewed'); +} +?> \ No newline at end of file