array( # LastDay = 24 hours; 1 hour = 60*60sec 'max'=>24, 'atom'=>60*60, 'fmt'=> 'date("G",$now-$atom*($maxnr-1-$nr))' ), 'LastWeek' => array( # LastWeek = 7 days 'max'=>7, 'atom'=>24*60*60, 'fmt'=> 'date("D",$now-$atom*($maxnr-1-$nr))' ), 'LastMonth' => array( 'max'=>30, 'atom'=>24*60*60, 'fmt'=> 'date("j",$now-$atom*($maxnr-1-$nr))' ), 'LastYear' => array( # date('n') is the month of the year 'max'=>12, 'atom'=>'n', 'fmt'=> '$TotalCounterMonthsShort[(12+(int)date("n",$now)-$maxnr+$nr)%12]' ), 'LastYears' => array( 'max'=>30, 'atom'=>'Y', 'fmt'=> '(int)date("Y",$now)-($maxnr-1-$nr)' ) )); SDVA($HandleActions, array ( $TotalCounterAction => 'HandleTotalCounter' )); SDVA($HandleAuth, array ( $TotalCounterAction => $TotalCounterAuthLevel )); global $TotalCounter; if ($TotalCounterMaxItems <= 0) $TotalCounterMaxItems = 1; $file = $TotalCounterFile; $lock = $TotalCounterLockfile; $geoIpFile = "$WorkDir/$TotalCounterGeoIPData"; clearstatcache(); ignore_user_abort(true); # while (file_exists($lock)) { # $st = stat($lock); # if ((time()-$st['mtime']) > 15) { # Abort("Too many visitors at the moment...please try later!"); # break; # } # } //------------------------------------------------------------------------------------ if (!function_exists("file_get_contents")) { function file_get_contents($filename) { if (($contents = file($filename))) { $contents = implode('', $contents); return $contents; } else return ''; } } if (function_exists('ResolvePageName')) { $tc_pagename = ResolvePageName($pagename); } else { $tc_pagename = str_replace('/', '.', $pagename); /* line changed by Chris Morison 9/3/06 */ } if ($tc_pagename == '') $tc_pagename = "$DefaultGroup.$DefaultName"; if ($action == 'browse') { //find users if (isset ($AuthId)) { $tc_user = $AuthId; } else { if (isset ($Author)) { $tc_user = $Author; } else { @ session_start(); if (isset ($_SESSION['authid'])) { $tc_user = $_SESSION['authid'][0]; } else { $tc_user = 'Guest (not authenticated)'; } } } //find web bot if (preg_match('/ia_archiver/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Alexa'; elseif (preg_match('/ask jeeves/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Ask Jeeves'; elseif (preg_match('/baiduspider/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Baidu'; elseif (preg_match('/libcurl/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'cURL'; elseif (preg_match('/gigabot/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Gigablast'; elseif (preg_match('/googlebot/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Google'; elseif (preg_match('/grub-client/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Grub'; elseif (preg_match('/slurp@inktomi.com/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Inktomi'; elseif (preg_match('/msnbot/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'MSN'; elseif (preg_match('/scooter/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Altavista'; elseif (preg_match('/wget/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'wget'; elseif (preg_match('/yahoo! slurp/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Yahoo!'; elseif (preg_match('/becomebot/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Become'; elseif (preg_match('/fast/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'Fast/Alltheweb'; elseif (preg_match('/zyborg/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/zealbot/', $_SERVER['HTTP_USER_AGENT'])) $tc_bot = 'WiseNut!'; //not a bot, so find the browser elseif (preg_match('/arachne/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Arachne GPL'; elseif (preg_match('/blazer/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Blazer'; elseif (preg_match('/opera/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Opera'; elseif (preg_match('/webtv/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'WebTV'; elseif (preg_match('/camino/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Camino'; elseif (preg_match('/netpositive/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'NetPositive'; elseif (preg_match('/internet explorer/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/msie/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/mspie/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'MS Internet Explorer'; elseif (preg_match('/avant browser/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/advanced browser/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Avant Browser'; elseif (preg_match('/galeon/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Galeon'; elseif (preg_match('/konqueror/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Konqueror'; elseif (preg_match('/icab/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'iCab'; elseif (preg_match('/omniweb/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'OmniWeb'; elseif (preg_match('/phoenix/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Phoenix'; elseif (preg_match('/firebird/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Firebird'; elseif (preg_match('/firefox/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Firefox'; elseif (preg_match('/minimo/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Minimo'; elseif (preg_match("/mozilla/", $_SERVER['HTTP_USER_AGENT']) && preg_match("rv:[0-9].[0-9][a-b]", $_SERVER['HTTP_USER_AGENT']) && !preg_match("netscape", $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Mozilla'; elseif (preg_match("/mozilla/", $_SERVER['HTTP_USER_AGENT']) && preg_match("rv:[0-9].[0-9]", $_SERVER['HTTP_USER_AGENT']) && !preg_match("netscape", $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Mozilla'; elseif (preg_match("/libwww/", $_SERVER['HTTP_USER_AGENT'])) { if (preg_match("/amaya/", $_SERVER['HTTP_USER_AGENT'])) { $tc_browser = 'Amaya'; } else { $tc_browser = 'Text browser'; } } elseif (preg_match('/chrome/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Chrome'; elseif (preg_match('/safari/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Safari'; elseif (preg_match('/elinks/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'ELinks'; elseif (preg_match('/offbyone/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Off By One'; elseif (preg_match('/playstation portable/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'PlayStation Portable'; elseif (preg_match('/netscape/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Netscape'; elseif (preg_match('/mozilla/', $_SERVER['HTTP_USER_AGENT']) && !preg_match("rv:[0-9]\.[0-9]\.[0-9]", $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Firefox'; elseif (preg_match('/links/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Links'; elseif (preg_match('/ibrowse/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'iBrowse'; elseif (preg_match('/w3m/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'w3m'; elseif (preg_match('/aweb/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'AWeb'; elseif (preg_match('/voyager/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Voyager'; elseif (preg_match('/oregano/', $_SERVER['HTTP_USER_AGENT'])) $tc_browser = 'Oregano'; else $tc_browser = 'Unknown'; //find operating system if (preg_match('/linux/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Linux'; elseif (preg_match('/irix/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'IRIX'; elseif (preg_match('/hp-ux/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'HP-Unix'; elseif (preg_match('/os2/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'OS/2'; elseif (preg_match('/beos/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'BeOS'; elseif (preg_match('/sunos/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'SunOS'; elseif (preg_match('/palm/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'PalmOS'; elseif (preg_match('/cygwin/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Cygwin'; elseif (preg_match('/amiga/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Amiga'; elseif (preg_match('/unix/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Unix'; elseif (preg_match('/qnx/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'QNX'; elseif (preg_match('/win/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Windows'; elseif (preg_match('/mac/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Mac'; elseif (preg_match('/risc/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'RISC'; elseif (preg_match('/dreamcast/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'Dreamcast'; elseif (preg_match('/freebsd/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'FreeBSD'; elseif (preg_match('/dos/', $_SERVER['HTTP_USER_AGENT'])) $tc_os = 'dos'; else $tc_os = 'Unknown'; //find referrer domain preg_match("/^(http:\/\/)?([^\/:]+)/i", $_SERVER['HTTP_REFERER'], $matches); $host = $matches[2]; //if (preg_match("/[^\.\/]+\.*[^\.\/]+$/", $host, $matches) != 0) $host = $matches[0]; if ($matches[2] != '') { $tc_referer = $matches[2]; } else { $tc_referer = 'Unknown'; } //find location if ($_SERVER['HTTP_X_FORWARDED_FOR'] != '') { if (strstr($_SERVER['HTTP_X_FORWARDED_FOR'], ', ')) { $ips = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']); $thehost = $ips[0]; } else { $thehost = $_SERVER['HTTP_X_FORWARDED_FOR']; } } else { if (strstr($_SERVER['REMOTE_HOST'], ', ')) { $ips = explode(', ', $_SERVER['REMOTE_HOST']); $thehost = $ips[0]; } else { $thehost = $_SERVER['REMOTE_HOST']; } } if (preg_match("/[^\.0-9]+$/", $thehost, $matches) != 0) $loc = $matches[0]; if ($loc != '') { $tc_location = $loc; } else { if ($TotalCounterEnableLookup == 1) { $thehost = @ gethostbyaddr($_SERVER['REMOTE_ADDR']); if (preg_match("/[^\.0-9]+$/", $thehost, $matches) != 0) $loc = $matches[0]; if ($loc != '') { $tc_location = $loc; } else { $tc_location = 'Unknown'; } } else if ($TotalCounterEnableGeoIP == 1) { include ('geoip/geoip.inc'); $gi = geoip_open($geoIpFile, GEOIP_STANDARD); $tc_location = strtolower(geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR'])); geoip_close($gi); } else { $tc_location = 'Unknown'; } } if ($tc_location != 'Unknown') $tc_location = strtolower($tc_location); } //------------------------------------------------------------------------------------ $oldumask = umask(0); //mkdir($lock, 0777); # touch($lock); # fixperms($lock); $downloadfile = "$WorkDir/$TotalCounterDownloadManager"; if (file_exists($downloadfile)) { $TotalCounterDownloads = unserialize(file_get_contents($downloadfile)); } if (file_exists($file)) { $TotalCounter = unserialize(file_get_contents($file)); } else { touch($file); $TotalCounter['Total'] = 0; $TotalCounter['Pages'][$tc_pagename] = 0; } if (($action == 'browse') && ($tc_pagename != '')) { if( dblock($file) ) { $TotalCounter = unserialize(file_get_contents($file)); $TotalCount = ++ $TotalCounter['Total']; if (!@ in_array($tc_pagename, $TotalCounterBlacklist['Pages'])) { $blacklisted = false; if (is_array($TotalCounterBlacklist['Pages'])) foreach ($TotalCounterBlacklist['Pages'] as $value) if (substr($value, 0, 1) == '/') if (preg_match($value, $tc_pagename) > 0) $blacklisted = true; if (!$blacklisted) { $PageCount = ++ $TotalCounter['Pages'][$tc_pagename]; ## handles the daily counter if ($TotalCounter['PagesTodayDay'][$tc_pagename] == date("%y%m%d")) $PageCountToday = ++ $TotalCounter['PagesTodayCounter'][$tc_pagename]; else { $TotalCounter['PagesTodayDay'][$tc_pagename] = date("%y%m%d"); $TotalCounter['PagesTodayCounter'][$tc_pagename] = 1; } } else { $PageCount = 0; } } if (!@ in_array($tc_user, $TotalCounterBlacklist['Users'])) { $blacklisted = false; if (is_array($TotalCounterBlacklist['Users'])) foreach ($TotalCounterBlacklist['Users'] as $value) if (substr($value, 0, 1) == '/') if (preg_match($value, $tc_user) > 0) $blacklisted = true; if (!$blacklisted) $TotalCounter['Users'][$tc_user]++; } if (defined('MULTILANGUAGE')) if (isset ($userlang2)) $TotalCounter['Languages'][$userlang2]++; if (isset ($tc_browser) && !@ in_array($tc_browser, $TotalCounterBlacklist['Browsers'])) { $TotalCounter['Browsers'][$tc_browser]++; } if (isset ($tc_bot) && !@ in_array($tc_bot, $TotalCounterBlacklist['Bots'])) { $TotalCounter['Bots'][$tc_bot]++; } if (!@ in_array($tc_os, $TotalCounterBlacklist['OSes'])) { $TotalCounter['OSes'][$tc_os]++; } if (!@ in_array($tc_referer, $TotalCounterBlacklist['Referers'])) { $blacklisted = false; if (is_array($TotalCounterBlacklist['Referers'])) foreach ($TotalCounterBlacklist['Referers'] as $value) if (substr($value, 0, 1) == '/') if (preg_match($value, $tc_referer) > 0) $blacklisted = true; if (!$blacklisted) $TotalCounter['Referers'][$tc_referer]++; } if (!@ in_array($tc_location, $TotalCounterBlacklist['Locations'])) { $TotalCounter['Locations'][$tc_location]++; } if (defined('MULTILANGUAGE')) if (!@ in_array($tc_location, $TotalCounterBlacklist['Languages'])) $TotalCounter['Languages'][$userlang2]++; ## by MateuszCzaplinski ## last day, last week, ... - collect data if (!isset ($tc_bot)) { $TCnow = time(); foreach ($TotalCounterTimeBins as $n=>$a) TCbins($n, $a['max'], $a['atom']); $TotalCounter['LastTimestamp'] = $TCnow; } dbexport_unlock($file, serialize($TotalCounter), 'w'); } else { // could not acquire a lockfile // check if the lockfile isn't a stale one, try to delete it if so dblock_remove_stale($file); } } else { $TotalCount = $TotalCounter['Total']; $PageCount = $TotalCounter['Pages'][$tc_pagename]; ## by Schlaefer $TotalCounter['PagesTodayDay'][$tc_pagename] == date("%y%m%d") ? $PageCountToday = $TotalCounter['PagesTodayCounter'][$tc_pagename] : $PageCountToday = 1; } //rmdir($lock); # unlink($lock); # umask($oldumask); //add the {$PageCount} and {$TotalCount} markup Markup_e('{$PageCount}', '<{$var}', '/\\{\\$PageCount\\}/', $PageCount); Markup_e('{$TotalCount}', '<{$var}', '/\\{\\$TotalCount\\}/', $TotalCount); ## by Schlaefer ## adds vars for the input form Markup('{$PopularPagesItems}', '<{$var}', '/{\\$TotalCounterMaxItems}/', $_REQUEST['TotalCounterMaxItems'] ? $_REQUEST['TotalCounterMaxItems'] : $TotalCounterMaxItems); //add the {$PageViews} page variable $FmtPV['$PageViews'] = '$GLOBALS["TotalCounter"]["Pages"][$pagename]'; ## by Schlaefer ## add the {$PagesTodayCounter} page variable $FmtPV['$PageCountToday'] = '$GLOBALS["TotalCounter"]["PagesTodayCounter"][$pagename]'; function HandleTotalCounter($pagename, $auth = 'read') { global $Action, $TotalCounter, $TotalCounterMaxItems, $TotalCounterBarColor, $TotalCounterShowNumbers, $TotalCount, $TotalCounterDownloads, $TotalCounterTimeBins, $TotalCounterBinsFmt; global $PageStartFmt, $PageEndFmt; //$page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); $page = RetrieveAuthPage($pagename, $auth); if (!$page) Abort("?you are not permited to perform this action"); $alllocations = array ( 'localhost' => 'localhost', 'Unknown' => 'Unknown', 'com' => 'Commercial', 'net' => 'Networks', 'org' => 'Organizations', 'aero' => 'Aviation', 'biz' => 'Business organizations', 'coop' => 'Co-operative organizations', 'edu' => 'Educational', 'gov' => 'US Government', 'info' => 'Info', 'int' => 'International organizations', 'mil' => 'US Dept of Defense', 'museum' => 'Museums', 'name' => 'Personal', 'travel' => 'Travelling', 'ac' => 'Ascension Island', 'ad' => 'Andorra', 'ae' => 'United Arab Emirates', 'af' => 'Afghanistan', 'ag' => 'Antigua & Barbuda', 'ai' => 'Anguilla', 'al' => 'Albania', 'am' => 'Armenia', 'an' => 'Netherlands Antilles', 'ao' => 'Angola', 'aq' => 'Antarctica', 'ar' => 'Argentina', 'as' => 'American Samoa', 'at' => 'Austria', 'au' => 'Australia', 'aw' => 'Aruba', 'az' => 'Azerbaijan', 'ba' => 'Bosnia & Herzegovina', 'bb' => 'Barbados', 'bd' => 'Bangladesh', 'be' => 'Belgium', 'bf' => 'Burkina Faso', 'bg' => 'Bulgaria', 'bh' => 'Bahrain', 'bi' => 'Burundi', 'bj' => 'Benin', 'bm' => 'Bermuda', 'bn' => 'Brunei Darussalam', 'bo' => 'Bolivia', 'br' => 'Brazil', 'bs' => 'Bahamas', 'bt' => 'Bhutan', 'bv' => 'Bouvet Island', 'bw' => 'Botswana', 'by' => 'Belarus', 'bz' => 'Belize', 'ca' => 'Canada', 'cc' => 'Cocos (Keeling) Islands', 'cd' => 'Democratic republic of Congo', 'cf' => 'Central African Republic', 'cg' => 'Congo', 'ch' => 'Switzerland', 'ci' => 'Ivory Coast', 'ck' => 'Cook Islands', 'cl' => 'Chile', 'cm' => 'Cameroon', 'cn' => 'China', 'co' => 'Colombia', 'cr' => 'Costa Rica', 'cs' => 'Czechoslovakia', 'cu' => 'Cuba', 'cv' => 'Cape Verde', 'cx' => 'Christmas Island', 'cy' => 'Cyprus', 'cz' => 'Czech Republic', 'de' => 'Germany', 'dj' => 'Djibouti', 'dk' => 'Denmark', 'dm' => 'Dominica', 'do' => 'Dominican Republic', 'dz' => 'Algeria', 'ec' => 'Ecuador', 'ee' => 'Estonia', 'eg' => 'Egypt', 'eh' => 'Western Sahara', 'er' => 'Eritrea', 'es' => 'Spain', 'et' => 'Ethiopia', 'eu' => 'European Union', 'fi' => 'Finland', 'fj' => 'Fiji', 'fk' => 'Falkland Islands', 'fm' => 'Micronesia', 'fo' => 'Faroe Islands', 'fr' => 'France', 'ga' => 'Gabon', 'gb' => 'United Kingdom', 'gd' => 'Grenada', 'ge' => 'Georgia', 'gf' => 'French Guiana', 'gg' => 'Guernsey', 'gh' => 'Ghana', 'gi' => 'Gibraltar', 'gl' => 'Greenland', 'gm' => 'Gambia', 'gn' => 'Guinea', 'gp' => 'Guadeloupe', 'gq' => 'Equatorial Guinea', 'gr' => 'Greece', 'gs' => 'South Georgia & South Sandwich Islands', 'gt' => 'Guatemala', 'gu' => 'Guam', 'gw' => 'Guinea-Bissau', 'gy' => 'Guyana', 'hk' => 'Hong Kong', 'hm' => 'Heard & McDonald Islands', 'hn' => 'Honduras', 'hr' => 'Croatia', 'ht' => 'Haiti', 'hu' => 'Hungary', 'id' => 'Indonesia', 'ie' => 'Ireland', 'il' => 'Israel', 'im' => 'Isle of Man', 'in' => 'India', 'io' => 'British Indian Ocean Territory', 'iq' => 'Iraq', 'ir' => 'Iran', 'is' => 'Iceland', 'it' => 'Italy', 'je' => 'Jersey', 'jm' => 'Jamaica', 'jo' => 'Jordan', 'jp' => 'Japan', 'ke' => 'Kenya', 'kg' => 'Kyrgyzstan', 'kh' => 'Cambodia', 'ki' => 'Kiribati', 'km' => 'Comoros', 'kn' => 'Saint Kitts & Nevis', 'kp', 'North Korea', 'kr' => 'South Korea', 'kw' => 'Kuwait', 'ky' => 'Cayman Islands', 'kz' => 'Kazakhstan', 'la' => 'Laos', 'lb' => 'Lebanon', 'lc' => 'Saint Lucia', 'li' => 'Liechtenstein', 'lk' => 'Sri Lanka', 'lr' => 'Liberia', 'ls' => 'Lesotho', 'lt' => 'Lithuania', 'lu' => 'Luxembourg', 'lv' => 'Latvia', 'ly' => 'Libyan Arab Jamahiriya', 'ma' => 'Morocco', 'mc' => 'Monaco', 'md' => 'Moldova', 'mg' => 'Madagascar', 'mh' => 'Marshall Islands', 'mk' => 'Macedonia', 'ml' => 'Mali', 'mm' => 'Myanmar', 'mn' => 'Mongolia', 'mo' => 'Macau', 'mp' => 'Northern Mariana Islands', 'mq' => 'Martinique', 'mr' => 'Mauritania', 'ms' => 'Montserrat', 'mt' => 'Malta', 'mu' => 'Mauritius', 'mv' => 'Maldives', 'mw' => 'Malawi', 'mx' => 'Mexico', 'my' => 'Malaysia', 'mz' => 'Mozambique', 'na' => 'Namibia', 'nc' => 'New Caledonia', 'ne' => 'Niger', 'nf' => 'Norfolk Island', 'ng' => 'Nigeria', 'ni' => 'Nicaragua', 'nl' => 'The Netherlands', 'no' => 'Norway', 'np' => 'Nepal', 'nr' => 'Nauru', 'nu' => 'Niue', 'nz' => 'New Zealand', 'om' => 'Oman', 'pa' => 'Panama', 'pe' => 'Peru', 'pf' => 'French Polynesia', 'pg' => 'Papua New Guinea', 'ph' => 'Philippines', 'pk' => 'Pakistan', 'pl' => 'Poland', 'pm' => 'St. Pierre & Miquelon', 'pn' => 'Pitcairn', 'pr' => 'Puerto Rico', 'ps' => 'Palestine', 'pt' => 'Portugal', 'pw' => 'Palau', 'py' => 'Paraguay', 'qa' => 'Qatar', 're' => 'Reunion', 'ro' => 'Romania', 'ru' => 'Russia', 'rw' => 'Rwanda', 'sa' => 'Saudi Arabia', 'sb' => 'Solomon Islands', 'sc' => 'Seychelles', 'sd' => 'Sudan', 'se' => 'Sweden', 'sg' => 'Singapore', 'sh' => 'St. Helena', 'si' => 'Slovenia', 'sj' => 'Svalbard & Jan Mayen Islands', 'sk' => 'Slovakia', 'sl' => 'Sierra Leone', 'sm' => 'San Marino', 'sn' => 'Senegal', 'so' => 'Somalia', 'sr' => 'Surinam', 'st' => 'Sao Tome & Principe', 'su' => 'USSR', 'sv' => 'El Salvador', 'sy' => 'Syrian Arab Republic', 'sz' => 'Swaziland', 'tc' => 'The Turks & Caicos Islands', 'td' => 'Chad', 'tf' => 'French Southern Territories', 'tg' => 'Togo', 'th' => 'Thailand', 'tj' => 'Tajikistan', 'tk' => 'Tokelau', 'tm' => 'Turkmenistan', 'tn' => 'Tunisia', 'to' => 'Tonga', 'tp' => 'East Timor', 'tr' => 'Turkey', 'tt' => 'Trinidad & Tobago', 'tv' => 'Tuvalu', 'tw' => 'Taiwan', 'tz' => 'Tanzania', 'ua' => 'Ukraine', 'ug' => 'Uganda', 'uk' => 'United Kingdom', 'um' => 'United States Minor Outlying Islands', 'us' => 'United States', 'uy' => 'Uruguay', 'uz' => 'Uzbekistan', 'va' => 'Vatican City', 'vc' => 'Saint Vincent & the Grenadines', 've' => 'Venezuela', 'vg' => 'British Virgin Islands', 'vi' => 'US Virgin Islands', 'vn' => 'Vietnam', 'vu' => 'Vanuatu', 'wf' => 'Wallis & Futuna Islands', 'ws' => 'Samoa', 'ye' => 'Yemen', 'yt' => 'Mayotte', 'yu' => 'Yugoslavia', 'za' => 'South Africa', 'zm' => 'Zambia', 'zr' => 'Zaire', 'zw' => 'Zimbabwe', ); $Action = 'TotalCounter statistics'; ## by Schlaefer ## sets the max items if provided by the form if ($_REQUEST['TotalCounterMaxItems']) $TotalCounterMaxItems = $_REQUEST['TotalCounterMaxItems']; //------------------------------------------------------------------------------------------------------------ // PAGES $html = '

Total Counter $[statistics]

' . '

' . '

$[Page views]

' . '' . '$[Pages] '; @ arsort($TotalCounter['Pages']); $tar = @ array_slice($TotalCounter['Pages'], 0, $TotalCounterMaxItems); $tot = $TotalCount; $max = @ current($tar); $i = 0; if (is_array($tar) && $tot) // by Florian Xaver foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; } ## by Schlaefer //------------------------------------------------------------------------------------------------------------ ## PAGES daily $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Page views] $[today]

' . '' . '$[Pages] '; $tar = array (); foreach ($TotalCounter['PagesTodayCounter'] as $pn => $cnt) { if ($TotalCounter['PagesTodayDay'][$pn] === date("%y%m%d")) $tar[$pn] = $cnt; } @ arsort($tar); $tot = @ array_sum($tar); $tar = @ array_slice($tar, 0, $TotalCounterMaxItems); $max = @ current($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; if ($i == $TotalCounterMaxItems) break; } //------------------------------------------------------------------------------------------------------------ // USERS $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Users]

' . '' . '$[Users] '; @ arsort($TotalCounter['Users']); $tar = @ array_slice($TotalCounter['Users'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . '" . ''; } //------------------------------------------------------------------------------------------------------------ // LANGUAGES if (defined('MULTILANGUAGE')) { $html .= '
$[Percent]$[Count]
' . ++ $i . '.' . ($pn != 'Guest (not authenticated)' ? "$pn" : $pn) . " " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Languages]

' . '' . '$[Languages] '; @ arsort($TotalCounter['Languages']); $tar = @ array_slice($TotalCounter['Languages'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; } } //------------------------------------------------------------------------------------------------------------ // BROWSERS $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Browsers]

' . '' . '$[Browsers] '; @ arsort($TotalCounter['Browsers']); $tar = @ array_slice($TotalCounter['Browsers'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; } //------------------------------------------------------------------------------------------------------------ // OPERATING SYSTEMS $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Operating systems]

' . '' . '$[Operating systems] '; @ arsort($TotalCounter['OSes']); $tar = @ array_slice($TotalCounter['OSes'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; } //------------------------------------------------------------------------------------------------------------ // REFERERS $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Referers]

' . '' . '$[Referers] '; @ arsort($TotalCounter['Referers']); $tar = @ array_slice($TotalCounter['Referers'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; } //------------------------------------------------------------------------------------------------------------ // LOCATIONS $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[Locations]

' . '' . '$[Locations] '; @ arsort($TotalCounter['Locations']); $tar = @ array_slice($TotalCounter['Locations'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . '' . '' . '" . ''; } //------------------------------------------------------------------------------------------------------------ // WEB BOTS $html .= '
$[Percent]$[Count]
' . ++ $i . '.' . ($alllocations[$pn] == '' ? 'Unknown' : $alllocations[$pn]) . ' ' . ($pn == 'Unknown' || $pn == 'localhost' ? '' : "(.$pn)") . ' ' . Round(100 * $cnt / $tot) . '%
 $cnt
' . '

' . '

$[Web bots]

' . '' . '$[Web bots] '; @ arsort($TotalCounter['Bots']); $tar = @ array_slice($TotalCounter['Bots'], 0, $TotalCounterMaxItems); $max = @ current($tar); $tot = @ array_sum($tar); $i = 0; if (is_array($tar)) foreach ($tar as $pn => $cnt) { $html .= '' . ($TotalCounterShowNumbers ? '' : '') . "" . ''; } //------------------------------------------------------------------------------------------------------------ // Downloads $html .= '
$[Percent]$[Count]
' . ++ $i . '.$pn " . Round(100 * $cnt / $tot) . "%
 $cnt
' . '

' . '

$[File Downloads]

' . '' . '$[Downloads] '; @ arsort($TotalCounterDownloads); $max = count($TotalCounterDownloads); $tot = @ array_sum($TotalCounterDownloads); $i = 0; if (is_array($TotalCounterDownloads)) { for ($row = 0; $row < $max; $row++) { $tablerow = each($TotalCounterDownloads); $value = $tablerow['value']; $html .= '' . ($TotalCounterShowNumbers ? '' : '') . '' . '' . '' . ''; } } //------------------------------------------------------------------------------------------------------------ // Time statistics ## by MateuszCzaplinski foreach( $TotalCounterTimeBins as $n=>$a ) { $html .= '
$[Count]
' . ++ $i . '.' . $tablerow['key'] . ' ' . $value . '
' . '

' . "

$[$n]

"; SDVA($TotalCounterBinsFmt,array( '"$count"', '"
"', 'date("G",$now-$atom*($maxnr-1-$nr))' )); $fmt = $a['fmt']; if( is_string($fmt) ) { $tmp = $fmt; $fmt = $TotalCounterBinsFmt; $fmt[2] = $tmp; } if( is_array($fmt) ) { $rows = array(); ## Variables used in 'fmt' $maxcount = @max( $TotalCounter[$n] ); $direction = 'height'; $maxnr = $a['max']; $atom = $a['atom']; $now = time(); for( $nr=0; $nr<$a['max']; $nr++ ) { for( $j=0; $j". (string)eval("global \$TotalCounterMonthsShort; return ({$fmt[$j]});"). "\n"; } } } $html .= ''.implode('',$rows).''; } $html .= '

