I wondered this morning why the data looked quite odd in WP ShortStat 1.2. After analyzing the PHP, I noticed the column “Hits in the last week” and a few other parts are calculated with a wrong date. I modified the following parts, and now the data output expresses the identic values which are found in the database. I hope Jeff will test these changes… and include them in the official version (open the article to read the code changes).
function getTodaysHits() {
global $wpdb;
$dt = time();
$dt = mktime(0, 0, 0, date(”m”,$dt), date(”d”,$dt), date(”Y”,$dt));
$query = “SELECT COUNT(*) AS ‘total’ FROM $this->table_stats WHERE dt >= $dt”;
return $wpdb->get_var($query);
}
function getTodaysUniqueHits() {
global $wpdb;
$dt = time();
$dt = mktime(0, 0, 0, date(”m”,$dt), date(”d”,$dt), date(”Y”,$dt));
$query = “SELECT COUNT(DISTINCT remote_ip) AS ‘total’ FROM $this->table_stats WHERE dt >= $dt”;
return $wpdb->get_var($query);
}
function getWeeksHits() {
global $wpdb;
$tmp = “”;
$dt_start = time();
$tmp = “<table cellpadding=\”0\” cellspacing=\”0\” border=\”0\”>\n”;
$tmp .= “\t<tr><th colspan=\”2\”>Hits in the last week</th></tr>\n”;
$tmp .= “\t<tr><td class=\”accent\”>Day</td><td class=\”accent last\”>Hits</td></tr>\n”;
for ($i=0; $i<7; $i++) {
$dt_start = mktime(0, 0, 0, date(”m”,$dt_start), date(”d”,$dt_start), date(”Y”,$dt_start));
$dt_stop = $dt_start;
$dt_start = $dt_start - (60 * 60 * 24);
$day = date(”l, j M Y”,$dt_start);
$query = “SELECT COUNT(*) AS ‘total’ FROM $this->table_stats WHERE dt > $dt_start AND dt <=$dt_stop";
if ($total = $wpdb->get_var($query)) {
$tmp .= “\t<tr><td>$day</td><td class=\”last\”>$total</td></tr>\n”;
}
}
$tmp .= “</table>”;
return $tmp;
}
take a look at SlimStat: http://wettone.com/code/slimstat
and a user experience
Einfach-Persoenlich.de
SlimStat is better since it doesnt produce such a huge datasize (a so called “pruning”-process deleting old datas)
Thanks! That’s what I’ve been searching for. Guess you using it too, Robert? ;)
nope, not yet, since an error ocurred during the creation of the database table. I have to contact the developer of SlimStat to solve the problem.