View Full Version : Post Views 0.2
shibuya246
06-14-2010, 01:43 PM
Post Views
Version: 0.2
Author: shibuya246 [Alan]
Created: 2010/06/14
Last Updated: 2010/09/07
Tested on: Hotaru 1.4.1 ~
Plug & Play: Yes
Supported: Yes
Description
Counts the number of times a post has been viewed and stores that counter in the db posts table. Allows you to show the number of views in the extras field area along with comment counts, tags and share buttons.
Instructions
1. Upload the "post_views" folder to your plugins folder.
2. Install it from Plugin Management in Admin.
3. Configure in Admin -> Plugin Settings -> User Rankings
Notes
Revision History
v.0.2 2010/09/07 - Alan - Added a Most View Posts Page
v.0.1 2010/06/14 - Alan - Released first version
Please click "Rate Thread" and give this plugin a rating. Thank you.
nothingman
06-14-2010, 04:11 PM
Wow, thanks shibuya!
Allows you to show the number of views in the extras field area along with comment counts, tags and share buttons.
Dumb question, but where is this extra fields area? and where is the view count supposed to show up :confused:
I see only the following
http://i.imgur.com/n7wzD.jpg
skorpyo
06-14-2010, 04:22 PM
Wow, thanks shibuya!
Dumb question, but where is this extra fields area? and where is the view count supposed to show up :confused:
I see only the following
http://i.imgur.com/n7wzD.jpg
You should check out here: http://bloggertools.net/
And thanks a lot shibuya...its so great...hope you will make the widget as well...
nothingman
06-14-2010, 04:25 PM
Hi Skorpyo, how come it doesn't show up on my site (http://www.lawrkhawm.com)?
skorpyo
06-14-2010, 04:35 PM
well...on mine works great http://web-mee.com/
Have you saved the plugin settings just in case?!
shibuya246
06-14-2010, 04:46 PM
Wow, thanks shibuya!
Dumb question, but where is this extra fields area? and where is the view count supposed to show up :confused:
I see only the following
http://i.imgur.com/n7wzD.jpg
check the admin settings for the plugin and make sure you have the check box ticked that says "Show views in extra fields area"
nothingman
06-14-2010, 04:49 PM
check the admin settings for the plugin and make sure you have the check box ticked that says "Show views in extra fields area"
@Shibuya @Skorpyo, I've done that. Cleared all the cache folders too! :(
shibuya246
06-14-2010, 04:49 PM
well...on mine works great http://web-mee.com/
Have you saved the plugin settings just in case?!
thanks. It will only count votes when play view the "bookmarking_post.php" page, normally when they hit the "read more" button from the main list of posts. It is using the hook "show_post_content_post" to do the updating of the db and "show_post_extra_fields" to display the number of views.
If you want to get it to work on the link bar as well, link bar will need udpdating for it.
shibuya246
06-14-2010, 04:50 PM
@Shibuya @Skorpyo, I've done that :(
Cleared all caches ? This one catches me out everytime :)
Can you remind me of your site again so i can take a look?
shibuya246
06-14-2010, 04:51 PM
Hi Skorpyo, how come it doesn't show up on my site (http://www.lawrkhawm.com)?
ok, just realised. this will only work with hotaru 1.3, since it requires the bookmarking plugin not sb_base
Time to upgrade?
nothingman
06-14-2010, 05:00 PM
Time to upgrade?
About time :o
shibuya246
06-14-2010, 05:11 PM
About time :o
If you have any troubles upgrading let me know. It was not too hard, but make sure you change the hotaru_settings.php file and replace sb_base with the bookmarking plugin
Everything else should fall into place nicely.
details here
http://hotarucms.org/showthread.php?817-Hotaru-CMS-1.3-Released
skorpyo
06-16-2010, 11:54 AM
It would be great if when a user submits an article the views count should remain on 0(zero) count...not on 1 view...just a suggestion
carlo75
08-27-2010, 04:56 PM
I see that BloggerTools and Footymix use this feature,
but I notice that hitting F5 refreshing the page increment the number, and this practice can provide wrong results, can be used by a spammer to increase his hits generating a fake interest on his posts.
4 question:
this is a simply counter or what else?
there's a way to prevent to count at least the same IP address for a specific time?
can hit be substituited from clicking through the posts? (something related at "Automatically count a users vote when they click on the URL link" in Vote plugin)
can became a plugin?
can became a plugin?
It already is ;) . I've merged your thread here.
carlo75
08-28-2010, 08:16 PM
completely miss that plugin :mad:
and the other question:
there's a way to prevent to count at least the same IP address for a specific time?
can hit be substituited from clicking through the posts? (something related at "Automatically count a users vote when they click on the URL link" in Vote plugin)
:rolleyes:
Gunaxin
08-29-2010, 12:08 AM
Howdy all. I've been away for a bit, but I'm checking in and see lots of progress, congrats! Like the plugin, however it doesn't seem to work for me. I think its because my posts don't actually have content, just a title, category, and thumbnail. So the view count doesn't work because I don't show Description or Summary?
Assuming that's the case, I was thinking that I don't really want a view count anyways for my purposes. I'd much rather see a count of clicks. So I'm thinking I can just modify this plugin a bit, to display "Clicks" instead of views, and have it triggered when someone clicks on an outgoing link, rather then triggered when displaying the content. I took a quick stab at it with my hack and pray style, but it didn't work. How would I call the function from the outgoing link?
carlo75
08-31-2010, 10:05 AM
When I enable Show views in extra fields area I receive this error:
Notice: Undefined property: stdClass::$post_views in C:\wamp\www\hotaru\content\plugins\post_views\post _views.php on line 84
What's the problem?
carlo75
08-31-2010, 03:01 PM
I notice that receive this error, because the installation of the plugin has no completed with success due to a stuck WAMP.
After some test, and reinstall to a fresh version, plugin works fine.
carlo75
09-01-2010, 07:01 AM
@shibuya246
There's a way to put number of views, in a different position instead inside post extra fields area?
something like that is correct?
<?php $views = $h->post->vars['post_row']->post_views; echo $views . 'Views';?>
if yes, can I put that everywhere?
There's a way to put number of views, in a different position instead inside post extra fields area?
You could use the plugin hook restrict and exclude technique, i.e.:
$h->pluginHook('post_extra_fields', 'post_views'); // show post views
$h->pluginHook('post_extra_fields', '', array(), array('post_views')); // show everything except post views
carlo75
09-01-2010, 09:52 AM
really simple way... I need to study more the documentation and php...
Instead I use this solution, surely less elegant than yours:
<?php
$views = $h->post->vars['post_row']->post_views;
echo '<div id="views">' . $views . '<br />Views</div>';
?>
like my previous reply, and I move where I want ;)
frytec
11-17-2011, 05:15 AM
Pls, how can i make the views count unique?
im using this plugin in my site but when i click a link it counts 1 views and when i reply a link it counts more 1 view. So i had 2 views in a row just for visiting and comenting a link.
another question
How can i use $pw->getPostsWidget($h, 'views') ?
I need to display most visited posts in a sidebar widget!
thanks guys.
hotaruuser
11-17-2011, 08:39 AM
Pls, how can i make the views count unique?
im using this plugin in my site but when i click a link it counts 1 views and when i reply a link it counts more 1 view. So i had 2 views in a row just for visiting and comenting a link.
another question
How can i use $pw->getPostsWidget($h, 'views') ?
I need to display most visited posts in a sidebar widget!
thanks guys.
For me its the same, editing the post count views already, I guess there is no check if the post was viewed already from the same user, it just counts every call of the script? But it does not bother me...
But there is a plugin already for the most visited posts?
http://forums.hotarucms.org/showthread.php?1107-Post-Views-Widget-0.1
frytec
11-17-2011, 06:27 PM
It does not bother me either, but my visitors and advertisers may think im trying to fool them.
im trying to solve that issue storing the IP of last viewer and comparing it with the current user IP.
i added a collumn in hotaru_posts table called 'post_last_viewer_ip' and im trying to store that IP.
But im having problems on saving the ip to DB.
$last_viewer_ip = $h->post->vars['post_row']->post_last_viewer_ip; //get last ip stored on DB
$post_id = $h->post->vars['post_row']->post_id; //get the post id
$viewer_ip=$_SERVER['REMOTE_ADDR']; // get current user ip
$viewer_ip = ip2long($viewer_ip); // convert the ip to a readable int like 34627864546
$sql = "UPDATE hotaru_posts SET post_last_viewer_ip = '$viewer_ip' WHERE post_id ='$post_id'";
$h->db->query($h->db->prepare($sql));
the DB is not being updated right..
post_last_viewer_ip is recieving 0 (zero) instead of the ip converted number!
any ideas?
hotaruuser
11-17-2011, 07:36 PM
Did you check by echoing the $viewer_ip after the remote adress is set, and, after it ip2long function is called? Thats how I do it always, check line after line if the variables are set correctly
frytec
11-17-2011, 07:47 PM
yes i checked on a test.php. it echos right.
i think the problem is on sql statement.
wich it is storing 0 (zero).
PuckRobin
11-18-2011, 07:22 AM
Using phymyadmin, execute the sql command and analyse the error. For example copy and paste the following line to SQL tab of phpmyadmin:
UPDATE hotaru_posts SET post_last_viewer_ip = '12345678' WHERE post_id ='1'
Using quotation marks for integers (post_last_viewer_ip, post_id) may be the problem.
On the other hand, you should be getting an e-mail in case of an mysql syntax error.
frytec
11-18-2011, 06:52 PM
@PuckRobin
in phpmyadmin, the sql command works ok.
in post_views, if i set post_last_viewer_ip a fixed value, the sql command works ok.
if i set post_last_viewer_ip assuming a variable $viewer_ip the variable shows like nulled. no data on sql command, but it shows data on a test.php page.
SQL query:
UPDATE hotaru_posts SET post_last_viewer_ip = WHERE post_id = 8044
PHP error log:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE post_id = 8044' at line 1
i think the problem is about the ezSQL extension.
frytec
11-18-2011, 09:48 PM
After researching and trying to do this all day, I think I did.
Still needs some tweaking, but it is much better than before.
The code:
public function show_post_content_post($h)
{
$current_ip = getenv("REMOTE_ADDR");
$viewer_ip = (string) $current_ip;
if ($viewer_ip != $h->post->vars['post_row']->post_last_viewer_ip) {
$sql = "UPDATE " . TABLE_POSTS . " SET post_last_viewer_ip = '" . $viewer_ip . "' WHERE post_id = %d";
$h->db->query($h->db->prepare($sql, $h->post->id));
$sql = "UPDATE " . TABLE_POSTS . " SET post_views = post_views + 1 WHERE post_id = %d";
$h->db->query($h->db->prepare($sql, $h->post->id));
$h->post->vars['post_row']->post_views += 1;
}
}
Now I just need to figure out how to count a view when user open the link using the link_bar plugin.
PuckRobin
11-19-2011, 05:45 AM
You may consider to add this to the if condition, since not every remote server provides REMOTE_ADDR:
if ( $viewer_ip AND ...
By the way, I didn't notice that you used $_SERVER['REMOTE_ADDR'].
I think you already solved it with getenv, but the suggested solution is something like this:
$h->cage->server->getRaw('REMOTE_ADDR')
http://forums.hotarucms.org/showthread.php?20-Hotaru-s-Custom-Inspekt-Functions
frytec
11-19-2011, 07:17 PM
AND.. what? didnt get it.. pls explain.
and what is the use of this line?
$h->post->vars['post_row']->post_views += 1;
PuckRobin
11-20-2011, 02:44 AM
if ($viewer_ip AND $viewer_ip != $h->post->vars['post_row']->post_last_viewer_ip) {
It increases the variable by one. Short form for:
$h->post->vars['post_row']->post_views = $h->post->vars['post_row']->post_views + 1;
http://www.w3schools.com/php/php_operators.asp
frytec
11-21-2011, 02:59 PM
PuckRobin sorry for bother you again, but whats the point in comparing 1 variable 2 times?
and the about the seccong code, i mean, why i have to increase a variable if this is being stored in the database?
i kinda removed that line and its still working thought.
PuckRobin
11-21-2011, 04:24 PM
You are not comparing twice. The first one ($viewer_ip by itself) checks if $viewer_ip is true (not null) and the other checks if it is different than a value. You don't want to store a null IP, right?
For the second one, I didn't check the code in detail and I don't know what developer thought there. You just asked me the command and I explained it :)
Maybe it is there to let other plugins to use that value.
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.