1 jellis613 Dec 20, 2004 05:40
3 jellis613 Dec 20, 2004 15:27
Thanks for the feedback Ed. You are right, there is no file conf/_main.php. What I meant was that I thought that if you created a conf/hacks.php file that you would have to add a require_once reference to the hacks file in the conf/_config.php file (where all of the other pages in the conf folder are referenced). If you dont include a reference to _hacks.php in this file, how else would it be referenced?
I'll check out the Statistics Deluxe hack, play around with it a bit and see if I can fit my module into there.
More thoughts for future development of this hack:
dont count hits when they come from domains on your black list (most importantly so that you dont count your own hits. Of course, you may want to do this for more selfish reasons)
Make a table that tracks all of the individual hits to posts over x number of days. This can then be used to post a list of the most popular pages over the last day/week/month, etc.
jellis
4 edb Dec 20, 2004 15:55
http://b2evolution.net/man/2004/06/16/hacks_howto
From b2evocore/_main.php:
// Load hacks file if it exists
@include_once( dirname(__FILE__) . '/../conf/hacks.php' );
This came up in a hack recently and I thought "huh?". I am now taking advantage of this by (slowly but surely) moving my hacks to that file. Not all hacks can go, but most can - and should I guess.
5 edb Dec 22, 2004 14:26
Stopping author-hits from incrementing the counter is not hard. Add this to the top of the function:
function blahblah....
global blahblah...
if( is_logged_in() ) {
if( $current_User->get( 'ID' ) == $Item->Author->get( 'ID' ) {
return;
}
}
the rest of the function
Disclaimer: I use the first conditional statement on the installation I'm testing this in, but not the second because I'm the only blogger on my blog. It wouldn't surprise me if something goes wrong with the second if statement, and if something does go wrong it'll be in the second half of the second if. I use
if( is_logged_in() ) {
if( $current_User->get( 'ID' ) == 1 ) {
auto_close_comments( '<li>', '</li>', 45 );
}
}
without issue, so I know two thirds of the first code block is valid ;)
The reason for the disclaimer is that I made up a neat little skin thing to list and link post titles in the category of the item viewed in single page mode that works great in one skin and fails completely in a normal skin.
Back on this hack: it needs to exclude robot hits. Google did me last night, or more accurately did about 80% of my posts. Why it chose those and not all others is beyond me, but it did. As you can imagine, all those posts got incremented. Guess it's time to hack a bit deeper eh?
6 jellis613 Dec 22, 2004 15:12
EdB wrote:
Disclaimer: I use the first conditional statement on the installation I'm testing this in, but not the second because I'm the only blogger on my blog. It wouldn't surprise me if something goes wrong with the second if statement, and if something does go wrong it'll be in the second half of the second if.
You were right, there was an error in the second half of the code (parsing error). I do not have time to test it right now, but when someone figures out why it is not working, let me know. I will post the change to the hack above (using your method).
7 jellis613 Dec 22, 2004 15:22
EdB wrote:
Back on this hack: it needs to exclude robot hits. Google did me last night, or more accurately did about 80% of my posts. Why it chose those and not all others is beyond me, but it did. As you can imagine, all those posts got incremented. Guess it's time to hack a bit deeper eh?
Well, I was also thinking along these lines. I have added a new function to the code listing in the first post above: check_referrer. This checks to see if the referrer is a search engine robot (if you include a True) parameter it will check to make sure that the hit referer is good (not recommended without further modification as this will block many hits from logging - all the hits who are browsing from one page on your site to another).
To implement, add the function check_referrer in the post above to your _hacks.php file. You will also need to modify the increment_post_hits function as follows to make the call to check_referrer (also posted above):
function increment_post_hits($p_ID){
global $DB, $Item, $current_User;
if( is_logged_in() ) { // do not log hit if author is hitting the post
if( $current_User->get( 'ID' ) == 1) {
return;
}
}
if (check_hit()) {
$sql_query = 'SELECT post_hits FROM evo_posts WHERE ID = ' . $p_ID;
$post_hits = $DB->get_var($sql_query);
$post_hits++;
$sql_query = 'UPDATE evo_posts SET post_hits = ' . $post_hits . ' WHERE ID ='. $p_ID;
$DB->query($sql_query);
}
}
Note: Since the whole purpose of this code is to make sure that robot and search engine hits are not recorded, I have no way of testing it. I can say that after implementing it, nothing on my site seems broken. The only way to know for sure is to check in your evo_hitlog table for search engine hits. If you get many of these and no posts hits are incremented like what happened to Ed, then that will confirm that this works. Let me know.
8 edb Dec 22, 2004 19:45
Got it (I think). Feed another parameter to the increment function from _main.php:
if( $disp == 'single' ) {
increment_post_hits( $Item->get('ID'), $Item->Author->get('ID') );
} ?>
Now change the function to take advantage of the new parameter:
function increment_post_hits( $p_ID, $a_ID ) {
global $DB, $current_User, $tableposts;
if( is_logged_in() ) {
if( $current_User->get('ID') == $a_ID ) {
return;
}
}
** the robot checking and excluding bit
** the rest of the actual function
}
I suppose it could be a tad more efficient by getting the current_User ID while still in _main and feeding a third parameter ($c_ID?) but this method worked on my uniblogger blog. It hasn't been there very long, but I'm not noticing any perceptible change in page generation time so I'm cool with it as-is. I checked it in a browser where I'm logged in and a browser where I'm not. It did not error when I was logged in, and incremented the counter when I was not. Oh goody!
9 jellis613 Dec 22, 2004 20:10
Thanks for the code Ed. I tested it and it works for me as well - I updated the code in the first post to reflect this.
I also noticed something amiss in the code for the check_hit function that prevented it from working properly (false positives). The ammended function is posted above. It now logs hits properly - only time will tell if it will actually work to prevent robot logs - though I am pretty confident that it will work.
Next for this hack:
Implement tracking of individual hits over set period of time (with autopruning) to be used to track the most popular pages during that time period
Module to display list of top X most popular pages, implement this in the Admin section, in Some Viewing Stats section, and in the _main.php page for the skin
Do the same for most popular pages over last X days. Include in Admin section a place to designate the time for tracking these hits
Any other thoughts?
10 majort Dec 24, 2004 12:05
Can you please also post the positions of where you put your coding into the source code. I am a bit confused on where they have to go to. A bit of surrounding original source would help for searching. Thanks a again and good work!
11 edb Dec 24, 2004 12:18
Hi. I was meaning to post this here because all I want for Christmas is traffic but I decided I had better clean up some old hacks first. The way I've finalized on this puts 3 things in existing files, and in only one case do I show flanking code. The second I describe because my versions look nothing like original equipment, and the third just goes in the sidebar. Anyway http://wonderwinds.com/weblog.php/2004/12/23/heavy_hitters isn't exactly what you see in this thread but it serves the same purpose and offers a sidebar rundown.
Hi jellis. I can think of one or two things on this of the top of my head. Since I haven't tried it yet so I can't speak to more than just quick thoughts (other than it's obviously working!).
jellis613 wrote:
I'm not sure what you meant by this. There is no _main.php in the conf folder, and I see further down the hack instructions you identify the need to call it from _main.php in the skins/skinname folder, so all I can think of is you are trying to tell b2evo to read the hacks file. There is no need to add a reference to hacks.php - if you add it to the conf folder b2evolution will read it.
jellis613 wrote:
You might want to check out captsolo's "[url=http://forums.b2evolution.net/viewtopic.php?t=2204]Statistics Deluxe[/url]" hack. It adds some groovy filtering of traffic data, and provides a nice vehicle for displaying the information your hack is collecting.
jellis613 wrote:
I think that one will be easy. After I install your hack it should be no problem to support this with a new file in skins/skinname and a new sidebar bit.
Thanks for the hack!