Categories
Computers Linux

Target fix for Statpress Reloaded

Statpress Reloaded by Manuel Grabowski is a nice and simple plugin that helps to keep track of the hit rate to WordPress blogs and is something I personally use it for this site.

statpress

Apart from the fact that the plugin is a bit slow it miscalculates the monthly target hit rates. This has been mentioned to the plugin maintainer but until that fix gets added, here is a short description and fix.

The following sections in statpress.php are repeated in four places and is used to normalise the number of hits so far this month over the entire month.

/ date("d", current_time('timestamp')) * date('d', mktime(0, 0, 0, date('m', current_time('timestamp'))+1, 0, date('Y', current_time('timestamp'))))

However, this uses entire days which leads to incorrect results. The error is more predominant early in the month and early in the days.

I have replaced the above segment (four instances) with this:

/ (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * 86400 * date('t')

This uses seconds since the beginning of month as the basis for normalisation which is more precise. It is not perfect – among other things it will fail exactly on midnight on the first of each month due to a divide by zero.

css.php