diff --git a/orcinus/admin.php b/orcinus/admin.php index 0dae315..1aee1c2 100644 --- a/orcinus/admin.php +++ b/orcinus/admin.php @@ -104,7 +104,8 @@ if (!in_array($_ODATA['admin_query_log_display'], $_RDATA['admin_query_log_displ $_RDATA['admin_pages'] = array( 'crawler' => 'Crawler', 'index' => 'Page Index', - 'search' => 'Search' + 'search' => 'Search', + 'stats' => 'Statistics' ); if ($_ODATA['s_limit_query_log']) $_RDATA['admin_pages']['queries'] = 'Query Log'; @@ -1259,7 +1260,9 @@ ORCINUS; $_RDATA['s_crawldata_info']['MIME-types'][$row['content_mime']] = $row['num']; } } else $_SESSION['error'][] = 'Could not read charset counts from search database.'; + break; + case 'stats': // Average hits per hour: First find the oldest `stamp` in the // database, then base all averages on the difference between that // time and now; also get average number of results @@ -1293,6 +1296,41 @@ ORCINUS; $_RDATA['q_median_results'] = (count($median) & 1) ? $median[$index]['results'] : ($median[$index - 1]['results'] + $median[$index]['results']) / 2; } } else $_SESSION['error'][] = 'Could not read result counts from query log.'; + + $select = $_DDATA['pdo']->query('SELECT INET_NTOA(`ip`) AS `ipaddr` FROM `'.$_DDATA['tbprefix'].'query`;')->fetchAll(); + $locCount = array(); + $locData = array('unk' => 'Unknown'); + foreach ($select as $row) { + try { + $geo = $_GEOIP2->country($row['ipaddr']); + if (!empty($geo->raw['country']['iso_code'])) { + if (empty($locCount[$geo->raw['country']['iso_code']])) { + $locCount[$geo->raw['country']['iso_code']] = 1; + } else $locCount[$geo->raw['country']['iso_code']]++; + $locData[$geo->raw['country']['iso_code']] = $geo->raw['country']['names']['en']; + } else { + if (empty($locCount['unk'])) { + $locCount['unk'] = 1; + } else $locCount['unk']++; + } + } catch(Exception $e) { + if (empty($locCount['unk'])) { + $locCount['unk'] = 1; + } else $locCount['unk']++; + } + } + arsort($locCount); + + $select = $_DDATA['pdo']->query('SELECT COUNT(*) as `searches`, DAYNAME(FROM_UNIXTIME(`stamp`)) as `weekday` FROM `'.$_DDATA['tbprefix'].'query` GROUP BY `weekday`;')->fetchAll(); + $dayWalker = array('Sun' => 0, 'Mon' => 0, 'Tue' => 0, 'Wed' => 0, 'Thu' => 0, 'Fri' => 0, 'Sat' => 0); + foreach ($select as $day) + $dayWalker[substr($day['weekday'], 0, 3)] = $day['searches']; + + $select = $_DDATA['pdo']->query('SELECT COUNT(*) as `searches`, `stamp` FROM `'.$_DDATA['tbprefix'].'query` GROUP BY HOUR(FROM_UNIXTIME(`stamp`));')->fetchAll(); + for ($x = 0, $days = array(), $hourWalker = array(); $x < 24; $x++) + $hourWalker[str_pad((string)$x, 2, '0', STR_PAD_LEFT).':00'] = 0; + foreach ($select as $hour) + $hourWalker[date('H:00', $hour['stamp'])] = $hour['searches']; break; case 'queries': @@ -2115,122 +2153,65 @@ ORCINUS;
- No searches logged yet. To see search statistics here, start - using your search engine. Tell your friends! -
-