Changeset 1332098
- Timestamp:
- 01/20/2016 01:04:56 PM (10 years ago)
- Location:
- bbpress-simple-view-counts/trunk
- Files:
-
- 1 added
- 2 edited
-
admin-options.php (added)
-
bbpress-simple-view-counts.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbpress-simple-view-counts/trunk/bbpress-simple-view-counts.php
r764794 r1332098 5 5 Description: Counts and shows views in bbPress 2 forum 6 6 Author: jezza101 7 Version: 0. 17 Version: 0.2 8 8 Author URI: http://www.blogercise.com 9 9 */ … … 11 11 12 12 /* 13 Date Version History14 ------ ----- --------15 13 Date Version History 14 ------ ----- -------- 15 12/01/2016 0.2 Added member counts 16 16 17 17 18 18 */ 19 19 20 //this plugin is maintained! 21 //contact me via my webpage, twitter @jezza101 or the forum support page on wordpress.org 22 23 const SVC_VERSION = 0.2; 24 25 20 26 class bbpress_simple_view_counts { 27 28 29 private $options; 30 private $pluginConfigPage; 21 31 22 32 public function __construct() { 23 33 24 //FILTERS NEEDED TO SHOW THE VIEWS IN THE FRONT END 25 add_action ('bbp_theme_after_topic_started_by', array($this,'show_views_forum_page'),60); 26 add_filter('bbp_get_single_topic_description', array($this,'show_views_topic_page'), 100, 2); 34 $this->options = get_option('svc-options'); 35 //print_r($this->options);die; 36 37 //FILTERS NEEDED TO SHOW THE VIEWS IN THE FRONT END 38 add_action ('bbp_theme_after_topic_started_by', array($this,'show_views_forum_page'),60); 39 add_filter('bbp_get_single_topic_description', array($this,'show_views_topic_page'), 100, 2); 40 41 42 // $options['version'] = SVC_VERSION; 43 // $options['hitCount'] = '1'; 44 // $options['memberCount'] ='1'; 45 // update_option('SVC-options',$options); 46 47 if (is_admin()) { 48 49 require_once(WP_PLUGIN_DIR .'/bbpress-simple-view-counts/admin-options.php'); 50 $this->pluginConfigPage = new PluginConfigPage(); 51 52 register_activation_hook(__FILE__, array($this, 'activate')); 53 add_action('admin_menu', array($this, 'register_my_custom_menu_page')); 54 55 //handle upgrades 56 if (empty($this->options['version']) || SVC_VERSION > $this->options['version']){ 57 //do upgrade 58 $this->upgrade(); 59 } 60 } 61 } 62 63 64 65 function register_my_custom_menu_page() 66 { 67 add_submenu_page('edit.php?post_type=forum', 'View Counts', 'View Count Options', 'administrator', 68 'bbPress_simple_view_count', array($this->pluginConfigPage,'show_options_page')); 69 } 70 71 72 73 function show_views_forum_page() { 74 75 //FORUM PAGE 76 //ie the forum pages lists all the posts in the forum, let's add a view count 77 78 $post_id = get_the_ID(); 79 $count = get_post_meta( $post_id, 'bbp_svc_viewcounts', true ); 80 81 if (!empty($count)){ 82 echo '<br><span class="bbp-topic-started-by">Views: '.$count.'</span>'; 83 } 84 return; 85 } 86 87 function show_views_topic_page( $content, $reply_id ) { 88 89 $post_id = get_the_ID(); 90 91 //HITS 92 IF ($this->options['hitCount']==1) { 93 //get previous count and add one! 94 $hitCount = get_post_meta($post_id, 'bbp_svc_viewcounts', true); 95 $hitCount = $hitCount + 1; 96 update_post_meta($post_id, 'bbp_svc_viewcounts', $hitCount) ; 97 98 if ($hitCount==1){ 99 $text = ". This post has been viewed 1 time"; 100 } 101 else if (!empty($hitCount)){ 102 $text = ". This post has been viewed $hitCount times"; 103 } 104 } 105 106 107 //MEMBER VIEWS 108 IF ($this->options['memberCount']==1) { 109 110 $user_ID = get_current_user_id(); 111 112 if ($user_ID > 0) { 113 114 //record users who have seen this page 115 $memberList = get_post_meta($post_id, 'bbp_svc_membercounts', true); 116 117 $memberArray = explode('.',$memberList); 118 $memberCount = sizeof($memberArray) -1; 119 if(array_search($user_ID,$memberArray)===FALSE) 120 { 121 $memberList = $memberList . $user_ID . '.'; 122 update_post_meta($post_id, 'bbp_svc_membercounts', $memberList) ; 123 $memberCount ++; 124 } 125 If($memberCount==1) { 126 $text .= ". The post has been read by " . $memberCount . " member."; 127 }else{ 128 $text .= ". The post has been read by " . $memberCount . " members."; 129 } 130 } 131 } 132 133 //echo"$text"; 134 135 //SHOW THE COUNTS 136 137 //inject our view count into the topic, let's replace the full stop at the end of the details. 138 //Better way to do this? 139 if (!empty($text)){ 140 $content = str_replace(".",$text,$content); 141 } 142 143 //echo "<p>P:$post_id C:$count"; 144 return $content ; 27 145 28 146 } 29 147 30 148 31 function show_views_forum_page() {149 public static function activate() { 32 150 33 //FORUM PAGE34 //ie the forum pages lists all the posts in the forum, let's add a view count151 //same as upgrade for now... 152 $this->upgrade(); 35 153 36 $post_id = get_the_ID(); 37 $count = get_post_meta( $post_id, 'bbp_svc_viewcounts', true ); 154 } 38 155 39 if (!empty($count)){ 40 echo '<br><span class="bbp-topic-started-by">Views: '.$count.'</span>'; 41 } 42 return; 43 } 156 function upgrade(){ 44 157 45 function show_views_topic_page( $content, $reply_id ) {158 $options = get_option("svc-options"); 46 159 160 //IF NO VERSION IS FOUND THEN THIS IS A NEW INSTALL 161 if (empty($options['version'])){ 47 162 48 //First let's update the view count 49 $post_id = get_the_ID(); 163 $options['version'] = SVC_VERSION; 164 $options['hitCount'] = '1'; 165 $options['memberCount'] =''; 50 166 51 //get previous count and add one! 52 $count = get_post_meta( $post_id, 'bbp_svc_viewcounts', true ); 53 $count = $count + 1 ; 167 update_option('SVC-options',$options); 168 } 54 169 55 //save the new count 56 update_post_meta($post_id, 'bbp_svc_viewcounts', $count) ; 170 //ELSE 171 //add new upgrades here 172 if (SVC_VERSION == 0.3){ 173 //upgrade to next version 57 174 58 59 //inject our view count into the topic, let's replace the full stop at the end of the details. 60 //Better way to do this? 61 if ($count==1){ 62 $content = str_replace(".",". This post has been viewed 1 time",$content); 63 } 64 else if (!empty($count)){ 65 $content = str_replace(".",". This post has been viewed $count times",$content); 66 } 67 68 //echo "<p>P:$post_id C:$count"; 69 70 return $content; 71 } 72 175 } 176 } 73 177 } 74 178 -
bbpress-simple-view-counts/trunk/readme.txt
r764794 r1332098 4 4 Tags: bbpress, views, reads, forum 5 5 Requires at least: 3.0.1 6 Tested up to: 3.67 Stable tag: 0. 16 Tested up to: 4.4.1 7 Stable tag: 0.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 16 16 once on the forum listing page and once at the top of each post. 17 17 18 The count is currently incremented on each refresh of the page. Counts are recorded using the WordPress post meta API. 18 You can select whether you want a simple hit count, or a unique count of member views. Or both. 19 * The hit count literally counts every time the page is displayed. 20 * The member count increases each time a member views the page for the first time. It is a unique count. This tracks users using their 21 WordPress user ID so if you mess with the user table the tracking will likely break. 19 22 20 23 Note that this is a new plugin and has not been tested on high volume sites so please perform your own tests 21 24 before implementing. Feedback on performance greatly appreciated. Please post in the plugin's WP forum area or 22 mention @jezza101 in a tweet. 25 mention @jezza101 in a tweet. This plugin is maintained, I use it on my own forums, but unless I have a request or it 26 breaks I will not be adding new features as it works how I want it to work. 23 27 24 28 == Installation == 25 29 Upload and install the plugin as normal. 26 30 27 The re are no configuration options at present.31 The options link is under the main Forum menu. Use this to select if you want to track hit count, member count or both. 28 32 29 33 == Frequently Asked Questions == … … 34 38 might be. 35 39 40 Tracking member views is likely to be more resource intensive, but only if you have a lot of members. 41 36 42 = The plugin doesn't work quite how I'd like it, can I make a suggestion? = 37 Sure, get in touch. This version is really a proof of concept and if it is popular I will expand it. 43 Sure, get in touch. The plugin works as I want it to so it is unlikely I will change it unless it breaks. But sure, feel free to make a 44 request, the member tracking was added by request! 38 45 39 46 = It's hardcoded in English, can you make it language friendly? = 40 Yes, this will be added in a future version. I just need to work out how... 47 Yes, this will be added in a future version. Please do let me know if this is important to you and I will prioritise this. 48 49 = Can you add a unique count? = 50 After careful consideration I have decided not to do this. Tracking unique views is a whole different ball game and is not easy to do. Even forum software 51 such as vBulletin shows a hit count. I want this plugin to stay simple. If you need to track unique views you are better off using Googe Analytics or 52 WordPress Stats. 53 54 = Does it work with caching plugins? = 55 I have no idea, I don't use any. But let me know. I suspect the only way to make this work would be to regnerate the page on each load but that would defeat 56 the point of the page cache. 41 57 42 58 43 59 == Changelog == 44 60 61 = 0.2 = 62 Added member tracking. The plugin can now give a unique count of member views. 63 45 64 = 0.1 = 46 65 * Initial release
Note: See TracChangeset
for help on using the changeset viewer.