Index: extensions/whois_online/Changelog.txt.php
===================================================================
--- extensions/whois_online/Changelog.txt.php	(revision 5916)
+++ extensions/whois_online/Changelog.txt.php	(revision 5954)
@@ -3,4 +3,9 @@
 Plugin Name: Whois online
 ** History **
+  2010-04-24 2.0.m
+						 Fix: IE8 User agent could be too long
+						 Fix: Failure on localisation (a French internet provider blocks external get_files)
+						 Fix: Loss of previous collected data
+						 
   2010-04-18 2.0.l
 						 "Undefined index:  Code" is removed
Index: extensions/whois_online/include/wo_functions.inc.php
===================================================================
--- extensions/whois_online/include/wo_functions.inc.php	(revision 5916)
+++ extensions/whois_online/include/wo_functions.inc.php	(revision 5954)
@@ -2,10 +2,299 @@
 /* Functions */
 
-
-
-
-
-
-
+/* Secure Config */
+if (!isset($conf['Whois Online']) or !isset($conf_whois['Active'])) $conf_whois = whois_online_conf();
+
+function whois_online_conf()
+{
+	global $conf;
+	$default = array(
+	  'Active' => true,
+	  'Delete level' => 20,
+	  'Radar limit' => 25,
+	  'Webmasters' => 2, // Normal
+	  'Administrators' => 2,
+	  'Obsolete limit' => 20,
+		'Default display' => true,
+	  'Add to Plugins menu' => false,
+	  'Add icon to History' => true,
+	  'Keep data' => true,
+	  'Search id' => 0,
+	  'Users' => Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0),
+	);
+	if (!isset($conf['Whois Online'])) $conf['Whois Online'] = serialize(Array());
+	$conf_whois = array_merge($default, unserialize($conf['Whois Online']));
+	if ((!isset($conf_whois['Version'])) or $conf_whois['Version'] != WHOIS_ONLINE_VER
+		or $conf['Whois Online'] != serialize($conf_whois)) {
+		$conf_whois['Version'] = WHOIS_ONLINE_VER;
+		$conf['Whois Online'] = serialize($conf_whois);
+		pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
+	  VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
+	}
+	return $conf_whois;
+}
+
+
+if ( !function_exists('pwg_get_contents') ) {
+	function pwg_get_contents($url, $mode='') {
+
+		global $pwg_mode, $pwg_prev_host;
+		$timeout = 5; // will be a parameter (only for the socket)
+
+		$host = (strtolower(substr($url,0,7)) == 'http://') ? substr($url,7) : $url;
+		$host = (strtolower(substr($host,0,8)) == 'https://') ? substr($host,8) : $host;
+		$doc = substr($host, strpos($host, '/'));
+		$host = substr($host, 0, strpos($host, '/'));
+
+		if ($pwg_prev_host != $host) $pwg_mode = ''; // What was possible with one website could be different with another
+		$pwg_prev_host = $host;
+		if (isset($pwg_mode)) $mode = $pwg_mode;
+		if ($mode == 'r') $mode = '';
+		// $mode = 'ch'; // Forcing a test '' all, 'fs' fsockopen, 'ch' cURL
+
+	// 1 - The simplest solution: file_get_contents
+	// Contraint: php.ini
+	//      ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
+	//      allow_url_fopen = On
+		if ( $mode == '' ) {
+		  if ( true === (bool) ini_get('allow_url_fopen') ) { 
+				$value = file_get_contents($url);
+				if ( $value !== false and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') {
+					return $value;
+				}
+			}
+		}
+		if ( $mode == '' ) $mode = 'fs';
+		if ( $pwg_mode == '' ) $pwg_mode = 'fs'; // Remind it
+	// 2 - Often accepted access: fsockopen
+		if ($mode == 'fs') {
+			$fs = fsockopen($host, 80, $errno, $errstr, $timeout);
+			if ( $fs !== false ) {
+				fwrite($fs, 'GET ' . $doc . " HTTP/1.1\r\n");
+				fwrite($fs, 'Host: ' . $host . "\r\n");
+				fwrite($fs, "Connection: Close\r\n\r\n");
+				stream_set_blocking($fs, TRUE);
+				stream_set_timeout($fs,$timeout); // Again the $timeout on the get
+				$info = stream_get_meta_data($fs);
+				$value = '';
+				while ((!feof($fs)) && (!$info['timed_out'])) {
+								$value .= fgets($fs, 4096);
+								$info = stream_get_meta_data($fs);
+								flush();
+				}
+				if ( $info['timed_out'] === false  and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') return $value;
+			}
+		}
+
+		if ( $pwg_mode == 'fs' ) $pwg_mode = 'ch'; // Remind it
+	// 3 - Sometime another solution: curl_exec
+	// See http://fr2.php.net/manual/en/curl.installation.php
+	  if (function_exists('curl_init') and $pwg_mode == 'ch') {
+			$ch = @curl_init();
+			@curl_setopt($ch, CURLOPT_URL, $url);
+			@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+			@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+			@curl_setopt($ch, CURLOPT_HEADER, 1);
+			@curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
+			@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+			@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+			$value = @curl_exec($ch);
+			$header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+			$status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
+			@curl_close($value);
+			if ($value !== false and $status >= 200 and $status < 400) {
+				$value = substr($value, $header_length);
+				// echo '<br/>-ch- ('. $value . ') <br/>';
+				return $value;
+			}
+			else $pwg_mode = 'failed'; // Sorry but remind it as well
+		}
+
+		// No other solutions
+		return false;
+	}
+}
+// Assume the Default display on pages
+function whois_default_display() {
+	global $template;
+	$template->set_filenames(array( 'Whois_display' => dirname(__FILE__).'/../default.tpl'));
+	$template->pparse('Whois_display');
+}
+
+// Add admin links
+function whois_add_icon($menu) {
+	global $conf_whois, $lang;
+	if ($conf_whois['Add icon to History'])
+		$lang['History'] .= '</a> <a class="external" href="' . get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php') . '">
+			<img class="button" src="' . WHOIS_ONLINE_PATH . 'icons/Whois_tuner.gif" alt="Whois Online configuration" title="Whois Online configuration" /></a>';
+	if ($conf_whois['Add to Plugins menu']) array_push($menu, array(
+				'NAME' => 'Whois Online',
+				'URL' => get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php'),
+			));
+	return $menu;
+}
+
+// Template function
+function Whois_most($text, $count, $when, $format) {
+ return sprintf(l10n($text),$count,date(l10n($format),$when));
+}
+
+// New member
+function whois_online_register($who) {
+	global $conf, $conf_whois;
+	$conf_whois['Users']['count'] = $who['id'];
+	$conf['Whois Online'] = serialize($conf_whois);
+	pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
+  VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
+	return;
+}
+
+function whois_country($trace, $bypass = false) {
+  if (!isset($trace['country'])) {
+			pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 255 ) NOT NULL AFTER `lang` ;');
+			$trace['country']='';
+	}
+	$c = array();
+	if ($trace['country']!='') $c = @unserialize(htmlspecialchars_decode($trace['country']));
+	if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c; 
+	if ($bypass and isset($c['Code']) and $c['Code']=='__') return $c;
+    $result = pwg_get_contents ('http://api.hostip.info/get_html.php?ip=' . $trace['IP'], 'r');
+	if ( $result !== false ) { 
+		$tokens = preg_split("/[:]+/", $result);
+		$c = array ('Name' => $tokens[1], 'City' => substr($tokens[3],0,-3));
+		if (strpos ($c['Name'], '?') === FALSE) {
+			$tokens = preg_split ("/[\(\)]/", $c['Name']);
+			$c['Code'] = isset($tokens[1]) ? $tokens[1]:'__';
+			$c['Name'] = ucwords ( strtolower( substr($c['Name'],0,-5)));
+		}
+		else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);
+	}
+	if (stripos($c['Name'], 'Squid')!==false) $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);
+	else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);
+	if ($c['Code'] == 'Private Address') {
+		$c['Name'] = l10n('Private Address');
+		$c['City'] = l10n('N/A');
+		$c['Code'] = '__';
+	}
+	$new = htmlspecialchars(serialize($c),ENT_QUOTES,'UTF-8');
+	if ($new == $trace['country']) return $c;
+	pwg_query('UPDATE ' . WHOIS_ONLINE_TABLE . ' 
+      SET `country` = \'' . $new . '\'
+    WHERE `session_id` = \'' . $trace['session_id'] . '\';');
+  return $c;
+}
+
+function whois_flag($trace, &$step, $limit = 10) {
+  $flag = WHOIS_ONLINE_PATH . 'flags/' . $trace['Country']['Code'] . '.jpg';
+	if (file_exists($flag)) return $flag;
+	if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/__.jpg';
+        $f = fopen  ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r');
+        $result='';
+        while ($l = fgets ($f, 1024)) $result .= $l;
+        fclose ($f);
+		$f = fopen($flag,"w+");
+	fputs($f,$result);
+	fclose($f);
+  return $flag;
+}
+
+// Read all data
+function whois_online_get_data($order='') {
+	$remove = "''"; // Nothing to remove ( = an empty session_id)
+	$ctr = 0; $Online[0] = '';
+	$result = pwg_query('SELECT * FROM ' . WHOIS_ONLINE_TABLE . $order . ';');
+	while($row=mysql_fetch_array($result)) {
+		$row['delay'] = (int) time() - $row['last_access'];
+		$row['elm_ids'] = explode(' ', $row['last_elm_ids']);
+		$row['cat_ids'] = explode(' ', $row['last_cat_ids']);
+		$row['tag_ids'] = explode(' ', $row['last_tag_ids']);
+		$row['sch_ids'] = explode(' ', $row['last_sch_ids']);
+		$row['dates'] = explode(' ', $row['last_dates']);
+		$ctr++;
+		if ( $row['IP'] != 'global' and $row['permanent'] == 'false'
+			and $row['delay'] > (float)( 60 * 60 * 24 * 3 )) $remove .= ", '" . $row['session_id'] . "'";
+		elseif ($row['IP'] == 'global') $Online[0] = $row;
+		else $Online[] = $row;
+	}
+	// Out of 7 visits: Reduce registered visits for 3 days without access
+	if ($remove != "''" and $ctr > (count($Online) * ONLINE_LEVEL)
+		and ($ctr-count($Online)) > ONLINE_LIMIT and ($Online[0]['pag_hits']%7)==0) {
+		pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `session_id` IN ('. $remove .')
+				AND `permanent` = \'false\' AND `IP` <> \'global\';');
+		if (($Online[0]['pag_hits']%13)==0) @pwg_query('OPTIMIZE TABLE ' . WHOIS_ONLINE_TABLE . ';');
+	}
+	return $Online;
+}
+
+// Update global and update/create current session_id
+function whois_online_update(&$global, &$dedicated, &$gtrace)
+{
+	global $lang_info;
+	// Rewrite the global record
+	if ( $gtrace == 2 ) {
+		$query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`,
+		`permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
+		`first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
+			VALUES (\'global\', \'true\',\'global\', 0, \''. $global['username'] .'\', \'--\', \'true\', \''
+			. time()  .'\',  \''
+			. implode(' ',$global['elm_ids']) . '\', \''
+			. implode(' ',$global['cat_ids']) . '\', \''
+			. implode(' ',$global['tag_ids']) . '\', \''
+			. implode(' ',$global['sch_ids']) . '\', \''
+			. $global['first_access_date'] . '\', \'\', \''
+			. $global['elm_hits'] . '\', \'' . $global['pag_hits'] . '\');';
+		pwg_query($query);
+	}
+	// Write or Rewrite the dedicated record
+	$query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, `user_agent`,
+	`any_previous`, `same_previous`, `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
+	`first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
+		VALUES (\''. $dedicated['IP'] .'\', \''
+		. $dedicated['hidden_IP'] .'\', \''. $dedicated['session_id'] .'\', \''
+		. $dedicated['user_id'] .'\', \''. $dedicated['username'] .'\', \''
+		. substr($lang_info['code'],0,2) .'\', \''
+		. $dedicated['user_agent'] .'\', \''
+		. $dedicated['any_previous'] .'\', \''
+		. $dedicated['same_previous'] .'\', \''
+		. $dedicated['permanent'] . '\', \''. time() .'\',  \''
+		. implode(' ',$dedicated['elm_ids']) . '\', \''
+		. implode(' ',$dedicated['cat_ids']) . '\', \''
+		. implode(' ',$dedicated['tag_ids']) . '\', \''
+		. implode(' ',$dedicated['sch_ids']) . '\', \''
+		. $dedicated['first_access_date'] . '\', \''
+		. implode(' ',$dedicated['dates']) . '\', \''
+		. $dedicated['elm_hits'] . '\', \''
+		. $dedicated['pag_hits'] . '\');';
+	pwg_query($query);
+}
+
+// Data tracking 
+// Parameters:
+//  - Array of Ids
+//  - New ID
+//  - Array of dates
+// => Add the ID if needed, Add Today if needed
+function whois_online_track(&$key, $id, &$date) {
+	if ($id != '') array_unshift($key, $id);
+	$key = array_unique($key);
+	if (count($key)>10) array_pop($key);
+	array_unshift($date, date('Y-m-d'));
+	$date = array_unique($date);
+	if (count($date)>5) array_pop($date);
+	return;
+}
+
+// Antiaspi delay conversion in seconds
+// delay in "HH:ii:ss" or "d :HH:ii:ss"
+// return delay in seconds
+function whois_online_duration($date_string)
+{
+ list($s, $i, $H, $d, $more) = 
+   array_merge(array_reverse(
+	   explode(" ",str_ireplace(':',' ', $date_string))),
+		 array(0,0,0,0,0));
+ $t = time();
+ return strtotime(sprintf("+%s days %s hours %s minutes %s seconds", 
+   $d, $H, $i, $s), $t) - $t;
+}
 
 /*
Index: extensions/whois_online/main.inc.php
===================================================================
--- extensions/whois_online/main.inc.php	(revision 5916)
+++ extensions/whois_online/main.inc.php	(revision 5954)
@@ -23,5 +23,5 @@
 /*
 Plugin Name: Whois online
-Version: 2.0.l
+Version: 2.0.m
 Description: Who is online?
 Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=279
@@ -29,5 +29,5 @@
 Author URI: http://www.vdigital.org
 */
-define('WHOIS_ONLINE_VER', '2.0.l'); 
+define('WHOIS_ONLINE_VER', '2.0.m'); 
 global $prefixeTable, $conf;
 // $conf['debug_l10n'] = true;
Index: extensions/whois_online/maintain.inc.php
===================================================================
--- extensions/whois_online/maintain.inc.php	(revision 5916)
+++ extensions/whois_online/maintain.inc.php	(revision 5954)
@@ -45,5 +45,5 @@
 	list($hits) = mysql_fetch_row(pwg_query('SELECT SUM(hit) FROM '.IMAGES_TABLE.';'));
 	$pags = floor($hits * 1.69); /* estimate : 1.69 is a frequent ratio between images hits and pages hits */
-	pwg_query('REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`,
+	pwg_query('INSERT IGNORE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`, `user_id`,`username`,`lang`,`permanent`,`last_access`,
 	`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
 	`first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
Index: extensions/whois_online/online.php
===================================================================
--- extensions/whois_online/online.php	(revision 5916)
+++ extensions/whois_online/online.php	(revision 5954)
@@ -4,34 +4,4 @@
 global $conf, $conf_whois, $prefixeTable;
 include_once(WHOIS_ONLINE_PATH.'include/wo_functions.inc.php');
-/* Secure Config */
-if (!isset($conf_whois['Active'])) $conf_whois = whois_online_conf();
-
-function whois_online_conf()
-{
-	global $conf;
-	$default = array(
-	  'Active' => true,
-	  'Delete level' => 20,
-	  'Radar limit' => 25,
-	  'Webmasters' => 2, // Normal
-	  'Administrators' => 2,
-	  'Obsolete limit' => 20,
-		'Default display' => true,
-	  'Add to Plugins menu' => false,
-	  'Add icon to History' => true,
-	  'Keep data' => true,
-	  'Search id' => 0,
-	  'Users' => Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0),
-	);
-	$conf_whois = array_merge($default, unserialize($conf['Whois Online']));
-	if ((!isset($conf_whois['Version'])) or $conf_whois['Version'] != WHOIS_ONLINE_VER
-		or $conf['Whois Online'] != serialize($conf_whois)) {
-		$conf_whois['Version'] = WHOIS_ONLINE_VER;
-		$conf['Whois Online'] = serialize($conf_whois);
-		pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
-	  VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
-	}
-	return $conf_whois;
-}
 
 define('ONLINE_LEVEL', (100+$conf_whois['Delete level'])/100);
@@ -49,265 +19,4 @@
 }
 
-if ( !function_exists('pwg_get_contents') ) {
-	function pwg_get_contents($url, $mode='') {
-
-		global $pwg_mode, $pwg_prev_host;
-		$timeout = 5; // will be a parameter (only for the socket)
-
-		$host = (strtolower(substr($url,0,7)) == 'http://') ? substr($url,7) : $url;
-		$host = (strtolower(substr($host,0,8)) == 'https://') ? substr($host,8) : $host;
-		$doc = substr($host, strpos($host, '/'));
-		$host = substr($host, 0, strpos($host, '/'));
-
-		if ($pwg_prev_host != $host) $pwg_mode = ''; // What was possible with one website could be different with another
-		$pwg_prev_host = $host;
-		if (isset($pwg_mode)) $mode = $pwg_mode;
-		if ($mode == 'r') $mode = '';
-		// $mode = 'ch'; // Forcing a test '' all, 'fs' fsockopen, 'ch' cURL
-
-	// 1 - The simplest solution: file_get_contents
-	// Contraint: php.ini
-	//      ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
-	//      allow_url_fopen = On
-		if ( $mode == '' ) {
-		  if ( true === (bool) ini_get('allow_url_fopen') ) { 
-				$value = file_get_contents($url);
-				if ( $value !== false and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') {
-					return $value;
-				}
-			}
-		}
-		if ( $mode == '' ) $mode = 'fs';
-		if ( $pwg_mode == '' ) $pwg_mode = 'fs'; // Remind it
-	// 2 - Often accepted access: fsockopen
-		if ($mode == 'fs') {
-			$fs = fsockopen($host, 80, $errno, $errstr, $timeout);
-			if ( $fs !== false ) {
-				fwrite($fs, 'GET ' . $doc . " HTTP/1.1\r\n");
-				fwrite($fs, 'Host: ' . $host . "\r\n");
-				fwrite($fs, "Connection: Close\r\n\r\n");
-				stream_set_blocking($fs, TRUE);
-				stream_set_timeout($fs,$timeout); // Again the $timeout on the get
-				$info = stream_get_meta_data($fs);
-				$value = '';
-				while ((!feof($fs)) && (!$info['timed_out'])) {
-								$value .= fgets($fs, 4096);
-								$info = stream_get_meta_data($fs);
-								flush();
-				}
-				if ( $info['timed_out'] === false  and substr($value,0,21) != '<!DOCTYPE HTML PUBLIC') return $value;
-			}
-		}
-
-		if ( $pwg_mode == 'fs' ) $pwg_mode = 'ch'; // Remind it
-	// 3 - Sometime another solution: curl_exec
-	// See http://fr2.php.net/manual/en/curl.installation.php
-	  if (function_exists('curl_init') and $pwg_mode == 'ch') {
-			$ch = @curl_init();
-			@curl_setopt($ch, CURLOPT_URL, $url);
-			@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
-			@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
-			@curl_setopt($ch, CURLOPT_HEADER, 1);
-			@curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
-			@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-			@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
-			$value = @curl_exec($ch);
-			$header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
-			$status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
-			@curl_close($value);
-			if ($value !== false and $status >= 200 and $status < 400) {
-				$value = substr($value, $header_length);
-				// echo '<br/>-ch- ('. $value . ') <br/>';
-				return $value;
-			}
-			else $pwg_mode = 'failed'; // Sorry but remind it as well
-		}
-
-		// No other solutions
-		return false;
-	}
-}
-// Assume the Default display on pages
-function whois_default_display() {
-	global $template;
-	$template->set_filenames(array( 'Whois_display' => dirname(__FILE__).'/default.tpl'));
-	$template->pparse('Whois_display');
-}
-
-// Add admin links
-function whois_add_icon($menu) {
-	global $conf_whois, $lang;
-	if ($conf_whois['Add icon to History'])
-		$lang['History'] .= '</a> <a class="external" href="' . get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php') . '">
-			<img class="button" src="' . WHOIS_ONLINE_PATH . 'icons/Whois_tuner.gif" alt="Whois Online configuration" title="Whois Online configuration" /></a>';
-	if ($conf_whois['Add to Plugins menu']) array_push($menu, array(
-				'NAME' => 'Whois Online',
-				'URL' => get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php'),
-			));
-	return $menu;
-}
-
-// Template function
-function Whois_most($text, $count, $when, $format) {
- return sprintf(l10n($text),$count,date(l10n($format),$when));
-}
-
-// New member
-function whois_online_register($who) {
-	global $conf, $conf_whois;
-	$conf_whois['Users']['count'] = $who['id'];
-	$conf['Whois Online'] = serialize($conf_whois);
-	pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
-  VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
-	return;
-}
-
-function whois_country($trace, $bypass = false) {
-  if (!isset($trace['country'])) {
-			pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 255 ) NOT NULL AFTER `lang` ;');
-			$trace['country']='';
-	}
-	$c = array();
-	if ($trace['country']!='') $c = @unserialize(htmlspecialchars_decode($trace['country']));
-	if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c; 
-	if ($bypass and isset($c['Code']) and $c['Code']=='__') return $c;
-    $result = pwg_get_contents ('http://api.hostip.info/get_html.php?ip=' . $trace['IP'], 'r');
-	if ( $result !== false ) { 
-		$tokens = preg_split("/[:]+/", $result);
-		$c = array ('Name' => $tokens[1], 'City' => substr($tokens[3],0,-3));
-		if (strpos ($c['Name'], '?') === FALSE) {
-			$tokens = preg_split ("/[\(\)]/", $c['Name']);
-			$c['Code'] = isset($tokens[1]) ? $tokens[1]:'__';
-			$c['Name'] = ucwords ( strtolower( substr($c['Name'],0,-5)));
-		}
-		else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);
-	}
-	else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',);
-	if ($c['Code'] == 'Private Address') {
-		$c['Name'] = l10n('Private Address');
-		$c['City'] = l10n('N/A');
-		$c['Code'] = '__';
-	}
-	$new = htmlspecialchars(serialize($c),ENT_QUOTES,'UTF-8');
-	if ($new == $trace['country']) return $c;
-	pwg_query('UPDATE ' . WHOIS_ONLINE_TABLE . ' 
-      SET `country` = \'' . $new . '\'
-    WHERE `session_id` = \'' . $trace['session_id'] . '\';');
-  return $c;
-}
-
-function whois_flag($trace, &$step, $limit = 10) {
-  $flag = WHOIS_ONLINE_PATH . 'flags/' . $trace['Country']['Code'] . '.jpg';
-	if (file_exists($flag)) return $flag;
-	if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/__.jpg';
-        $f = fopen  ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r');
-        $result='';
-        while ($l = fgets ($f, 1024)) $result .= $l;
-        fclose ($f);
-		$f = fopen($flag,"w+");
-	fputs($f,$result);
-	fclose($f);
-  return $flag;
-}
-
-// Read all data
-function whois_online_get_data($order='') {
-	$remove = "''"; // Nothing to remove ( = an empty session_id)
-	$ctr = 0; $Online[0] = '';
-	$result = pwg_query('SELECT * FROM ' . WHOIS_ONLINE_TABLE . $order . ';');
-	while($row=mysql_fetch_array($result)) {
-		$row['delay'] = (int) time() - $row['last_access'];
-		$row['elm_ids'] = explode(' ', $row['last_elm_ids']);
-		$row['cat_ids'] = explode(' ', $row['last_cat_ids']);
-		$row['tag_ids'] = explode(' ', $row['last_tag_ids']);
-		$row['sch_ids'] = explode(' ', $row['last_sch_ids']);
-		$row['dates'] = explode(' ', $row['last_dates']);
-		$ctr++;
-		if ( $row['IP'] != 'global' and $row['permanent'] == 'false'
-			and $row['delay'] > (float)( 60 * 60 * 24 * 3 )) $remove .= ", '" . $row['session_id'] . "'";
-		elseif ($row['IP'] == 'global') $Online[0] = $row;
-		else $Online[] = $row;
-	}
-	// Out of 7 visits: Reduce registered visits for 3 days without access
-	if ($remove != "''" and $ctr > (count($Online) * ONLINE_LEVEL)
-		and ($ctr-count($Online)) > ONLINE_LIMIT and ($Online[0]['pag_hits']%7)==0) {
-		pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `session_id` IN ('. $remove .')
-				AND `permanent` = \'false\' AND `IP` <> \'global\';');
-		if (($Online[0]['pag_hits']%13)==0) @pwg_query('OPTIMIZE TABLE ' . WHOIS_ONLINE_TABLE . ';');
-	}
-	return $Online;
-}
-
-// Update global and update/create current session_id
-function whois_online_update(&$global, &$dedicated, &$gtrace)
-{
-	global $lang_info;
-	// Rewrite the global record
-	if ( $gtrace == 2 ) {
-		$query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`,
-		`permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
-		`first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
-			VALUES (\'global\', \'true\',\'global\', 0, \''. $global['username'] .'\', \'--\', \'true\', \''
-			. time()  .'\',  \''
-			. implode(' ',$global['elm_ids']) . '\', \''
-			. implode(' ',$global['cat_ids']) . '\', \''
-			. implode(' ',$global['tag_ids']) . '\', \''
-			. implode(' ',$global['sch_ids']) . '\', \''
-			. $global['first_access_date'] . '\', \'\', \''
-			. $global['elm_hits'] . '\', \'' . $global['pag_hits'] . '\');';
-		pwg_query($query);
-	}
-	// Write or Rewrite the dedicated record
-	$query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, `user_agent`,
-	`any_previous`, `same_previous`, `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`,
-	`first_access_date`, `last_dates`, `elm_hits`, `pag_hits`)
-		VALUES (\''. $dedicated['IP'] .'\', \''
-		. $dedicated['hidden_IP'] .'\', \''. $dedicated['session_id'] .'\', \''
-		. $dedicated['user_id'] .'\', \''. $dedicated['username'] .'\', \''
-		. substr($lang_info['code'],0,2) .'\', \''
-		. $dedicated['user_agent'] .'\', \''
-		. $dedicated['any_previous'] .'\', \''
-		. $dedicated['same_previous'] .'\', \''
-		. $dedicated['permanent'] . '\', \''. time() .'\',  \''
-		. implode(' ',$dedicated['elm_ids']) . '\', \''
-		. implode(' ',$dedicated['cat_ids']) . '\', \''
-		. implode(' ',$dedicated['tag_ids']) . '\', \''
-		. implode(' ',$dedicated['sch_ids']) . '\', \''
-		. $dedicated['first_access_date'] . '\', \''
-		. implode(' ',$dedicated['dates']) . '\', \''
-		. $dedicated['elm_hits'] . '\', \''
-		. $dedicated['pag_hits'] . '\');';
-	pwg_query($query);
-}
-
-// Data tracking 
-// Parameters:
-//  - Array of Ids
-//  - New ID
-//  - Array of dates
-// => Add the ID if needed, Add Today if needed
-function whois_online_track(&$key, $id, &$date) {
-	if ($id != '') array_unshift($key, $id);
-	$key = array_unique($key);
-	if (count($key)>10) array_pop($key);
-	array_unshift($date, date('Y-m-d'));
-	$date = array_unique($date);
-	if (count($date)>5) array_pop($date);
-	return;
-}
-
-// Antiaspi delay conversion in seconds
-// delay in "HH:ii:ss" or "d :HH:ii:ss"
-// return delay in seconds
-function whois_online_duration($date_string)
-{
- list($s, $i, $H, $d, $more) = 
-   array_merge(array_reverse(
-	   explode(" ",str_ireplace(':',' ', $date_string))),
-		 array(0,0,0,0,0));
- $t = time();
- return strtotime(sprintf("+%s days %s hours %s minutes %s seconds", 
-   $d, $H, $i, $s), $t) - $t;
-}
 
 /*
@@ -523,5 +232,5 @@
 	$ctr_same = count(explode(' ',$visit['same_previous']));
 	
-	$visit['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
+	$visit['user_agent'] = substr($_SERVER['HTTP_USER_AGENT'],0,160);
 	$Vip =& $visit['IP'];
 	$visit['Allowed_SE'] = false;
