* @copyright 2004 Telartis * @version 1.7 * * @link http://www.telartis.nl/xcms/awstats * * Changelog: * 1.0 initial version * 1.1 use awstats language files to set your language * 1.2 register_globals setting can be off * 1.3 display yearly totals and last entry (Marco Gruber) * 1.4 use english messages when no language files found * 1.5 error_reporting setting can be E_ALL * 1.6 fixed incorrect unique visitors in year view (ConteZero) * 1.7 changed number and byte format * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /******************************************************* * SETUP SECTION *******************************************************/ /** * Set this value to the directory where AWStats * saves its database and working files into. */ $DirData = './data'; /** * The URL of the AWStats script. */ $AWStatsURL = '/awstats-6.3/wwwroot/cgi-bin/awstats.pl'; /** * Set your language. * Possible value: * Albanian=al, Bosnian=ba, Bulgarian=bg, Catalan=ca, * Chinese (Taiwan)=tw, Chinese (Simpliefied)=cn, Czech=cz, Danish=dk, * Dutch=nl, English=en, Estonian=et, Euskara=eu, Finnish=fi, * French=fr, Galician=gl, German=de, Greek=gr, Hebrew=he, Hungarian=hu, * Icelandic=is, Indonesian=id, Italian=it, Japanese=jp, Korean=kr, * Latvian=lv, Norwegian (Nynorsk)=nn, Norwegian (Bokmal)=nb, Polish=pl, * Portuguese=pt, Portuguese (Brazilian)=br, Romanian=ro, Russian=ru, * Serbian=sr, Slovak=sk, Spanish=es, Swedish=se, Turkish=tr, Ukrainian=ua, * Welsh=wlk. */ $Lang = 'en'; /** * Set the location of language files. */ $DirLang = './lang'; /** * Set number format. */ $dec_point = '.'; $thousands_sep = ' '; /** * Config names to filter. Shows all if empty array. */ $FilterConfigs = array(); /* To read website configs from database, do something like: $sql = 'SELECT config FROM users WHERE (user=...)'; $rs = mysql_query($sql); if ($rs) while ($row = mysql_fetch_array($rs)) $FilterConfigs[] = $row['config']; */ /******************************************************* * PROGRAM SECTION *******************************************************/ if (isset($_GET["year"])) $year = $_GET["year"]; else $year = date("Y"); if (isset($_GET["month"])) $month = $_GET["month"]; else $month = date("n"); if (isset($_GET["sort"])) $sort = $_GET["sort"]; else $sort = "bandwidth"; function get_config($file) { $r = ''; if (preg_match('/awstats\d{6}\.(.+)\.txt/', $file, $match)) $r = $match[1]; return $r; } function read_history($file) { $f = fopen($file, "r"); $s = fread($f, filesize($file)); fclose($f); $visits_total = 0; $unique_total = 0; $pages_total = 0; $hits_total = 0; $bandwidth_total = 0; $config = get_config($file); if (preg_match('/TotalVisits (\d+)/', $s, $match)) $visits_total = (int)$match[1]; if (preg_match('/TotalUnique (\d+)/', $s, $match)) $unique_total = (int)$match[1]; if (preg_match('/\nBEGIN_DAY \d+\n(.*)\nEND_DAY\n/s', $s, $match)) { foreach (explode("\n", $match[1]) as $row) { list($date, $pages, $hits, $bandwidth, $visits) = split(' ', $row); $pages_total += $pages; $hits_total += $hits; $bandwidth_total += $bandwidth; } } return array("config"=>$config, "visits"=>$visits_total, "unique"=>$unique_total, "pages"=>$pages_total, "hits"=>$hits_total, "bandwidth"=>$bandwidth_total); } $dirfiles = array(); $dir = @opendir($DirData); if (!$dir) die("Could not open directory $DirData"); while ($file = readdir($dir)) $dirfiles[] = $file; $files = array(); $config = array(); if ($month == 'all') $pat = '\d{2}'; else $pat = substr("0".$month, -2); $pat = '/awstats'.$pat.$year.'\.(.+)\.txt/'; foreach ($dirfiles as $file) if (preg_match($pat, $file, $match)) { $config = $match[1]; if (!$FilterConfigs || in_array($config, $FilterConfigs)) { $configs[] = $config; $files[] = $file; } } $rows = array(); if ($files) { array_multisort($configs, $files); $visits_total = 0; $unique_total = 0; $pages_total = 0; $hits_total = 0; $bandwidth_total = 0; $row_prev = array(); for ($i = 0, $cnt = count($files); $i <= $cnt; $i++) { $row = array(); if ($i < $cnt) { $row = read_history($DirData.'/'.$files[$i]); $visits_total += $row["visits"]; $unique_total += $row["unique"]; $pages_total += $row["pages"]; $hits_total += $row["hits"]; $bandwidth_total += $row["bandwidth"]; } if ( isset($row["config"]) && isset($row_prev["config"]) && ($row["config"] == $row_prev["config"]) ) { $row["visits"] += $row_prev["visits"]; $row["unique"] += $row_prev["unique"]; $row["pages"] += $row_prev["pages"]; $row["hits"] += $row_prev["hits"]; $row["bandwidth"] += $row_prev["bandwidth"]; } elseif ($i > 0) $rows[] = $row_prev; $row_prev = $row; } } function multisort(&$array, $key) { $cmp = create_function('$a, $b', 'if ($a["'.$key.'"] == $b["'.$key.'"]) return 0;'. 'return ($a["'.$key.'"] > $b["'.$key.'"]) ? -1 : 1;'); usort($array, $cmp); } if ($sort == "config") sort($rows); else multisort($rows, $sort); function read_language_data($file) { $r = array(); $lines = file($file); foreach ($lines as $line) if (preg_match('/^message(\d+)=(.*)$/', $line, $match)) $r[$match[1]] = $match[2]; return $r; } $message = read_language_data("$DirLang/awstats-$Lang.txt"); if (!$message) { $message[7] = 'Statistics for'; $message[10] = 'Number of visits'; $message[11] = 'Unique visitors'; $message[56] = 'Pages'; $message[57] = 'Hits'; $message[60] = 'Jan'; $message[61] = 'Feb'; $message[62] = 'Mar'; $message[63] = 'Apr'; $message[64] = 'May'; $message[65] = 'Jun'; $message[66] = 'Jul'; $message[67] = 'Aug'; $message[68] = 'Sep'; $message[69] = 'Oct'; $message[70] = 'Nov'; $message[71] = 'Dec'; $message[75] = 'Bandwidth'; $message[102] = 'Total'; $message[115] = 'OK'; $message[133] = 'Reported period'; } function byte_format($number, $decimals = 2) { global $dec_point, $thousands_sep; // kilo, mega, giga, tera, peta, exa, zetta, yotta $prefix_arr = array('','k','M','G','T','P','E','Z','Y'); $i = 0; if ($number == 0) $result = 0; else { $value = round($number, $decimals); while ($value > 1024) { $value /= 1024; $i++; } $result = number_format($value, $decimals, $dec_point, $thousands_sep); } $result .= ' '.$prefix_arr[$i].'B'; if (!$i) $result .= 'ytes'; return $result; } function num_format($number, $decimals = 0) { global $dec_point, $thousands_sep; return number_format($number, $decimals, $dec_point, $thousands_sep); } /******************************************************* * HTML SECTION *******************************************************/ ?> AWStats Totals
: \n"; for ($i = 1; $i <= 12; $i++) { echo "
  ".$row["config"]."".num_format($row["unique"]). "".num_format($row["visits"])."".num_format($row["pages"]). "".num_format($row["hits"])."".byte_format($row["bandwidth"])."\n"; echo "
 Total".num_format($unique_total). "".num_format($visits_total)."".num_format($pages_total). "".num_format($hits_total)."".byte_format($bandwidth_total)."\n"; ?>


AWStats Totals 1.7 - © 2004 Telartis