123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- <?php
-
- $TABLETRACK_OPEN = $_configuration['statistics_database']."`.`track_e_open";
- $TABLESTATS_PROVIDERS = $_configuration['statistics_database']."`.`track_c_providers";
- $TABLESTATS_COUNTRIES = $_configuration['statistics_database']."`.`track_c_countries";
- $TABLESTATS_BROWSERS = $_configuration['statistics_database']."`.`track_c_browsers";
- $TABLESTATS_OS = $_configuration['statistics_database']."`.`track_c_os";
- $TABLESTATS_REFERERS = $_configuration['statistics_database']."`.`track_c_referers";
-
-
-
- function decodeOpenInfos()
- {
- global $TABLETRACK_OPEN;
-
-
- $ignore = ignore_user_abort();
-
-
- ignore_user_abort(1) ;
-
-
- $sql = "SELECT open_id
- FROM `$TABLETRACK_OPEN`
- WHERE open_date <= NOW()
- ORDER BY open_id DESC
- LIMIT 1";
-
- $query = @mysql_query($sql);
- if (mysql_errno())
- {
- echo "\n<!-- **** ".mysql_errno().": ".mysql_error()." In : $sql **** -->\n";
- }
- $res = @mysql_fetch_array($query);
- $processBegin = $res[0];
-
-
-
- $sql = "SELECT open_remote_host
- FROM `$TABLETRACK_OPEN`
- WHERE open_remote_host != ''
- AND open_id <= '".$processBegin."' ";
- $query = mysql_query( $sql );
- if( mysql_num_rows($query) != 0 )
- {
-
- $list_countries = loadCountries();
-
- while ($row = mysql_fetch_row ($query) )
- {
- $remote_host = $row[0];
-
-
- $provider = extractProvider( $remote_host );
-
- $providers_array = addProvider( $provider,$providers_array );
-
-
-
- $country = extractCountry( $remote_host, $list_countries );
-
- $countries_array = addCountry( $country, $countries_array );
- }
-
- fillProvidersTable( $providers_array );
- fillCountriesTable( $countries_array );
- }
-
-
-
-
- $sql = "SELECT open_agent
- FROM `$TABLETRACK_OPEN`
- WHERE open_remote_host != ''
- AND open_id <= '".$processBegin."' ";
- $query = mysql_query( $sql );
- if( mysql_num_rows($query) != 0 )
- {
-
-
- $list_browsers = loadBrowsers();
-
- $list_os = loadOs();
-
- while ( $row = mysql_fetch_row ($query) )
- {
- $agent = $row[0];
-
-
- list( $browser,$os ) = split( "[|]",extractAgent( $agent , $list_browsers , $list_os ) );
-
- $browsers_array = addBrowser( $browser , $browsers_array );
- $os_array = addOs( $os , $os_array );
- }
-
- fillBrowsersTable( $browsers_array );
- fillOsTable( $os_array );
- }
-
-
-
- $sql = "SELECT open_referer
- FROM `$TABLETRACK_OPEN`
- WHERE open_referer != ''
- AND open_id <= '".$processBegin."' ";
- $query = mysql_query( $sql );
- if( mysql_num_rows($query) != 0 )
- {
- $i=0;
- while ($row = mysql_fetch_row ($query) )
- {
- $ref = $row[0];
- $referers_array = addReferer( $ref , $referers_array );
- }
- fillReferersTable( $referers_array );
- }
-
-
-
-
-
-
-
- cleanProcessedRecords($processBegin);
-
-
- ignore_user_abort($ignore);
- }
- function cleanProcessedRecords( $limit )
- {
- global $TABLETRACK_OPEN;
- $sql = "UPDATE `".$TABLETRACK_OPEN."`
- SET open_remote_host = '',
- open_agent = '',
- open_referer =''
- WHERE open_id <= '".$limit."'";
-
- $query = mysql_query( $sql );
-
- mysql_query("OPTIMIZE TABLE $TABLETRACK_OPEN");
-
- }
- function extractProvider($remhost)
- {
-
- if($remhost == "Unknown")
- return $remhost;
-
- $explodedRemhost = explode(".", $remhost);
- $provider = $explodedRemhost[sizeof( $explodedRemhost )-2]
- ."."
- .$explodedRemhost[sizeof( $explodedRemhost )-1];
-
- if($provider == "co.uk" || $provider == "co.jp")
- return $explodedRemhost[sizeof( $explodedRemhost )-3].$provider;
- else return $provider;
-
- }
- function addProvider($provider,$providers_array)
- {
- if( isset( $providers_array[$provider] ) )
- {
-
- $providers_array[$provider] = $providers_array[$provider] + 1;
- }
- else
- {
-
- $providers_array[$provider] = 1;
- }
- return $providers_array;
- }
- function fillProvidersTable($providers_array)
- {
- global $TABLESTATS_PROVIDERS;
-
- if(is_array($providers_array))
- {
- foreach ( $providers_array as $prov=>$number )
- {
- $sql = "SELECT counter
- FROM `".$TABLESTATS_PROVIDERS."`
- WHERE `provider` = '".$prov."'";
- $res = mysql_query($sql);
-
-
- if( $row = mysql_num_rows($res) )
- {
-
- $sql2 = "UPDATE `".$TABLESTATS_PROVIDERS."`
- SET `counter` = counter + '$number'
- WHERE `provider` = '".$prov."'";
- }
- else
- {
-
- $sql2 = "INSERT INTO `".$TABLESTATS_PROVIDERS."`
- (`provider`,`counter`)
- VALUES ('".$prov."','".$number."')";
- }
- mysql_query($sql2);
- }
- }
- }
- function loadCountries()
- {
- global $TABLESTATS_COUNTRIES;
-
- $sql = "SELECT code, country
- FROM `".$TABLESTATS_COUNTRIES."`";
-
- $res = mysql_query( $sql );
-
- $i = 0 ;
- while( $row = mysql_fetch_array( $res ) ) {
- $list_countries[$i][0] = $row["code"];
- $list_countries[$i][1] = $row["country"];
- $i++;
- }
- return $list_countries;
- mysql_free_result($res);
- }
- function extractCountry($remhost,$list_countries)
- {
- if($remhost == "Unknown")
- return $remhost;
-
- $explodedRemhost = explode(".",$remhost);
- $countryCode = $explodedRemhost[sizeof( $explodedRemhost )-1];
-
- for($i = 0 ; $i < sizeof( $list_countries );$i++)
- {
- if($list_countries[$i][0] == $countryCode)
- return $list_countries[$i][1];
- }
- }
- function addCountry($country,$countries_array)
- {
- if( isset( $countries_array[$country] ) )
- {
-
- $countries_array[$country] = $countries_array[$country] + 1;
- }
- else
- {
-
- $countries_array[$country] = 1;
- }
- return $countries_array;
-
- }
- function fillCountriesTable($countries_array)
- {
- global $TABLESTATS_COUNTRIES;
- if(is_array($countries_array) )
- {
- foreach ( $countries_array as $country=>$number )
- {
-
- $sql = "UPDATE `".$TABLESTATS_COUNTRIES."`
- SET `counter` = counter + '$number'
- WHERE `country` = '".$country."'";
- mysql_query($sql);
- }
- }
- }
-
- function loadBrowsers()
- {
- $buffer = split ("#","Gecko|Gecko#Mozilla/3|Mozilla 3.x#Mozilla/4.0|Mozilla 4.0x#Mozilla/4.5|Mozilla 4.5x#Mozilla/4.6|Mozilla 4.6x#Mozilla/4.7|Mozilla 4.7x#Mozilla/5.0|Mozilla 5.0x#MSIE 1.2|MSIE 1.2#MSIE 3.01|MSIE 3.x#MSIE 3.02|MSIE 3.x#MSIE 4.0|MSIE 4.x#MSIE 4.01|MSIE 4.x#MSIE 4.5|MSIE 4.5#MSIE 5.0b1|MSIE 5.0x#MSIE 5.0b2|MSIE 5.0x#MSIE 5.0|MSIE 5.0x#MSIE 5.01|MSIE 5.0x#MSIE 5.1|MSIE 5.1#MSIE 5.1b1|MSIE 5.1#MSIE 5.5|MSIE 5.5#MSIE 5.5b1|MSIE 5.5#MSIE 5.5b2|MSIE 5.5#MSIE 6.0|MSIE 6#MSIE 6.0b|MSIE 6#MSIE 6.5a|MSIE 6.5#Lynx/2.8.0|Lynx 2#Lynx/2.8.1|Lynx 2#Lynx/2.8.2|Lynx 2#Lynx/2.8.3|Lynx 2#Lynx/2.8.4|Lynx 2#Lynx/2.8.5|Lynx 2#HTTrack 3.0x|HTTrack#OmniWeb/4.0.1|OmniWeb#Opera 3.60|Opera 3.60#Opera 4.0|Opera 4#Opera 4.01|Opera 4#Opera 4.02|Opera 4#Opera 5|Opera 5#Opera/3.60|Opera 3.60#Opera/4|Opera 4#Opera/5|Opera 5#Opera/6|Opera 6#Opera 6|Opera 6#Netscape6|NS 6#Netscape/6|NS 6#Netscape7|NS 7#Netscape/7|NS 7#Konqueror/2.0|Konqueror 2#Konqueror/2.0.1|Konqueror 2#Konqueror/2.1|Konqueror 2#Konqueror/2.1.1|Konqueror 2#Konqueror/2.1.2|Konqueror 2#Konqueror/2.2|Konqueror 2#Teleport Pro|Teleport Pro#WebStripper|WebStripper#WebZIP|WebZIP#Netcraft Web|NetCraft#Googlebot|Googlebot#WebCrawler|WebCrawler#InternetSeer|InternetSeer#ia_archiver|ia archiver");
-
-
- $i=0;
- foreach( $buffer as $buffer1 ) {
- list ( $list_browsers[$i][0], $list_browsers[$i][1]) = split ('[|]', $buffer1 );
- $i++;
- }
- return $list_browsers;
- }
- function loadOs()
- {
- $buffer = split ("#","Windows 95|Win 95#Windows_95|Win 95#Windows 98|Win 98#Windows NT|Win NT#Windows NT 5.0|Win 2000#Windows NT 5.1|Win XP#Windows 2000|Win 2000#Windows XP|Win XP#Windows ME|Win Me#Win95|Win 95#Win98|Win 98#WinNT|Win NT#linux-2.2|Linux 2#Linux|Linux#Linux 2|Linux 2#Macintosh|Mac#Mac_PPC|Mac#Mac_PowerPC|Mac#SunOS 5|SunOS 5#SunOS 6|SunOS 6#FreeBSD|FreeBSD#beOS|beOS#InternetSeer|InternetSeer#Googlebot|Googlebot#Teleport Pro|Teleport Pro");
- $i=0;
- foreach( $buffer as $buffer1 ) {
- list ( $list_os[$i][0], $list_os[$i][1]) = split ('[|]', $buffer1 );
- $i+=1;
- }
- return $list_os;
- }
- function extractAgent( $user_agent, $list_browsers, $list_os )
- {
-
- $viewable_browser = "Unknown";
- $viewable_os = "Unknown";
-
-
-
- for($i = 0; $i < count( $list_browsers ); $i++)
- {
- $pos = strpos( $user_agent, $list_browsers[$i][0] );
- if( $pos !== false )
- {
- $viewable_browser = $list_browsers[$i][1];
- }
- }
-
-
- for($i = 0; $i < count($list_os); $i++)
- {
- $pos = strpos( $user_agent, $list_os[$i][0] );
- if( $pos !== false )
- {
- $viewable_os = $list_os[$i][1];
- }
- }
- return $viewable_browser."|".$viewable_os;
-
- }
- function addBrowser($browser,$browsers_array)
- {
- if( isset( $browsers_array[$browser] ) )
- {
-
- $browsers_array[$browser] = $browsers_array[$browser] + 1;
- }
- else
- {
-
- $browsers_array[$browser] = 1;
- }
- return $browsers_array;
-
- }
- function addOs($os,$os_array)
- {
- if( isset( $os_array[$os] ) )
- {
-
- $os_array[$os] = $os_array[$os] + 1;
- }
- else
- {
-
- $os_array[$os] = 1;
- }
- return $os_array;
-
- }
- function fillBrowsersTable($browsers_array)
- {
- global $TABLESTATS_BROWSERS;
- if ( is_array($browsers_array ) )
- {
- foreach ( $browsers_array as $browser=>$number )
- {
- $sql = "SELECT counter
- FROM `".$TABLESTATS_BROWSERS."`
- WHERE `browser` = '".$browser."'";
- $res = mysql_query($sql);
-
- if( $row = mysql_num_rows($res) )
- {
-
- $sql2 = "UPDATE `".$TABLESTATS_BROWSERS."`
- SET `counter` = counter + '$number'
- WHERE `browser` = '".$browser."'";
- }
- else
- {
-
- $sql2 = "INSERT INTO `".$TABLESTATS_BROWSERS."`
- (`browser`,`counter`)
- VALUES ('".$browser."','".$number."')";
- }
- mysql_query($sql2);
- }
- }
- }
- function fillOsTable($os_array)
- {
- global $TABLESTATS_OS;
- if ( is_array($os_array) )
- {
- foreach ( $os_array as $os=>$number )
- {
- $sql = "SELECT counter
- FROM `".$TABLESTATS_OS."`
- WHERE `os` = '".$os."'";
- $res = mysql_query($sql);
-
- if( $row = mysql_num_rows($res) )
- {
-
- $sql2 = "UPDATE `".$TABLESTATS_OS."`
- SET `counter` = counter + '$number'
- WHERE `os` = '".$os."'";
- }
- else
- {
-
- $sql2 = "INSERT INTO `".$TABLESTATS_OS."`
- (`os`,`counter`)
- VALUES ('".$os."','".$number."')";
- }
- mysql_query($sql2);
- }
- }
- }
- function addReferer($referer,$referers_array)
- {
- if( isset( $referers_array[$referer] ) )
- {
-
- $referers_array[$referer] = $referers_array[$referer] + 1;
- }
- else
- {
-
- $referers_array[$referer] = 1;
- }
- return $referers_array;
-
- }
-
- function fillReferersTable($referers_array)
- {
- global $TABLESTATS_REFERERS;
- if (is_array($referers_array) )
- {
- foreach ( $referers_array as $referer=>$number )
- {
- $sql = "SELECT counter
- FROM `".$TABLESTATS_REFERERS."`
- WHERE `referer` = '".$referer."'";
- $res = mysql_query($sql);
-
-
- if( $row = mysql_num_rows($res) )
- {
-
- $sql2 = "UPDATE `".$TABLESTATS_REFERERS."`
- SET `counter` = counter + '$number'
- WHERE `referer` = '".$referer."'";
- }
- else
- {
-
- $sql2 = "INSERT INTO `".$TABLESTATS_REFERERS."`
- (`referer`,`counter`)
- VALUES ('".$referer."','".$number."')";
- }
- mysql_query($sql2);
- }
- }
- }
- ?>
|