TotalCounter v' . TOTALCOUNTER . '

'; PrintFmt($pagename, array ( & $PageStartFmt, $html, & $PageEndFmt )); } ## by MateuszCzaplinski ## Manages an array of counters, each for a specified time interval. ## In $TotalCounter[$name] array there are $max counters. Each counter ## is for time interval of $atom length. ## Note: if $atom is a number, it is a length of interval measured ## in seconds. If $atom is a string, it means date($atom) is executed ## and the result is the index of an interval. ## NOTE: See TODO below function TCbins($name,$max,$atom) { global $TotalCounter, $TCnow; $last = $TotalCounter['LastTimestamp']; if( $TCnow < $last ) return; // some error? if( !$last ) $TotalCounter[$name] = array_fill(0,$max,0); if( is_string($atom) ) { $diff = (int)date($atom,$TCnow) - (int)date($atom,$last); if( $diff < 0 ) $diff += $max; # TODO: handle time delta > $max # Until fixed, if the site has no visitor for about a # year, statistics will get falsified (empty years will compress) } else $diff = (int)($TCnow/$atom) - (int)($last/$atom); if( $diff < 0 ) return; if( $diff > 0 ) { $a = @array_slice($TotalCounter[$name], $diff, max(0,$max-$diff)); if(!$a) $a = array(); $a = array_pad($a, $max, 0); $TotalCounter[$name] = $a; } $TotalCounter[$name][$max-1]++; // put our visit in last bin } //Windows 9x FLOCK Alternative - Chozo4 //Passes multiple instance stress testing //http://mechresource.myvnc.com/board //Modified (breaks and returns 0 on failure, // or returns 1 on success) by Mateusz Czaplinski, 22.01.2008 function aquirelock($wp) { //Check if lock doesn't exist or our target is unwritable if(file_exists("$wp.l") || !is_writable($wp)) return 0; //create the lock - hide warnings and pass empty if already created from racing return @ fopen("$wp.l", 'x'); } function dblock($wp) { global $TotalCounterEnableChmods; //Check for lockfile handle - if empty , another process raced the lock so report a failure $ftw = aquirelock($wp); if( !$ftw ) return 0; if($TotalCounterEnableChmods) chmod($wp, 0444); //set the target file to read-only fwrite($ftw, 'lock'); //write the lockfile with 4bytes if($TotalCounterEnableChmods) chmod("$wp.l", 0444); //set the lockfile to read only (OPTIONAL) fclose($ftw); //close our lockfile clearstatcache(); //Clear the stat cache return 1; } // Note: don't call it if 'dblock()' returned 0 ! function dbexport_unlock($wp, $data, $meth) { global $TotalCounterEnableChmods; if($TotalCounterEnableChmods) chmod($wp, 0666); //Set the target file to read+write //Write the passed string to the target file then close fwrite($ftw = fopen($wp, $meth), $data); fclose($ftw); //Validate the written data ujsing a string comparison $check = file_get_contents($wp); if ($check != $data) echo "Data Mismatch - Locking FAILED!
"; chmod("$wp.l", 0666); //Set the lockfile to read+write (OPTIONAL) unlink("$wp.l"); //Release the lockfile by removing it } function dblock_remove_stale($wp) { $t=filemtime("$wp.l"); // 75 minutes - to make absolutely sure we're not tricked by Daylight // Savings on Windows - see http://www.php.net/manual/en/function.stat.php#58404 if( $t+(75*60) < time()) @unlink("$wp.l"); } ?>