get_row("SELECT lastvisit, visits, frequency FROM $table WHERE page='$page'"); if ($row) { $results['lastvisit'] = $row->lastvisit; $results['visits'] = $row->visits; $results['frequency'] = $row->frequency; } else $results = null; return $results; } function wp_ftr_googlestats ($date_format = '', $visited_phrase = 'Googlebot visited this page ', $never_visited_phrase = 'Googlebot never visited this page') { if ($date_format == '') $date_format = get_settings('date_format'); $stats = wp_ftr_get_googlestats(); if ($stats) { $mysqldate = date('Y-m-d H:i:s', $stats['lastvisit']); $lastvisit = mysql2date($date_format, $mysqldate); echo $visited_phrase . $lastvisit; } else { echo $never_visited_phrase; } } function wp_ftr_googlestats_hook () { global $table_prefix, $wpdb; $useragent = mysql_real_escape_string(getenv ("HTTP_USER_AGENT")); if (strpos($useragent, "+http://www.googlebot.com/bot.html") || strpos($useragent, "+http://www.google.com/bot.html")) { $page = mysql_real_escape_string($_SERVER['REQUEST_URI']); $table = $table_prefix . "googlestats"; $now = time(); $row = $wpdb->get_row("SELECT lastvisit, visits, frequency FROM $table WHERE page = '$page'"); if ($row) { $lastvisit = $row->lastvisit; $visits = $row->visits; $frequency = $row->frequency; if ($visits == 1) { /* This is the SECOND time Google visits this page */ $frequency = $now - $lastvisit; $visits++; $lastvisit = $now; } else { $frequency = (($frequency * ($visits - 1)) + ($now - $lastvisit)) / $visits; $visits++; $lastvisit = $now; } $wpdb->query("UPDATE $table SET frequency = $frequency, lastvisit = $lastvisit, visits = $visits WHERE page = '$page'"); } else { /* This is the FIRST time Google visits this page */ $result = $wpdb->query("INSERT INTO $table (page, lastvisit, visits) VALUES ('$page', $now, 1)"); } } } add_action ('shutdown', 'wp_ftr_googlestats_hook'); function wp_ftr_googlestats_adminpage() { global $table_prefix, $wpdb; $table = $table_prefix . "googlestats"; if (isset ($_GET['googlestats_resetstats'])) { $sql = "UPDATE $table SET visits = 1, frequency = 0"; //echo "
$sql
"; $wpdb->query ($sql); } $records = 20; $searchtype = "mrv"; if (isset($_POST['googlestats_records'])) $records = $_POST['googlestats_records']; if (isset($_POST['googlestats_searchtype'])) $searchtype = $_POST['googlestats_searchtype']; ?>Reset statistics (frequency data wil be erased, last visit date will be preserved).
0 AND visits >= 3"; //Data about visit frequency are statistically meaningful after at least three visits $sql .= " ORDER BY "; switch ($searchtype) { case "mrv": $sql .= "lastvisit DESC"; break; case "lrv": $sql .= "lastvisit"; break; case "mov": $sql .= "frequency"; break; case "lov": $sql .= "frequency DESC"; break; default: $sql .= "lastvisit DESC"; break; } $sql .= " LIMIT $records"; //echo "$sql
"; // For debugging purposes $rows = $wpdb->get_results ($sql); if ($rows) { echo '| Page | Visits (*) | Frequency (*) | Last visit |
|---|---|---|---|
| page . '">' . $row->page . ' | ' .$row->visits . ' | ' . $freq . ' | ' . date('Y-m-d H:i:s',$row->lastvisit) . ' |
(*) Data about visit frequency are statistically meaningful after at least three visits
'; } else { echo 'No Google visits yet!
'; } /* $rows */ echo '